aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0130-Expand-ArmorStand-API.patch
blob: 7df27326f11e0601082aa017824a18d8c01c1583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: willies952002 <admin@domnian.com>
Date: Thu, 26 Jul 2018 02:22:44 -0400
Subject: [PATCH] Expand ArmorStand API

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..0ac1618113699ac50b9c35294bf23fb9fb7cfbad
--- /dev/null
+++ b/src/main/java/io/papermc/paper/math/Rotations.java
@@ -0,0 +1,100 @@
+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..53359ab4a6659bce895deef6a21cde848d3cadcd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/math/RotationsImpl.java
@@ -0,0 +1,27 @@
+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 2ee3814a52945f541e049b621b9552f8ae9e261d..575d58d96445e9ef3711cd6613471d5fe17bbb10 100644
--- a/src/main/java/org/bukkit/entity/ArmorStand.java
+++ b/src/main/java/org/bukkit/entity/ArmorStand.java
@@ -14,7 +14,7 @@ public interface ArmorStand extends LivingEntity {
      *
      * @return the held item
      * @see #getEquipment()
-     * @deprecated prefer {@link EntityEquipment#getItemInHand()}
+     * @deprecated prefer {@link ArmorStand#getItem(EquipmentSlot)} // Paper
      */
     @NotNull
     @Deprecated
@@ -26,7 +26,7 @@ public interface ArmorStand extends LivingEntity {
      * @param item the item to hold
      * @see #getEquipment()
      * @deprecated prefer
-     * {@link EntityEquipment#setItemInHand(org.bukkit.inventory.ItemStack)}
+     * {@link ArmorStand#setItem(EquipmentSlot, ItemStack)} // Paper
      */
     @Deprecated
     void setItemInHand(@Nullable ItemStack item);
@@ -379,5 +379,169 @@ public interface ArmorStand extends LivingEntity {
      * @param tick {@code true} if this armour stand can tick, {@code false} otherwise
      */
     void setCanTick(final boolean tick);
+
+    /**
+     * Returns the item the armor stand has
+     * equip in the given equipment slot
+     *
+     * @param slot the equipment slot to get
+     * @return the ItemStack in the equipment slot
+     * @throws IllegalArgumentException if the slot is invalid for the entity
+     */
+    @NotNull
+    ItemStack getItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot);
+
+    /**
+     * Sets the item the armor stand has
+     * equip in the given equipment slot
+     *
+     * @param slot the equipment slot to set
+     * @param item the item to hold
+     * @throws IllegalArgumentException if the slot is invalid for the entity
+     */
+    void setItem(@NotNull final org.bukkit.inventory.EquipmentSlot slot, @Nullable final ItemStack item);
+
+    /**
+     * Get the list of disabled slots
+     *
+     * @return list of disabled slots
+     */
+    @NotNull
+    java.util.Set<org.bukkit.inventory.EquipmentSlot> getDisabledSlots();
+
+    /**
+     * Set the disabled slots
+     *
+     * This makes it so a player is unable to interact with the Armor Stand to place, remove, or replace an item in the given slot(s)
+     * Note: Once a slot is disabled, the only way to get an item back it to break the armor stand.
+     *
+     * @param slots var-arg array of slots to lock
+     */
+    void setDisabledSlots(@NotNull org.bukkit.inventory.EquipmentSlot... slots);
+
+    /**
+     * Disable specific slots, adding them
+     * to the currently disabled slots
+     *
+     * This makes it so a player is unable to interact with the Armor Stand to place, remove, or replace an item in the given slot(s)
+     * Note: Once a slot is disabled, the only way to get an item back it to break the armor stand.
+     *
+     * @param slots var-arg array of slots to lock
+     */
+    void addDisabledSlots(@NotNull final org.bukkit.inventory.EquipmentSlot... slots);
+
+    /**
+     * Remove the given slots from the disabled
+     * slots list, enabling them.
+     *
+     * This makes it so a player is able to interact with the Armor Stand to place, remove, or replace an item in the given slot(s)
+     *
+     * @param slots var-arg array of slots to unlock
+     */
+    void removeDisabledSlots(@NotNull final org.bukkit.inventory.EquipmentSlot... slots);
+
+    /**
+     * Check if a specific slot is disabled
+     *
+     * @param slot The slot to check
+     * @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
 }