Make Minecraft navigation canNavigateTo non destructive

This commit is contained in:
fullwall 2024-12-21 12:39:59 +08:00
parent b58a7a2040
commit a96d800c91
16 changed files with 102 additions and 7 deletions

View File

@ -41,7 +41,6 @@ import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.SpigotUtil; import net.citizensnpcs.api.util.SpigotUtil;
import net.citizensnpcs.npc.ai.AStarNavigationStrategy.AStarPlanner; import net.citizensnpcs.npc.ai.AStarNavigationStrategy.AStarPlanner;
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
import net.citizensnpcs.trait.RotationTrait; import net.citizensnpcs.trait.RotationTrait;
import net.citizensnpcs.trait.RotationTrait.PacketRotationSession; import net.citizensnpcs.trait.RotationTrait.PacketRotationSession;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
@ -104,8 +103,7 @@ public class CitizensNavigator implements Navigator, Runnable {
planner.tick(Setting.MAXIMUM_ASTAR_ITERATIONS.asInt(), Setting.MAXIMUM_ASTAR_ITERATIONS.asInt()); planner.tick(Setting.MAXIMUM_ASTAR_ITERATIONS.asInt(), Setting.MAXIMUM_ASTAR_ITERATIONS.asInt());
return planner.plan != null; return planner.plan != null;
} else { } else {
MCNavigator nav = NMS.getTargetNavigator(npc.getEntity(), dest, params); return NMS.canNavigateTo(npc.getEntity(), dest, params);
return nav.getCancelReason() == null;
} }
} }

View File

@ -154,6 +154,10 @@ public class NMS {
BRIDGE.cancelMoveDestination(entity); BRIDGE.cancelMoveDestination(entity);
} }
public static boolean canNavigateTo(Entity entity, Location dest, NavigatorParameters params) {
return BRIDGE.canNavigateTo(entity, dest, params);
}
public static void clearCustomNBT(ItemMeta meta) { public static void clearCustomNBT(ItemMeta meta) {
if (CUSTOM_NBT_TAG_MISSING) if (CUSTOM_NBT_TAG_MISSING)
return; return;

View File

@ -63,6 +63,8 @@ public interface NMSBridge {
public void cancelMoveDestination(Entity entity); public void cancelMoveDestination(Entity entity);
public boolean canNavigateTo(Entity entity, Location dest, NavigatorParameters params);
public default Iterable<Object> createBundlePacket(List<Object> packets) { public default Iterable<Object> createBundlePacket(List<Object> packets) {
return packets; return packets;
} }
@ -95,12 +97,12 @@ public interface NMSBridge {
public Location getDestination(Entity entity); public Location getDestination(Entity entity);
public float getForwardBackwardMovement(Entity entity);
public GameProfileRepository getGameProfileRepository(); public GameProfileRepository getGameProfileRepository();
public float getHeadYaw(Entity entity); public float getHeadYaw(Entity entity);
public float getForwardBackwardMovement(Entity entity);
public EntityPacketTracker getPacketTracker(Entity entity); public EntityPacketTracker getPacketTracker(Entity entity);
public List<Entity> getPassengers(Entity entity); public List<Entity> getPassengers(Entity entity);
@ -129,14 +131,14 @@ public interface NMSBridge {
public Entity getVehicle(Entity entity); public Entity getVehicle(Entity entity);
public float getXZMovement(Entity entity);
public default Collection<Player> getViewingPlayers(Entity entity) { public default Collection<Player> getViewingPlayers(Entity entity) {
return entity.getTrackedBy(); return entity.getTrackedBy();
} }
public double getWidth(Entity entity); public double getWidth(Entity entity);
public float getXZMovement(Entity entity);
public float getYaw(Entity entity); public float getYaw(Entity entity);
public boolean isOnGround(Entity entity); public boolean isOnGround(Entity entity);

View File

@ -320,6 +320,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -341,6 +341,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -347,6 +347,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -366,6 +366,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -411,6 +411,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -426,6 +426,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -439,6 +439,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ(), 1) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -452,6 +452,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final PathNavigation navigation = getNavigation(entity);
return navigation.createPath(new BlockPos(dest.getX(), dest.getY(), dest.getZ()), 1) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -458,6 +458,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final PathNavigation navigation = getNavigation(entity);
return navigation.createPath(new BlockPos(dest.getX(), dest.getY(), dest.getZ()), 1) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);

View File

@ -496,6 +496,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final PathNavigation navigation = getNavigation(entity);
return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null;
}
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Iterable<Object> createBundlePacket(List source) { public Iterable<Object> createBundlePacket(List source) {

View File

@ -507,6 +507,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final PathNavigation navigation = getNavigation(entity);
return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null;
}
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Iterable<Object> createBundlePacket(List source) { public Iterable<Object> createBundlePacket(List source) {

View File

@ -494,6 +494,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final PathNavigation navigation = getNavigation(entity);
return navigation.createPath(BlockPos.containing(dest.getX(), dest.getY(), dest.getZ()), 1) != null;
}
@Override @Override
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public Iterable<Object> createBundlePacket(List source) { public Iterable<Object> createBundlePacket(List source) {

View File

@ -301,6 +301,13 @@ public class NMSImpl implements NMSBridge {
} }
} }
@Override
public boolean canNavigateTo(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
final NavigationAbstract navigation = getNavigation(entity);
return navigation.a(dest.getX(), dest.getY(), dest.getZ()) != null;
}
@Override @Override
public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) { public EntityPacketTracker createPacketTracker(org.bukkit.entity.Entity entity, PacketAggregator agg) {
Entity handle = getHandle(entity); Entity handle = getHandle(entity);