Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

DerToaster98
Copy link
Contributor

  • 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.

@DerToaster98 DerToaster98 marked this pull request as draft November 24, 2024 17:45
@DerToaster98
Copy link
Contributor Author

Need to do some more testing, looks like i broke directors with the clamping

(cherry picked from commit acce226)
@DerToaster98 DerToaster98 marked this pull request as ready for review November 24, 2024 18:10
@TylerS1066
Copy link
Collaborator

Need to do some more testing, looks like i broke directors with the clamping

Every time changes are attempted it breaks things, I am hesitant to accept changes here.

@DerToaster98
Copy link
Contributor Author

Need to do some more testing, looks like i broke directors with the clamping

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.

@DerToaster98
Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Comment on lines +105 to +109
Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange);
if (targetBlock != null && !targetBlock.getType().isAir()) {
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector());
targetVector = targetVector.normalize();
}
Copy link
Collaborator

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?

Copy link
Contributor Author

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

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.

Comment on lines +99 to +107
// 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();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Contributor Author

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.

Comment on lines +128 to +137
// 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());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Contributor Author

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.

Comment on lines +11 to +47
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;
}
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants