diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 7570a6d36..acc65a764 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -2344,8 +2344,8 @@ public class NPCCommands { permission = "citizens.npc.swim") public void swim(CommandContext args, CommandSender sender, NPC npc) throws CommandException { boolean swim = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set")) - : !npc.data().get(NPC.SWIMMING_METADATA, true); - npc.data().setPersistent(NPC.SWIMMING_METADATA, swim); + : !npc.data().get(NPC.Metadata.SWIMMING, true); + npc.data().setPersistent(NPC.Metadata.SWIMMING, swim); Messaging.sendTr(sender, swim ? Messages.SWIMMING_SET : Messages.SWIMMING_UNSET, npc.getName()); } diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index d3d9673c9..e6c73bba1 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -11,7 +11,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.WaterMob; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.metadata.FixedMetadataValue; @@ -26,6 +25,7 @@ import net.citizensnpcs.NPCNeedsRespawnEvent; import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.ai.Navigator; +import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer; import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.event.NPCDespawnEvent; import net.citizensnpcs.api.event.NPCSpawnEvent; @@ -152,11 +152,6 @@ public class CitizensNPC extends AbstractNPC { return getEntity() != null && NMS.isValid(getEntity()); } - private boolean isWaterMob(Entity entity) { - return entity instanceof WaterMob || entity.getType().name().equals("TURTLE") - || entity.getType().name().equals("AXOLOTL"); - } - @Override public void load(final DataKey root) { super.load(root); @@ -368,8 +363,15 @@ public class CitizensNPC extends AbstractNPC { resetCachedCoord(); return; } - if (data().has(NPC.Metadata.SWIMMING) ? data(). get(NPC.Metadata.SWIMMING) - : !isWaterMob(getEntity())) { + if (navigator.isNavigating()) { + if (!data().has(NPC.Metadata.SWIMMING) || data(). get(NPC.Metadata.SWIMMING)) { + Location currentDest = navigator.getPathStrategy().getCurrentDestination(); + if (currentDest == null || currentDest.getY() > getStoredLocation().getY()) { + NMS.trySwim(getEntity(), SwimmingExaminer.isWaterMob(getEntity()) ? 0.01F : 0.04F); + } + } + } else if (data().has(NPC.Metadata.SWIMMING) ? data(). get(NPC.Metadata.SWIMMING) + : !SwimmingExaminer.isWaterMob(getEntity())) { NMS.trySwim(getEntity()); } navigator.run(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java index f19bb929c..d33a1584f 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java @@ -54,6 +54,11 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { this.npc = npc; } + @Override + public Location getCurrentDestination() { + return vector != null ? vector.toLocation(npc.getEntity().getWorld()) : null; + } + @Override public Iterable getPath() { return plan == null ? null : plan.getPath(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java index 4329d9019..3d4f11639 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/FlyingAStarNavigationStrategy.java @@ -56,6 +56,11 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy { this.npc = npc; } + @Override + public Location getCurrentDestination() { + return vector != null ? vector.toLocation(npc.getEntity().getWorld()) : null; + } + @Override public Iterable getPath() { return plan == null ? null : plan.getPath(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index d3dfd6bf2..d3c3a0e69 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -18,7 +18,7 @@ import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.Util; public class MCNavigationStrategy extends AbstractPathStrategy { - private final Entity handle; + private final Entity entity; private final MCNavigator navigator; private final NavigatorParameters parameters; private final Location target; @@ -28,7 +28,7 @@ public class MCNavigationStrategy extends AbstractPathStrategy { List list = Lists.newArrayList(path); this.target = list.get(list.size() - 1).toLocation(npc.getStoredLocation().getWorld()); this.parameters = params; - handle = npc.getEntity(); + entity = npc.getEntity(); this.navigator = NMS.getTargetNavigator(npc.getEntity(), list, params); } @@ -39,10 +39,15 @@ public class MCNavigationStrategy extends AbstractPathStrategy { } this.target = Util.getCenterLocation(dest.getBlock()); this.parameters = params; - handle = npc.getEntity(); + entity = npc.getEntity(); this.navigator = NMS.getTargetNavigator(npc.getEntity(), target, params); } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return navigator.getPath(); @@ -76,7 +81,7 @@ public class MCNavigationStrategy extends AbstractPathStrategy { if (getCancelReason() != null) return true; boolean wasFinished = navigator.update(); - Location loc = handle.getLocation(HANDLE_LOCATION); + Location loc = entity.getLocation(HANDLE_LOCATION); double dX = target.getX() - loc.getX(); double dZ = target.getZ() - loc.getZ(); double dY = target.getY() - loc.getY(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 71f728b48..83525647c 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -63,6 +63,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { return cancelReason; } + @Override + public Location getCurrentDestination() { + return targetNavigator.getCurrentDestination(); + } + @Override public Iterable getPath() { return targetNavigator.getPath(); @@ -147,6 +152,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { private int failureTimes = 0; private PathStrategy strategy; + @Override + public Location getCurrentDestination() { + return strategy.getCurrentDestination(); + } + @Override public Iterable getPath() { return strategy.getPath(); @@ -209,6 +219,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { fallback = navigator; } + @Override + public Location getCurrentDestination() { + return active.getCurrentDestination(); + } + @Override public Iterable getPath() { if (active != null) { @@ -255,6 +270,8 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { } public static interface TargetNavigator { + Location getCurrentDestination(); + Iterable getPath(); void setPath(); diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java index a0510a63c..36b1f6124 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/StraightLineNavigationStrategy.java @@ -37,6 +37,11 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy { this.npc = npc; } + @Override + public Location getCurrentDestination() { + return destination; + } + @Override public Iterable getPath() { return null; diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index 0d28f9b4f..f18cd2b70 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -86,7 +86,6 @@ public class CommandTrait extends Trait { private boolean chargeCommandCosts(Player player, Hand hand) { if (cost > 0) { - System.out.println("XYZ"); try { RegisteredServiceProvider provider = Bukkit.getServicesManager() .getRegistration(Economy.class); @@ -147,7 +146,7 @@ public class CommandTrait extends Trait { } String output = Util.prettyEnum(executionMode) + " "; if (cost > 0) { - output += "Cost: " + StringHelper.wrap(output); + output += "Cost: " + StringHelper.wrap(cost); } if (experienceCost > 0) { output += " XP cost: " + StringHelper.wrap(experienceCost); diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index 0652cd393..21c8d9ba9 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -88,6 +88,10 @@ public class NMS { return BRIDGE.getCollisionBox(block).add(block.getX(), block.getY(), block.getZ()); } + public static Location getDestination(Entity entity) { + return BRIDGE.getDestination(entity); + } + public static Field getField(Class clazz, String field) { return getField(clazz, field, true); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index 7e97076cf..d715c4cb6 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -53,6 +53,8 @@ public interface NMSBridge { public BoundingBox getCollisionBox(Block block); + public Location getDestination(Entity entity); + public GameProfileRepository getGameProfileRepository(); public float getHeadYaw(Entity entity); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index e07e89e01..26d671955 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -362,6 +362,14 @@ public class NMSImpl implements NMSBridge { return new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -563,7 +571,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1187,17 +1195,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index caa598370..4c6a1cc74 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -381,6 +381,14 @@ public class NMSImpl implements NMSBridge { return new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -601,7 +609,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1251,17 +1259,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1284,7 +1299,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index d272e7a9c..3968d0fe0 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -385,6 +385,14 @@ public class NMSImpl implements NMSBridge { return new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -605,7 +613,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1259,17 +1267,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1292,7 +1307,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index a3822c810..3a7d26546 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -406,6 +406,14 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.getBoundingBox()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -626,7 +634,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1297,17 +1305,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1330,7 +1345,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index e9117e7e7..126cd7818 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -449,6 +449,14 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.getBoundingBox()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -682,7 +690,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1357,17 +1365,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1390,7 +1405,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/PufferFishController.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/PufferFishController.java index f4c56cba1..025576a90 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/PufferFishController.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/PufferFishController.java @@ -119,11 +119,6 @@ public class PufferFishController extends MobEntityController { return npc == null ? super.d(save) : false; } - @Override - public boolean doAITick() { - return npc == null ? super.doAITick() : false; - } - @Override public void e(Vec3D vec3d) { if (npc == null || !npc.isFlyable()) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index dd748b9da..8aaba2126 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -458,6 +458,14 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.getBoundingBox()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ() > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ)))); @@ -692,7 +700,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1396,17 +1404,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1429,7 +1444,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/PufferFishController.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/PufferFishController.java index 10e5951ff..25fbfefa8 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/PufferFishController.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/PufferFishController.java @@ -121,11 +121,6 @@ public class PufferFishController extends MobEntityController { return npc == null ? super.d(save) : false; } - @Override - public boolean doAITick() { - return npc == null ? super.doAITick() : false; - } - @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) { diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 2b597666c..797548981 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -464,6 +464,14 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.getBoundingBox()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ() > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX() - tX) / (handle.locZ() - tZ)))); @@ -707,7 +715,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1419,17 +1427,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1452,7 +1467,7 @@ public class NMSImpl implements NMSBridge { @Override public void update() { updateNavigation(navigation); - } + }; } private static class NavigationIterable implements Iterable { diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/PufferFishController.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/PufferFishController.java index b8e1c0012..667ea2503 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/PufferFishController.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/PufferFishController.java @@ -173,11 +173,6 @@ public class PufferFishController extends MobEntityController { return npc; } - @Override - public boolean isEffectiveAi() { - return npc == null ? super.isEffectiveAi() : false; - } - @Override public boolean isLeashed() { if (npc == null) diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index e95b663fe..44cbc882d 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -474,6 +474,15 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.bounds()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getMoveControl() : null; + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.getZ() > tZ) return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ)))); @@ -701,7 +710,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { PathNavigation navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new MCTargetNavigator(entity, navigation, target, parameters); } @Override @@ -1409,18 +1418,25 @@ public class NMSImpl implements NMSBridge { } } - private static class NavigationFieldWrapper implements TargetNavigator { + private static class MCTargetNavigator implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final PathNavigation navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(PathNavigation navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private MCTargetNavigator(org.bukkit.entity.Entity entity, PathNavigation navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); diff --git a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/PufferFishController.java b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/PufferFishController.java index fa4535910..4fe42e215 100644 --- a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/PufferFishController.java +++ b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/PufferFishController.java @@ -25,6 +25,7 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.animal.Pufferfish; @@ -174,11 +175,6 @@ public class PufferFishController extends MobEntityController { return npc; } - @Override - public boolean isEffectiveAi() { - return npc == null ? super.isEffectiveAi() : false; - } - @Override public boolean isLeashed() { if (npc == null) @@ -257,7 +253,13 @@ public class PufferFishController extends MobEntityController { @Override public void travel(Vec3 vec3d) { if (npc == null || !npc.isFlyable()) { - super.travel(vec3d); + if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) { + this.moveRelative(0.01F, vec3d); + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.9D)); + } else { + super.travel(vec3d); + } } else { NMSImpl.flyingMoveLogic(this, vec3d); } diff --git a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/SalmonController.java b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/SalmonController.java index d0f3b8fd1..b851c90e2 100644 --- a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/SalmonController.java +++ b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/SalmonController.java @@ -229,7 +229,7 @@ public class SalmonController extends MobEntityController { @Override public void travel(Vec3 vec3d) { if (npc == null || !npc.isFlyable()) { - if (!npc.useMinecraftAI() && isInWater() ) { + if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) { this.moveRelative(0.01F, vec3d); this.move(MoverType.SELF, this.getDeltaMovement()); this.setDeltaMovement(this.getDeltaMovement().scale(0.9D)); diff --git a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/TropicalFishController.java b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/TropicalFishController.java index 81035a1ce..ef59a1603 100644 --- a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/TropicalFishController.java +++ b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/entity/TropicalFishController.java @@ -23,6 +23,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.animal.TropicalFish; import net.minecraft.world.entity.player.Player; @@ -230,7 +231,13 @@ public class TropicalFishController extends MobEntityController { @Override public void travel(Vec3 vec3d) { if (npc == null || !npc.isFlyable()) { - super.travel(vec3d); + if (!npc.useMinecraftAI() && isInWater() && !npc.getNavigator().isNavigating()) { + this.moveRelative(0.01F, vec3d); + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.9D)); + } else { + super.travel(vec3d); + } } else { NMSImpl.flyingMoveLogic(this, vec3d); } diff --git a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/util/NMSImpl.java b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/util/NMSImpl.java index 163d2baea..dacc8d025 100644 --- a/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/util/NMSImpl.java +++ b/v1_18_R1/src/main/java/net/citizensnpcs/nms/v1_18_R1/util/NMSImpl.java @@ -284,7 +284,6 @@ import net.minecraft.world.scores.PlayerTeam; @SuppressWarnings("unchecked") public class NMSImpl implements NMSBridge { - public NMSImpl() { loadEntityTypes(); } @@ -479,6 +478,15 @@ public class NMSImpl implements NMSBridge { return shape.isEmpty() ? BoundingBox.EMPTY : NMSBoundingBox.wrap(shape.bounds()); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getMoveControl() : null; + return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(), + controller.getWantedZ()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.getZ() > tZ) return (float) (-Math.toDegrees(Math.atan((handle.getX() - tX) / (handle.getZ() - tZ)))); @@ -638,8 +646,7 @@ public class NMSImpl implements NMSBridge { for (Player player : Bukkit.getOnlinePlayers()) { for (int i = 0; i < path.getNodeCount(); i++) { Node pp = path.getNode(i); - org.bukkit.block.Block block = new Vector(pp.x, pp.y, pp.z).toLocation(player.getWorld()) - .getBlock(); + org.bukkit.block.Block block = player.getWorld().getBlockAt(pp.x, pp.y, pp.z); player.sendBlockChange(block.getLocation(), block.getBlockData()); } } @@ -706,7 +713,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { PathNavigation navigation = getNavigation(entity); - return navigation == null ? null : new MCTargetNavigator(navigation, target, parameters); + return navigation == null ? null : new MCTargetNavigator(entity, navigation, target, parameters); } @Override @@ -1415,17 +1422,24 @@ public class NMSImpl implements NMSBridge { } private static class MCTargetNavigator implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final PathNavigation navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private MCTargetNavigator(PathNavigation navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private MCTargetNavigator(org.bukkit.entity.Entity entity, PathNavigation navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index f53cccfec..f785f8a38 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -314,6 +314,14 @@ public class NMSImpl implements NMSBridge { return aabb == null ? BoundingBox.EMPTY : new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f); } + @Override + public Location getDestination(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) entity).getControllerMove() : null; + return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f()); + } + private float getDragonYaw(Entity handle, double tX, double tZ) { if (handle.locZ > tZ) return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); @@ -501,7 +509,7 @@ public class NMSImpl implements NMSBridge { public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, NavigatorParameters parameters) { NavigationAbstract navigation = getNavigation(entity); - return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + return navigation == null ? null : new NavigationFieldWrapper(entity, navigation, target, parameters); } @Override @@ -1125,17 +1133,24 @@ public class NMSImpl implements NMSBridge { } private static class NavigationFieldWrapper implements TargetNavigator { + private final org.bukkit.entity.Entity entity; private final NavigationAbstract navigation; private final NavigatorParameters parameters; private final org.bukkit.entity.Entity target; - private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, - NavigatorParameters parameters) { + private NavigationFieldWrapper(org.bukkit.entity.Entity entity, NavigationAbstract navigation, + org.bukkit.entity.Entity target, NavigatorParameters parameters) { + this.entity = entity; this.navigation = navigation; this.target = target; this.parameters = parameters; } + @Override + public Location getCurrentDestination() { + return NMS.getDestination(entity); + } + @Override public Iterable getPath() { return new NavigationIterable(navigation); @@ -1449,7 +1464,6 @@ public class NMSImpl implements NMSBridge { private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST); - private static final float DEFAULT_SPEED = 1F; private static Map, Integer> ENTITY_CLASS_TO_INT; private static Map, String> ENTITY_CLASS_TO_NAME;