Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Allow using degrees for ArmorStand rotations

Open SoSeDiK opened this issue 3 years ago • 12 comments

Introduces the new Rotations class that is used for storing rotations in degrees on each axis (X, Y, Z).

Currently, the patch adds usage for it for ArmorStand rotations, which makes manipulations easier and more precise (since it follows vanilla logic of using degrees instead of radians).

Example usage to set the right arm's rotation to 90 degrees on the X axis:

armorStand.setRightArmRotations(Rotations.ofDegrees(90, 0, 0));

Simple! Before you'd have to use EulerAngle with a workaround like Math.toRadians(90).

Feel free to give any feedback :)

SoSeDiK avatar May 24 '22 10:05 SoSeDiK

Using the Vector class here doesn't really make sense

kennytv avatar May 27 '22 08:05 kennytv

For me it just does the job of storing degrees for each axis 😅 Though I understand what you mean

Would you prefer a new class that would store 3 numbers? Possibly similar to EulerAngle, but for degrees? If so, any name/additional method suggestions?

SoSeDiK avatar May 27 '22 09:05 SoSeDiK

Could just go with the Vanilla name of Rotations

kennytv avatar May 28 '22 08:05 kennytv

Made a test version, open to suggestions. Rotations could be a record in theory, but I'm not 100% on this.

SoSeDiK avatar May 28 '22 13:05 SoSeDiK

Sure, making it a record would fit here

kennytv avatar May 30 '22 08:05 kennytv

Should be ready now. Namings/javadocs can be tweaked if needed.

SoSeDiK avatar May 30 '22 10:05 SoSeDiK

I’m curious what was the reasoning behind adding an entirely new type rather than just doing something like a new utility method? Because at least currently it doesn’t look immediately obvious what is the difference between these two classes… not to mention you now have to add getters and setters for each limb. Idk, just seems cluttered.

Owen1212055 avatar May 30 '22 11:05 Owen1212055

I’m curious what was the reasoning behind adding an entirely new type rather than just doing something like a new utility method? Because at least currently it doesn’t look immediately obvious what is the difference between these two classes… not to mention you now have to add getters and setters for each limb. Idk, just seems cluttered.

I'm not sure what you mean. What kind of utility method? Currently, the only way to change ArmorStand's rotations is via EulerAngle class which uses radians. Newly added Rotations follows vanilla and works with degrees. If you meant expanding EulerAngle then it'd require adding static fromDegrees() method with additional conversion methods for each axis as well as already present add/substruct (at least 9 in total) that would constantly rely on Math.toDegrees() and Math.toRadians(). I don't think this would be a better approach and I'd say would clutter EalerAngle instead.

SoSeDiK avatar May 30 '22 12:05 SoSeDiK

Since we have plans on fixing the clusterfuck that are Location and Vector usage in Bukkit, use-specific classes that can also be used elsewhere are the way to go... tho also with that in mind, one last request: Please make Rotations an interface with a private inner record implementing it. Instead of the public constructor, you then use a static ofDegrees method on the interface. Please also move it from the /util package to /math

kennytv avatar May 30 '22 12:05 kennytv

make Rotations an interface with a private inner record implementing it

I suppose you meant package-private implementation since it's not possible to have an inner private record inside the interface (classes are forced to be public static in there by default and records can't have a non-public constructor).

I tried to do it similarly to what adventure does. I'm open to any suggestions.

SoSeDiK avatar May 30 '22 15:05 SoSeDiK

Might be a little late, but any reason why we use doubles instead of Floats? Minecraft uses floats for armor stand rotations.

Owen1212055 avatar May 30 '22 15:05 Owen1212055

Might be a little late, but any reason why we use doubles instead of Floats? Minecraft uses floats for armor stand rotations.

Just for ease of use. No need to specify that the value 45.5 is float 45.5F every time or cast (float) someValue wherever you have double in your code. In theory, Rotations can be used in other places too.

SoSeDiK avatar May 30 '22 16:05 SoSeDiK