From 5af202b7c61129bef8bde42c6207b19e7ba3ab47 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 26 May 2025 12:11:55 -0500 Subject: [PATCH] Clean up comments, fix logic --- .../features/directors/AADirectors.java | 4 +- .../features/directors/ArrowDirectors.java | 6 +-- .../features/directors/CannonDirectors.java | 7 ++-- .../movecraft/combat/utils/MathHelper.java | 37 ------------------- 4 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/main/java/net/countercraft/movecraft/combat/features/directors/AADirectors.java b/src/main/java/net/countercraft/movecraft/combat/features/directors/AADirectors.java index 7da4c65..589ef7c 100644 --- a/src/main/java/net/countercraft/movecraft/combat/features/directors/AADirectors.java +++ b/src/main/java/net/countercraft/movecraft/combat/features/directors/AADirectors.java @@ -98,10 +98,10 @@ private void processFireball(@NotNull SmallFireball fireball) { double speed = fireballVector.length() ; // store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1 fireballVector = fireballVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far - // the player is looking at nothing, shoot in that general direction + // shoot in that general direction Vector targetVector = p.getLocation().getDirection(); - if (AADirectorRange >= 0) { + // Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence) Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange); if (targetBlock != null && !targetBlock.getType().isAir()) { targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector()); diff --git a/src/main/java/net/countercraft/movecraft/combat/features/directors/ArrowDirectors.java b/src/main/java/net/countercraft/movecraft/combat/features/directors/ArrowDirectors.java index 5e87d53..a4d94f2 100644 --- a/src/main/java/net/countercraft/movecraft/combat/features/directors/ArrowDirectors.java +++ b/src/main/java/net/countercraft/movecraft/combat/features/directors/ArrowDirectors.java @@ -96,12 +96,12 @@ private void processArrow(@NotNull Arrow arrow) { double speed = arrowVector.length(); // store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1 arrowVector = arrowVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far - // the player is looking at nothing, shoot in that general direction + // shoot in that general direction Vector targetVector = p.getLocation().getDirection(); if (ArrowDirectorRange >= 0) { + // Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence) Block targetBlock = DirectorUtils.getDirectorBlock(p, ArrowDirectorRange); - if (targetBlock != null && !targetBlock.getType().equals(Material.AIR)) { - // shoot directly at the block the player is looking at (IE: with convergence) + if (targetBlock != null && !targetBlock.getType().isAir()) { targetVector = targetBlock.getLocation().toVector().subtract(arrow.getLocation().toVector()); targetVector = targetVector.normalize(); } diff --git a/src/main/java/net/countercraft/movecraft/combat/features/directors/CannonDirectors.java b/src/main/java/net/countercraft/movecraft/combat/features/directors/CannonDirectors.java index 7f7f705..048eb3f 100644 --- a/src/main/java/net/countercraft/movecraft/combat/features/directors/CannonDirectors.java +++ b/src/main/java/net/countercraft/movecraft/combat/features/directors/CannonDirectors.java @@ -125,13 +125,12 @@ private void processTNT(@NotNull TNTPrimed tnt) { double horizontalSpeed = tntVector.length(); tntVector = tntVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far - // the player is looking at nothing, shoot in that general direction + // shoot in that general direction Vector targetVector = p.getLocation().getDirection(); - if (CannonDirectorRange >= 0) { + // Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence) Block targetBlock = DirectorUtils.getDirectorBlock(p, CannonDirectorRange); - if (targetBlock != null && targetBlock.getType().equals(Material.AIR)) { - // shoot directly at the block the player is looking at (IE: with convergence) + if (targetBlock != null && !targetBlock.getType().isAir()) { targetVector = targetBlock.getLocation().toVector().subtract(tnt.getLocation().toVector()); } } diff --git a/src/main/java/net/countercraft/movecraft/combat/utils/MathHelper.java b/src/main/java/net/countercraft/movecraft/combat/utils/MathHelper.java index 7935943..6e39a84 100644 --- a/src/main/java/net/countercraft/movecraft/combat/utils/MathHelper.java +++ b/src/main/java/net/countercraft/movecraft/combat/utils/MathHelper.java @@ -4,21 +4,10 @@ import org.bukkit.util.Vector; public class MathHelper { - public static double clamp(double value) { - // Double.MIN_VALUE represents the lowest POSITIVE double value to match IEEE754 format return clamp(-Double.MAX_VALUE, Double.MAX_VALUE, value); } - // Same as with doubles! - public static float clamp(float value) { - return clamp(-Float.MAX_VALUE, Float.MAX_VALUE, value); - } - - public static int clamp(int value) { - return clamp(Integer.MIN_VALUE, Integer.MAX_VALUE, value); - } - public static double clamp(double min, double max, double value) { if (value > max) { return max; @@ -29,35 +18,9 @@ public static double clamp(double min, double max, double value) { return value; } - public static int clamp(int min, int max, int value) { - if (value > max) { - return max; - } - if (value < min) { - return min; - } - return value; - } - - public static float clamp(float min, float max, float value) { - if (value > max) { - return max; - } - if (value < min) { - return min; - } - return value; - } - public static void clampVectorModify(final Vector vector) { vector.setX(clamp(vector.getX())); vector.setY(clamp(vector.getY())); vector.setZ(clamp(vector.getZ())); } - public static Vector clampVector(final Vector vector) { - Vector result = vector.clone(); - clampVectorModify(result); - return result; - } - }