From 943714b9515598d243030c3309b240fd287a1631 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 26 Apr 2019 20:33:14 +0800 Subject: [PATCH] Minor perf improvements --- .../net/citizensnpcs/api/astar/pathfinder/DoorExaminer.java | 6 +----- .../api/astar/pathfinder/MinecraftBlockExaminer.java | 1 - .../net/citizensnpcs/api/astar/pathfinder/VectorGoal.java | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/citizensnpcs/api/astar/pathfinder/DoorExaminer.java b/src/main/java/net/citizensnpcs/api/astar/pathfinder/DoorExaminer.java index 22986d08..7ced7625 100644 --- a/src/main/java/net/citizensnpcs/api/astar/pathfinder/DoorExaminer.java +++ b/src/main/java/net/citizensnpcs/api/astar/pathfinder/DoorExaminer.java @@ -8,10 +8,6 @@ import org.bukkit.block.BlockState; import org.bukkit.material.Door; -import net.citizensnpcs.api.astar.pathfinder.BlockExaminer; -import net.citizensnpcs.api.astar.pathfinder.BlockSource; -import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; -import net.citizensnpcs.api.astar.pathfinder.PathPoint; import net.citizensnpcs.api.astar.pathfinder.PathPoint.PathCallback; import net.citizensnpcs.api.npc.NPC; @@ -36,7 +32,7 @@ static class DoorOpener implements PathCallback { public void run(NPC npc, Block point, ListIterator path) { BlockState state = point.getState(); Door door = (Door) state.getData(); - if (npc.getStoredLocation().distance(point.getLocation()) < 2) { + if (npc.getStoredLocation().distanceSquared(point.getLocation()) < 4) { boolean bottom = !door.isTopHalf(); Block set = bottom ? point : point.getRelative(BlockFace.DOWN); state = set.getState(); diff --git a/src/main/java/net/citizensnpcs/api/astar/pathfinder/MinecraftBlockExaminer.java b/src/main/java/net/citizensnpcs/api/astar/pathfinder/MinecraftBlockExaminer.java index 2e85bef2..62325b43 100644 --- a/src/main/java/net/citizensnpcs/api/astar/pathfinder/MinecraftBlockExaminer.java +++ b/src/main/java/net/citizensnpcs/api/astar/pathfinder/MinecraftBlockExaminer.java @@ -180,7 +180,6 @@ public static boolean validPosition(Block in) { Material.JUNGLE_FENCE, Material.ACACIA_FENCE, Material.DARK_OAK_FENCE); private static final Set UNWALKABLE = EnumSet.of(Material.AIR, Material.LAVA, Material.CACTUS); private static final Vector UP = new Vector(0, 1, 0); - private static Material WEB = SpigotUtil.isUsing1_13API() ? Material.COBWEB : Material.valueOf("WEB"); static { diff --git a/src/main/java/net/citizensnpcs/api/astar/pathfinder/VectorGoal.java b/src/main/java/net/citizensnpcs/api/astar/pathfinder/VectorGoal.java index f9cd8584..6f3bf81a 100644 --- a/src/main/java/net/citizensnpcs/api/astar/pathfinder/VectorGoal.java +++ b/src/main/java/net/citizensnpcs/api/astar/pathfinder/VectorGoal.java @@ -35,7 +35,7 @@ public float h(VectorNode from) { @Override public boolean isFinished(VectorNode node) { - double distanceSquared = node.getVector().distanceSquared(goal); + double distanceSquared = node.location.distanceSquared(goal); return goal.equals(node.location) || distanceSquared <= leeway; } }