mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 01:27:33 +01:00
Implement new PathStrategy method, improve swimming navigation
This commit is contained in:
parent
208b1c9ca2
commit
b26dfb3d0f
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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().<Boolean> get(NPC.Metadata.SWIMMING)
|
||||
: !isWaterMob(getEntity())) {
|
||||
if (navigator.isNavigating()) {
|
||||
if (!data().has(NPC.Metadata.SWIMMING) || data().<Boolean> 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().<Boolean> get(NPC.Metadata.SWIMMING)
|
||||
: !SwimmingExaminer.isWaterMob(getEntity())) {
|
||||
NMS.trySwim(getEntity());
|
||||
}
|
||||
navigator.run();
|
||||
|
@ -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<Vector> getPath() {
|
||||
return plan == null ? null : plan.getPath();
|
||||
|
@ -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<Vector> getPath() {
|
||||
return plan == null ? null : plan.getPath();
|
||||
|
@ -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<Vector> 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<Vector> 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();
|
||||
|
@ -63,6 +63,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
return cancelReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getCurrentDestination() {
|
||||
return targetNavigator.getCurrentDestination();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Vector> 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<Vector> 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<Vector> getPath() {
|
||||
if (active != null) {
|
||||
@ -255,6 +270,8 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
}
|
||||
|
||||
public static interface TargetNavigator {
|
||||
Location getCurrentDestination();
|
||||
|
||||
Iterable<Vector> getPath();
|
||||
|
||||
void setPath();
|
||||
|
@ -37,6 +37,11 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getCurrentDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Vector> getPath() {
|
||||
return null;
|
||||
|
@ -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<Economy> 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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<Vector> getPath() {
|
||||
return new NavigationIterable(navigation);
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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()) {
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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) {
|
||||
|
@ -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<Vector> 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<Vector> {
|
||||
|
@ -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)
|
||||
|
@ -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<Vector> getPath() {
|
||||
return new NavigationIterable(navigation);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Vector> getPath() {
|
||||
return new NavigationIterable(navigation);
|
||||
|
@ -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<Vector> getPath() {
|
||||
return new NavigationIterable(navigation);
|
||||
@ -1449,7 +1464,6 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Set<EntityType> 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<Class<?>, Integer> ENTITY_CLASS_TO_INT;
|
||||
private static Map<Class<?>, String> ENTITY_CLASS_TO_NAME;
|
||||
|
Loading…
Reference in New Issue
Block a user