Set destVector for doors as well

This commit is contained in:
fullwall 2019-04-25 16:57:36 +08:00
parent 0f45b85ca3
commit 86f4118683

View File

@ -94,6 +94,15 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
} }
Location currLoc = npc.getEntity().getLocation(NPC_LOCATION); Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5); Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();
if (door.isOpen()) {
BlockFace targetFace = door.getFacing().getOppositeFace();
destVector.setX(vector.getX() + targetFace.getModX());
destVector.setZ(vector.getZ() + targetFace.getModZ());
}
}
if (currLoc.toVector().distanceSquared(destVector) <= params.distanceMargin()) { if (currLoc.toVector().distanceSquared(destVector) <= params.distanceMargin()) {
plan.update(npc); plan.update(npc);
if (plan.isComplete()) { if (plan.isComplete()) {
@ -113,15 +122,6 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (distance > 0 && dY > NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) { if (distance > 0 && dY > NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) {
NMS.setShouldJump(npc.getEntity()); NMS.setShouldJump(npc.getEntity());
} }
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();
if (door.isOpen()) {
BlockFace targetFace = door.getFacing().getOppositeFace();
destVector.setX(vector.getX() + targetFace.getModX());
destVector.setZ(vector.getZ() + targetFace.getModZ());
}
}
NMS.setDestination(npc.getEntity(), destVector.getX(), destVector.getY(), destVector.getZ(), params.speed()); NMS.setDestination(npc.getEntity(), destVector.getX(), destVector.getY(), destVector.getZ(), params.speed());
params.run(); params.run();
plan.run(npc); plan.run(npc);