mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Allow using degrees for ArmorStand rotations (#7847)
This commit is contained in:
parent
0d81f1e394
commit
c30dcbbc4c
@ -3,10 +3,152 @@ From: willies952002 <admin@domnian.com>
|
||||
Date: Thu, 26 Jul 2018 02:22:44 -0400
|
||||
Subject: [PATCH] Expand ArmorStand API
|
||||
|
||||
Add the following:
|
||||
Adds the following:
|
||||
- Add proper methods for getting and setting items in both hands. Deprecates old methods
|
||||
- Enable/Disable slot interactions
|
||||
- Allow using degrees for ArmorStand rotations (via new Rotations class)
|
||||
|
||||
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/math/Rotations.java b/src/main/java/io/papermc/paper/math/Rotations.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/math/Rotations.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.math;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * Rotations is an immutable object that stores rotations
|
||||
+ * in degrees on each axis (X, Y, Z).
|
||||
+ */
|
||||
+public interface Rotations {
|
||||
+
|
||||
+ /**
|
||||
+ * Rotations instance with every axis set to 0
|
||||
+ */
|
||||
+ Rotations ZERO = ofDegrees(0, 0, 0);
|
||||
+
|
||||
+ /**
|
||||
+ * Creates a new Rotations instance holding the provided rotations
|
||||
+ *
|
||||
+ * @param x the angle for the X axis in degrees
|
||||
+ * @param y the angle for the Y axis in degrees
|
||||
+ * @param z the angle for the Z axis in degrees
|
||||
+ * @return Rotations instance holding the provided rotations
|
||||
+ */
|
||||
+ static @NotNull Rotations ofDegrees(double x, double y, double z) {
|
||||
+ return new RotationsImpl(x, y, z);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the angle on the X axis in degrees
|
||||
+ *
|
||||
+ * @return the angle in degrees
|
||||
+ */
|
||||
+ double x();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the angle on the Y axis in degrees
|
||||
+ *
|
||||
+ * @return the angle in degrees
|
||||
+ */
|
||||
+ double y();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the angle on the Z axis in degrees
|
||||
+ *
|
||||
+ * @return the angle in degrees
|
||||
+ */
|
||||
+ double z();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns a new Rotations instance which is the result
|
||||
+ * of changing the X axis to the passed angle
|
||||
+ *
|
||||
+ * @param x the angle in degrees
|
||||
+ * @return the resultant Rotations
|
||||
+ */
|
||||
+ @NotNull Rotations withX(double x);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns a new Rotations instance which is the result
|
||||
+ * of changing the Y axis to the passed angle
|
||||
+ *
|
||||
+ * @param y the angle in degrees
|
||||
+ * @return the resultant Rotations
|
||||
+ */
|
||||
+ @NotNull Rotations withY(double y);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns a new Rotations instance which is the result
|
||||
+ * of changing the Z axis to the passed angle
|
||||
+ *
|
||||
+ * @param z the angle in degrees
|
||||
+ * @return the resultant Rotations
|
||||
+ */
|
||||
+ @NotNull Rotations withZ(double z);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns a new Rotations instance which is the result of adding
|
||||
+ * the x, y, z components to this Rotations
|
||||
+ *
|
||||
+ * @param x the angle to add to the X axis in degrees
|
||||
+ * @param y the angle to add to the Y axis in degrees
|
||||
+ * @param z the angle to add to the Z axis in degrees
|
||||
+ * @return the resultant Rotations
|
||||
+ */
|
||||
+ @NotNull Rotations add(double x, double y, double z);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns a new Rotations instance which is the result of subtracting
|
||||
+ * the x, y, z components from this Rotations
|
||||
+ *
|
||||
+ * @param x the angle to subtract from the X axis in degrees
|
||||
+ * @param y the angle to subtract from the Y axis in degrees
|
||||
+ * @param z the angle to subtract from the Z axis in degrees
|
||||
+ * @return the resultant Rotations
|
||||
+ */
|
||||
+ default @NotNull Rotations subtract(double x, double y, double z) {
|
||||
+ return add(-x, -y, -z);
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/math/RotationsImpl.java b/src/main/java/io/papermc/paper/math/RotationsImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/math/RotationsImpl.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.math;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+record RotationsImpl(double x, double y, double z) implements Rotations {
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull RotationsImpl withX(double x) {
|
||||
+ return new RotationsImpl(x, y, z);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull RotationsImpl withY(double y) {
|
||||
+ return new RotationsImpl(x, y, z);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull RotationsImpl withZ(double z) {
|
||||
+ return new RotationsImpl(x, y, z);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull RotationsImpl add(double x, double y, double z) {
|
||||
+ return new RotationsImpl(this.x + x, this.y + y, this.z + z);
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/entity/ArmorStand.java b/src/main/java/org/bukkit/entity/ArmorStand.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/entity/ArmorStand.java
|
||||
@ -99,5 +241,101 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return {@code true} if the slot is disabled, else {@code false}.
|
||||
+ */
|
||||
+ boolean isSlotDisabled(@NotNull org.bukkit.inventory.EquipmentSlot slot);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's body rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getBodyRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's body rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setBodyRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's left arm rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getLeftArmRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's left arm rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setLeftArmRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's right arm rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getRightArmRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's right arm rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setRightArmRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's left leg rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getLeftLegRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's left leg rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setLeftLegRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's right leg rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getRightLegRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's right leg rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setRightLegRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the ArmorStand's head rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @return the current rotations
|
||||
+ */
|
||||
+ @NotNull io.papermc.paper.math.Rotations getHeadRotations();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the ArmorStand's head rotations as
|
||||
+ * {@link io.papermc.paper.math.Rotations}.
|
||||
+ *
|
||||
+ * @param rotations the current rotations
|
||||
+ */
|
||||
+ void setHeadRotations(@NotNull io.papermc.paper.math.Rotations rotations);
|
||||
// Paper end
|
||||
}
|
||||
|
@ -3,13 +3,16 @@ From: willies952002 <admin@domnian.com>
|
||||
Date: Thu, 26 Jul 2018 02:25:46 -0400
|
||||
Subject: [PATCH] Implement Expanded ArmorStand API
|
||||
|
||||
Add the following:
|
||||
Adds the following:
|
||||
- Add proper methods for getting and setting items in both hands. Deprecates old methods
|
||||
- Enable/Disable slot interactions
|
||||
- Allow using degrees for ArmorStand rotations (via new Rotations class)
|
||||
|
||||
== AT ==
|
||||
public net.minecraft.world.entity.decoration.ArmorStand isDisabled(Lnet/minecraft/world/entity/EquipmentSlot;)Z
|
||||
|
||||
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
|
||||
@ -90,6 +93,74 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ public boolean isSlotDisabled(org.bukkit.inventory.EquipmentSlot slot) {
|
||||
+ return getHandle().isDisabled(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(slot));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getBodyRotations() {
|
||||
+ return fromNMSRotations(getHandle().bodyPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setBodyRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setBodyPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getLeftArmRotations() {
|
||||
+ return fromNMSRotations(getHandle().leftArmPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setLeftArmRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setLeftArmPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getRightArmRotations() {
|
||||
+ return fromNMSRotations(getHandle().rightArmPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setRightArmRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setRightArmPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getLeftLegRotations() {
|
||||
+ return fromNMSRotations(getHandle().leftLegPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setLeftLegRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setLeftLegPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getRightLegRotations() {
|
||||
+ return fromNMSRotations(getHandle().rightLegPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setRightLegRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setRightLegPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.math.Rotations getHeadRotations() {
|
||||
+ return fromNMSRotations(getHandle().headPose);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setHeadRotations(io.papermc.paper.math.Rotations rotations) {
|
||||
+ getHandle().setHeadPose(toNMSRotations(rotations));
|
||||
+ }
|
||||
+
|
||||
+ private static io.papermc.paper.math.Rotations fromNMSRotations(Rotations old) {
|
||||
+ return io.papermc.paper.math.Rotations.ofDegrees(old.getX(), old.getY(), old.getZ());
|
||||
+ }
|
||||
+
|
||||
+ private static Rotations toNMSRotations(io.papermc.paper.math.Rotations old) {
|
||||
+ return new Rotations((float) old.x(), (float) old.y(), (float) old.z());
|
||||
+ }
|
||||
+
|
||||
@Override
|
||||
public boolean canTick() {
|
||||
|
Loading…
Reference in New Issue
Block a user