Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
Loading