-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature, Improvement]: Disable converging, prevent IllegalArgumentException #141
base: main
Are you sure you want to change the base?
Conversation
DerToaster98
commented
Nov 24, 2024
- Converging automatically toggles off, if the range is less than 0. We tried setting it to 0 with the old version and it still tried to converge. Specifying a long list of blocks that are "transparent" is not really a option if you dont want converging
- Our console used to get spammed with "X is not finite" exceptions. Clamped the vectors now so it does not run into that try block as printing out all those exceptions slows the server down.
Need to do some more testing, looks like i broke directors with the clamping |
(cherry picked from commit acce226)
Every time changes are attempted it breaks things, I am hesitant to accept changes here. |
For your information, that has been fixed in the following commit. That patch is live on TTE since 3 weeks ago and has seen a lot of combat since then. Works just fine. |
If you are intersted, the part that broke it is explained in the commit "correct mathhelper". Basically Double.MIN_VALUE is not what one expects at first glance, instead it is the lowest positvice double value to match IEEE754 format. What the function does overall is limiting the value between the min and max limits, which prevents the "not finite" exception from occuring |
else { // shoot directly at the block the player is looking at (IE: with convergence) | ||
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector()); | ||
targetVector = targetVector.normalize(); | ||
if (AADirectorRange >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this check? If you mean to check the configuration, that should be done once on load not on every fireball.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a less than comparison. Sure, i could cache it in a boolean value, but that isn't really a difference. Point is to be able to actually disable converging completely. With the "original" version of yours that is NOT possible (tried setting it to negative values and 0). The only "proper" way to disable converging on your version is defining a long list of blocks that are "transparent", not really clean to manage and unnecessary. Plus, if the distance is less than or equals to 0, performing the raycast is completely unnecessary.
Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange); | ||
if (targetBlock != null && !targetBlock.getType().isAir()) { | ||
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector()); | ||
targetVector = targetVector.normalize(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of changing this code for no effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because DirectorUtils will ALWAYS execute a raycast, regardless of what you give it, sure the relevant code here could be included there however.
Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange); | ||
Vector targetVector; | ||
// the player is looking at nothing, shoot in that general direction | ||
Vector targetVector = p.getLocation().getDirection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because DirectorUtils will ALWAYS execute a raycast, regardless of what you give it, sure the relevant code here could be included there however.
// the player is looking at nothing, shoot in that general direction | ||
Vector targetVector = p.getLocation().getDirection(); | ||
if (ArrowDirectorRange >= 0) { | ||
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) | ||
targetVector = targetBlock.getLocation().toVector().subtract(arrow.getLocation().toVector()); | ||
targetVector = targetVector.normalize(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because DirectorUtils will ALWAYS execute a raycast, regardless of what you give it, sure the relevant code here could be included there however.
// the player is looking at nothing, shoot in that general direction | ||
Vector targetVector = p.getLocation().getDirection(); | ||
|
||
if (CannonDirectorRange >= 0) { | ||
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) | ||
targetVector = targetBlock.getLocation().toVector().subtract(tnt.getLocation().toVector()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because DirectorUtils will ALWAYS execute a raycast, regardless of what you give it, sure the relevant code here could be included there however.
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; | ||
} | ||
if (value < min) { | ||
return min; | ||
} | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this should be replaced with one single utility function in Directors.java
which clamps an entire vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not director specific code. It is math. Thus one does not expect it to be in DirectorUtils, that'y why it is in a separate MathHelper class cause it makes more sense there logically. I can add a function to clamp an entire vector.
Functions should be where they thematically fit.