1818 */
1919package com .comphenix .packetwrapper ;
2020
21- import com .comphenix .packetwrapper .util .Removed ;
21+ import com .comphenix .packetwrapper .util .BackwardsCompatible ;
22+ import com .comphenix .packetwrapper .util .EntityUtil ;
2223import com .comphenix .protocol .PacketType ;
2324import com .comphenix .protocol .events .PacketContainer ;
2425import com .comphenix .protocol .events .PacketEvent ;
3031
3132import java .util .UUID ;
3233
33- /*
34- * public PacketPlayOutSpawnEntityLiving(EntityLiving var0) {
35- * this.a = var0.getId();
36- * this.b = var0.getUniqueID();
37- * this.c = IRegistry.ENTITY_TYPE.a(var0.getEntityType());
38- * this.d = var0.locX();
39- * this.e = var0.locY();
40- * this.f = var0.locZ();
41- * this.j = (byte)(int)(var0.yaw * 256.0F / 360.0F);
42- * this.k = (byte)(int)(var0.pitch * 256.0F / 360.0F);
43- * this.l = (byte)(int)(var0.aC * 256.0F / 360.0F);
44- * double var1 = 3.9D;
45- * Vec3D var3 = var0.getMot();
46- * double var4 = MathHelper.a(var3.x, -3.9D, 3.9D);
47- * double var6 = MathHelper.a(var3.y, -3.9D, 3.9D);
48- * double var8 = MathHelper.a(var3.z, -3.9D, 3.9D);
49- * this.g = (int)(var4 * 8000.0D);
50- * this.h = (int)(var6 * 8000.0D);
51- * this.i = (int)(var8 * 8000.0D);
52- * }
53- */
34+ @ BackwardsCompatible
5435public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
5536 public static final PacketType TYPE = PacketType .Play .Server .SPAWN_ENTITY_LIVING ;
5637
@@ -71,14 +52,13 @@ public WrapperPlayServerSpawnEntityLiving(Entity entity) {
7152
7253 // Useful constructor
7354 private static PacketContainer fromEntity (Entity entity ) {
74- if (entityConstructor == null )
75- entityConstructor = PROTOCOL_MANAGER .createPacketConstructor (TYPE , entity );
55+ if (entityConstructor == null ) entityConstructor = protocolManager ().createPacketConstructor (TYPE , entity );
7656 return entityConstructor .createPacket (entity );
7757 }
7858
7959 /**
8060 * Retrieve entity ID.
81- *
61+ *
8262 * @return The current EID
8363 */
8464 public int getEntityID () {
@@ -87,7 +67,7 @@ public int getEntityID() {
8767
8868 /**
8969 * Retrieve the entity that will be spawned.
90- *
70+ *
9171 * @param world - the current world of the entity.
9272 * @return The spawned entity.
9373 */
@@ -97,7 +77,7 @@ public Entity getEntity(World world) {
9777
9878 /**
9979 * Retrieve the entity that will be spawned.
100- *
80+ *
10181 * @param event - the packet event.
10282 * @return The spawned entity.
10383 */
@@ -117,7 +97,7 @@ public void setUniqueId(UUID value) {
11797
11898 /**
11999 * Set entity ID.
120- *
100+ *
121101 * @param value - new value.
122102 */
123103 public void setEntityID (int value ) {
@@ -126,29 +106,27 @@ public void setEntityID(int value) {
126106
127107 /**
128108 * Retrieve the type of mob.
129- *
109+ *
130110 * @return The current Type
131111 */
132- @ SuppressWarnings ("deprecation" )
133112 public EntityType getType () {
134- return EntityType . fromId (handle .getIntegers ().read (1 ));
113+ return EntityUtil . getEntityTypeById (handle .getIntegers ().read (1 ));
135114 }
136115
137116 /**
138117 * Set the type of mob.
139- *
118+ *
140119 * @param value - new value.
141120 */
142- @ SuppressWarnings ("deprecation" )
143121 public void setType (EntityType value ) {
144- handle .getIntegers ().write (1 , ( int ) value .getTypeId ());
122+ handle .getIntegers ().write (1 , EntityUtil .getTypeId (value ));
145123 }
146124
147125 /**
148126 * Retrieve the x position of the object.
149127 * <p>
150128 * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
151- *
129+ *
152130 * @return The current X
153131 */
154132 public double getX () {
@@ -157,7 +135,7 @@ public double getX() {
157135
158136 /**
159137 * Set the x position of the object.
160- *
138+ *
161139 * @param value - new value.
162140 */
163141 public void setX (double value ) {
@@ -169,7 +147,7 @@ public void setX(double value) {
169147 * Retrieve the y position of the object.
170148 * <p>
171149 * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
172- *
150+ *
173151 * @return The current y
174152 */
175153 public double getY () {
@@ -178,7 +156,7 @@ public double getY() {
178156
179157 /**
180158 * Set the y position of the object.
181- *
159+ *
182160 * @param value - new value.
183161 */
184162 public void setY (double value ) {
@@ -190,7 +168,7 @@ public void setY(double value) {
190168 * Retrieve the z position of the object.
191169 * <p>
192170 * Note that the coordinate is rounded off to the nearest 1/32 of a meter.
193- *
171+ *
194172 * @return The current z
195173 */
196174 public double getZ () {
@@ -199,7 +177,7 @@ public double getZ() {
199177
200178 /**
201179 * Set the z position of the object.
202- *
180+ *
203181 * @param value - new value.
204182 */
205183 public void setZ (double value ) {
@@ -209,7 +187,7 @@ public void setZ(double value) {
209187
210188 /**
211189 * Retrieve the yaw.
212- *
190+ *
213191 * @return The current Yaw
214192 */
215193 public float getYaw () {
@@ -218,16 +196,16 @@ public float getYaw() {
218196
219197 /**
220198 * Set the yaw of the spawned mob.
221- *
199+ *
222200 * @param value - new yaw.
223201 */
224202 public void setYaw (float value ) {
225- handle .getBytes ().write (0 , (byte ) (value * 256.0F / 360.0F ));
203+ handle .getBytes ().write (0 , (byte ) (int ) ( value * 256.0F / 360.0F ));
226204 }
227205
228206 /**
229207 * Retrieve the pitch.
230- *
208+ *
231209 * @return The current pitch
232210 */
233211 public float getPitch () {
@@ -236,16 +214,16 @@ public float getPitch() {
236214
237215 /**
238216 * Set the pitch of the spawned mob.
239- *
217+ *
240218 * @param value - new pitch.
241219 */
242220 public void setPitch (float value ) {
243- handle .getBytes ().write (1 , (byte ) (value * 256.0F / 360.0F ));
221+ handle .getBytes ().write (1 , (byte ) (int ) ( value * 256.0F / 360.0F ));
244222 }
245223
246224 /**
247225 * Retrieve the yaw of the mob's head.
248- *
226+ *
249227 * @return The current yaw.
250228 */
251229 public float getHeadPitch () {
@@ -254,16 +232,16 @@ public float getHeadPitch() {
254232
255233 /**
256234 * Set the yaw of the mob's head.
257- *
235+ *
258236 * @param value - new yaw.
259237 */
260238 public void setHeadPitch (float value ) {
261- handle .getBytes ().write (2 , (byte ) (value * 256.0F / 360.0F ));
239+ handle .getBytes ().write (2 , (byte ) (int ) ( value * 256.0F / 360.0F ));
262240 }
263241
264242 /**
265243 * Retrieve the velocity in the x axis.
266- *
244+ *
267245 * @return The current velocity X
268246 */
269247 public double getVelocityX () {
@@ -272,16 +250,16 @@ public double getVelocityX() {
272250
273251 /**
274252 * Set the velocity in the x axis.
275- *
253+ *
276254 * @param value - new value.
277255 */
278256 public void setVelocityX (double value ) {
279- handle .getIntegers ().write (MINOR_VERSION >= 9 ? 2 : 5 , (int ) (value * 8000.0D ));
257+ handle .getIntegers ().write (MINOR_VERSION >= 9 ? 2 : 5 , (int ) (ConversionUtil . fitBetween ( value , - 3.9 , 3.9 ) * 8000.0D ));
280258 }
281259
282260 /**
283261 * Retrieve the velocity in the y axis.
284- *
262+ *
285263 * @return The current velocity y
286264 */
287265 public double getVelocityY () {
@@ -290,16 +268,16 @@ public double getVelocityY() {
290268
291269 /**
292270 * Set the velocity in the y axis.
293- *
271+ *
294272 * @param value - new value.
295273 */
296274 public void setVelocityY (double value ) {
297- handle .getIntegers ().write (MINOR_VERSION >= 9 ? 3 : 6 , (int ) (value * 8000.0D ));
275+ handle .getIntegers ().write (MINOR_VERSION >= 9 ? 3 : 6 , (int ) (ConversionUtil . fitBetween ( value , - 3.9 , 3.9 ) * 8000.0D ));
298276 }
299277
300278 /**
301279 * Retrieve the velocity in the z axis.
302- *
280+ *
303281 * @return The current velocity z
304282 */
305283 public double getVelocityZ () {
@@ -308,32 +286,34 @@ public double getVelocityZ() {
308286
309287 /**
310288 * Set the velocity in the z axis.
311- *
289+ *
312290 * @param value - new value.
313291 */
314292 public void setVelocityZ (double value ) {
315- handle .getIntegers ().write (MINOR_VERSION >= 9 ? 4 : 7 , (int ) (value * 8000.0D ));
293+ handle .getIntegers ().write (MINOR_VERSION >= 9 ? 4 : 7 , (int ) (ConversionUtil . fitBetween ( value , - 3.9 , 3.9 ) * 8000.0D ));
316294 }
317295
318296 /**
319- * Retrieve the data watcher. This was removed in 1.15
297+ * Retrieve the data watcher.
320298 * <p>
321299 * Content varies by mob, see Entities.
322- *
300+ *
323301 * @return The current Metadata
324302 */
325- @ Removed
303+ @ BackwardsCompatible ( untilMinor = 14 )
326304 public WrappedDataWatcher getMetadata () {
305+ if (MINOR_VERSION >= 15 ) throw new UnsupportedOperationException ("Unsupported on versions greater than 1.14" );
327306 return handle .getDataWatcherModifier ().read (0 );
328307 }
329308
330309 /**
331- * Set the data watcher. This was removed in 1.15.
332- *
310+ * Set the data watcher.
311+ *
333312 * @param value - new value.
334313 */
335- @ Removed
314+ @ BackwardsCompatible ( untilMinor = 14 )
336315 public void setMetadata (WrappedDataWatcher value ) {
316+ if (MINOR_VERSION >= 15 ) throw new UnsupportedOperationException ("Unsupported on versions greater than 1.14" );
337317 handle .getDataWatcherModifier ().write (0 , value );
338318 }
339319}
0 commit comments