From 988f392c4e4349774a0f834b14439b6727211488 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 5 Jun 2021 17:21:12 +0200 Subject: [PATCH 1/3] Optimize ArrowStopper --- .../steamwar/fightsystem/listener/ArrowStopper.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 35d8af1..9eff32a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -61,18 +61,23 @@ public class ArrowStopper { private boolean checkBlocks(Block start, Block end) { Block cursor = start; + BlockFace from = BlockFace.SELF; while (!cursor.getLocation().equals(end.getLocation())) { BlockFace nearest = BlockFace.SELF; - double nearestDistance = cursor.getLocation().distance(end.getLocation()); + double nearestDistance = getSquareDistance(cursor.getLocation(), end.getLocation()); for (BlockFace face : BLOCK_FACES) { + if(face == from) { + continue; + } Block relative = cursor.getRelative(face); - double distance = relative.getLocation().distance(end.getLocation()); + double distance = getSquareDistance(relative.getLocation(), end.getLocation()); if(distance < nearestDistance) { nearestDistance = distance; nearest = face; } } + from = nearest; cursor = cursor.getRelative(nearest); if(checkBlock(cursor)) return true; @@ -81,6 +86,10 @@ public class ArrowStopper { return false; } + private double getSquareDistance(Location loc1, Location loc2) { + return loc1.getX() * loc2.getX() + loc1.getY() * loc2.getY() + loc1.getZ() * loc2.getZ(); + } + private boolean checkBlock(Block block) { return Config.HiddenBlocks.contains(block.getType().name().toLowerCase()); } -- 2.39.2 From 0c9a67a28e74e478dd373d07b9771a695bffa39a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jun 2021 15:14:34 +0200 Subject: [PATCH 2/3] Reverting --- .../de/steamwar/fightsystem/listener/ArrowStopper.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 9eff32a..e1dd4d0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -65,13 +65,13 @@ public class ArrowStopper { while (!cursor.getLocation().equals(end.getLocation())) { BlockFace nearest = BlockFace.SELF; - double nearestDistance = getSquareDistance(cursor.getLocation(), end.getLocation()); + double nearestDistance = cursor.getLocation().distanceSquared(end.getLocation()); for (BlockFace face : BLOCK_FACES) { if(face == from) { continue; } Block relative = cursor.getRelative(face); - double distance = getSquareDistance(relative.getLocation(), end.getLocation()); + double distance = relative.getLocation().distanceSquared(end.getLocation()); if(distance < nearestDistance) { nearestDistance = distance; nearest = face; @@ -86,10 +86,6 @@ public class ArrowStopper { return false; } - private double getSquareDistance(Location loc1, Location loc2) { - return loc1.getX() * loc2.getX() + loc1.getY() * loc2.getY() + loc1.getZ() * loc2.getZ(); - } - private boolean checkBlock(Block block) { return Config.HiddenBlocks.contains(block.getType().name().toLowerCase()); } -- 2.39.2 From 75017cc628562c2b77f9815670d2b4da5a8a0f4c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Jun 2021 15:20:41 +0200 Subject: [PATCH 3/3] Smoll Fix --- .../src/de/steamwar/fightsystem/listener/ArrowStopper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index e1dd4d0..6da7da5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -77,7 +77,7 @@ public class ArrowStopper { nearest = face; } } - from = nearest; + from = nearest.getOppositeFace(); cursor = cursor.getRelative(nearest); if(checkBlock(cursor)) return true; -- 2.39.2