Skip to content

Commit 0117226

Browse files
authored
Fix director convergence (#145)
1 parent 7947163 commit 0117226

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

src/main/java/net/countercraft/movecraft/combat/features/directors/AADirectors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ private void processFireball(@NotNull SmallFireball fireball) {
9898
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
9999
fireballVector = fireballVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far
100100

101-
// the player is looking at nothing, shoot in that general direction
101+
// shoot in that general direction
102102
Vector targetVector = p.getLocation().getDirection();
103-
104103
if (AADirectorRange >= 0) {
104+
// Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence)
105105
Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange);
106106
if (targetBlock != null && !targetBlock.getType().isAir()) {
107107
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector());

src/main/java/net/countercraft/movecraft/combat/features/directors/ArrowDirectors.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ private void processArrow(@NotNull Arrow arrow) {
9696
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
9797
arrowVector = arrowVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far
9898

99-
// the player is looking at nothing, shoot in that general direction
99+
// shoot in that general direction
100100
Vector targetVector = p.getLocation().getDirection();
101101
if (ArrowDirectorRange >= 0) {
102+
// Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence)
102103
Block targetBlock = DirectorUtils.getDirectorBlock(p, ArrowDirectorRange);
103-
if (targetBlock != null && !targetBlock.getType().equals(Material.AIR)) {
104-
// shoot directly at the block the player is looking at (IE: with convergence)
104+
if (targetBlock != null && !targetBlock.getType().isAir()) {
105105
targetVector = targetBlock.getLocation().toVector().subtract(arrow.getLocation().toVector());
106106
targetVector = targetVector.normalize();
107107
}

src/main/java/net/countercraft/movecraft/combat/features/directors/CannonDirectors.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,12 @@ private void processTNT(@NotNull TNTPrimed tnt) {
125125
double horizontalSpeed = tntVector.length();
126126
tntVector = tntVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far
127127

128-
// the player is looking at nothing, shoot in that general direction
128+
// shoot in that general direction
129129
Vector targetVector = p.getLocation().getDirection();
130-
131130
if (CannonDirectorRange >= 0) {
131+
// Range is greater than zero and the player is looking at a block, direct at it (IE: with convergence)
132132
Block targetBlock = DirectorUtils.getDirectorBlock(p, CannonDirectorRange);
133-
if (targetBlock != null && targetBlock.getType().equals(Material.AIR)) {
134-
// shoot directly at the block the player is looking at (IE: with convergence)
133+
if (targetBlock != null && !targetBlock.getType().isAir()) {
135134
targetVector = targetBlock.getLocation().toVector().subtract(tnt.getLocation().toVector());
136135
}
137136
}

src/main/java/net/countercraft/movecraft/combat/utils/MathHelper.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,10 @@
44
import org.bukkit.util.Vector;
55

66
public class MathHelper {
7-
87
public static double clamp(double value) {
9-
// Double.MIN_VALUE represents the lowest POSITIVE double value to match IEEE754 format
108
return clamp(-Double.MAX_VALUE, Double.MAX_VALUE, value);
119
}
1210

13-
// Same as with doubles!
14-
public static float clamp(float value) {
15-
return clamp(-Float.MAX_VALUE, Float.MAX_VALUE, value);
16-
}
17-
18-
public static int clamp(int value) {
19-
return clamp(Integer.MIN_VALUE, Integer.MAX_VALUE, value);
20-
}
21-
2211
public static double clamp(double min, double max, double value) {
2312
if (value > max) {
2413
return max;
@@ -29,35 +18,9 @@ public static double clamp(double min, double max, double value) {
2918
return value;
3019
}
3120

32-
public static int clamp(int min, int max, int value) {
33-
if (value > max) {
34-
return max;
35-
}
36-
if (value < min) {
37-
return min;
38-
}
39-
return value;
40-
}
41-
42-
public static float clamp(float min, float max, float value) {
43-
if (value > max) {
44-
return max;
45-
}
46-
if (value < min) {
47-
return min;
48-
}
49-
return value;
50-
}
51-
5221
public static void clampVectorModify(final Vector vector) {
5322
vector.setX(clamp(vector.getX()));
5423
vector.setY(clamp(vector.getY()));
5524
vector.setZ(clamp(vector.getZ()));
5625
}
57-
public static Vector clampVector(final Vector vector) {
58-
Vector result = vector.clone();
59-
clampVectorModify(result);
60-
return result;
61-
}
62-
6326
}

0 commit comments

Comments
 (0)