Implement debug NavigatorParameter and change some Player yaw code

This commit is contained in:
fullwall 2016-12-10 19:53:55 +08:00
parent 9df3481a9b
commit e3981a15a6
6 changed files with 16 additions and 22 deletions

View File

@ -192,7 +192,6 @@ public class CitizensNPC extends AbstractNPC {
at = at.clone();
getTrait(CurrentLocation.class).setLocation(at);
entityController.spawn(at, this);
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));

View File

@ -8,7 +8,6 @@ import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.AbstractPathStrategy;
import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.TargetType;
@ -62,7 +61,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
setCancelReason(CancelReason.STUCK);
} else {
vector = plan.getCurrentVector();
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
if (params.debug()) {
plan.debug();
}
}
@ -70,7 +69,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
@Override
public void stop() {
if (plan != null && Setting.DEBUG_PATHFINDING.asBoolean()) {
if (plan != null && params.debug()) {
plan.debugEnd();
}
plan = null;
@ -101,7 +100,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
double dY = vector.getY() - currLoc.getY();
double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
if (params.debug()) {
npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL,
0);
}

View File

@ -43,7 +43,7 @@ import net.citizensnpcs.util.Util;
public class CitizensNavigator implements Navigator, Runnable {
private final NavigatorParameters defaultParams = new NavigatorParameters().baseSpeed(UNINITIALISED_SPEED)
.range(Setting.DEFAULT_PATHFINDING_RANGE.asFloat())
.range(Setting.DEFAULT_PATHFINDING_RANGE.asFloat()).debug(Setting.DEBUG_PATHFINDING.asBoolean())
.defaultAttackStrategy(MCTargetStrategy.DEFAULT_ATTACK_STRATEGY)
.attackRange(Setting.NPC_ATTACK_DISTANCE.asDouble())
.updatePathRate(Setting.DEFAULT_PATHFINDER_UPDATE_PATH_RATE.asInt())

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.npc.ai;
import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -9,7 +10,6 @@ import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.AbstractPathStrategy;
import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.TargetType;
@ -64,7 +64,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
setCancelReason(CancelReason.STUCK);
} else {
vector = plan.getCurrentVector();
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
if (parameters.debug()) {
plan.debug();
}
}
@ -73,7 +73,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
@Override
public void stop() {
if (plan != null && Setting.DEBUG_PATHFINDING.asBoolean()) {
if (plan != null && parameters.debug()) {
plan.debugEnd();
}
plan = null;
@ -108,6 +108,10 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
}
vector = plan.getCurrentVector();
}
if (parameters.debug()) {
npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL,
0);
}
double d0 = vector.getX() + 0.5D - current.getX();
double d1 = vector.getY() + 0.1D - current.getY();

View File

@ -140,17 +140,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
npc.update();
}
private float bodyControla(float paramFloat1, float paramFloat2, float paramFloat3) {
float f = MathHelper.g(paramFloat1 - paramFloat2);
if (f < -paramFloat3) {
f = -paramFloat3;
}
if (f >= paramFloat3) {
f = paramFloat3;
}
return paramFloat1 - f;
}
@Override
public void collide(net.minecraft.server.v1_11_R1.Entity entity) {
// this method is called by both the entities involved - cancelling

View File

@ -82,14 +82,17 @@ public class PlayerControllerMove extends ControllerMove {
double d1 = this.d - this.a.locZ;
double d2 = this.c - i;
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
if (d3 < 2.500000277905201E-007D)
if (d3 < 2.500000277905201E-007D) {
this.a.bf = (0.0F);
return;
}
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
this.a.yaw = a(this.a.yaw, f, 30.0F);
this.a.yaw = a(this.a.yaw, f, 90.0F);
NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
speed.setValue(0.1D * this.e);
float movement = (float) (this.e * speed.getValue()) * 10;
this.a.l(movement);
this.a.bf = movement;
if (shouldSlimeJump() || ((d2 > 0.0D) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();