18
18
*/
19
19
package com .comphenix .packetwrapper ;
20
20
21
- import com .comphenix .packetwrapper .util .Removed ;
21
+ import com .comphenix .packetwrapper .util .BackwardsCompatible ;
22
+ import com .comphenix .packetwrapper .util .EntityUtil ;
22
23
import com .comphenix .protocol .PacketType ;
23
24
import com .comphenix .protocol .events .PacketContainer ;
24
25
import com .comphenix .protocol .events .PacketEvent ;
30
31
31
32
import java .util .UUID ;
32
33
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
54
35
public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
55
36
public static final PacketType TYPE = PacketType .Play .Server .SPAWN_ENTITY_LIVING ;
56
37
@@ -71,14 +52,13 @@ public WrapperPlayServerSpawnEntityLiving(Entity entity) {
71
52
72
53
// Useful constructor
73
54
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 );
76
56
return entityConstructor .createPacket (entity );
77
57
}
78
58
79
59
/**
80
60
* Retrieve entity ID.
81
- *
61
+ *
82
62
* @return The current EID
83
63
*/
84
64
public int getEntityID () {
@@ -87,7 +67,7 @@ public int getEntityID() {
87
67
88
68
/**
89
69
* Retrieve the entity that will be spawned.
90
- *
70
+ *
91
71
* @param world - the current world of the entity.
92
72
* @return The spawned entity.
93
73
*/
@@ -97,7 +77,7 @@ public Entity getEntity(World world) {
97
77
98
78
/**
99
79
* Retrieve the entity that will be spawned.
100
- *
80
+ *
101
81
* @param event - the packet event.
102
82
* @return The spawned entity.
103
83
*/
@@ -117,7 +97,7 @@ public void setUniqueId(UUID value) {
117
97
118
98
/**
119
99
* Set entity ID.
120
- *
100
+ *
121
101
* @param value - new value.
122
102
*/
123
103
public void setEntityID (int value ) {
@@ -126,29 +106,27 @@ public void setEntityID(int value) {
126
106
127
107
/**
128
108
* Retrieve the type of mob.
129
- *
109
+ *
130
110
* @return The current Type
131
111
*/
132
- @ SuppressWarnings ("deprecation" )
133
112
public EntityType getType () {
134
- return EntityType . fromId (handle .getIntegers ().read (1 ));
113
+ return EntityUtil . getEntityTypeById (handle .getIntegers ().read (1 ));
135
114
}
136
115
137
116
/**
138
117
* Set the type of mob.
139
- *
118
+ *
140
119
* @param value - new value.
141
120
*/
142
- @ SuppressWarnings ("deprecation" )
143
121
public void setType (EntityType value ) {
144
- handle .getIntegers ().write (1 , ( int ) value .getTypeId ());
122
+ handle .getIntegers ().write (1 , EntityUtil .getTypeId (value ));
145
123
}
146
124
147
125
/**
148
126
* Retrieve the x position of the object.
149
127
* <p>
150
128
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
151
- *
129
+ *
152
130
* @return The current X
153
131
*/
154
132
public double getX () {
@@ -157,7 +135,7 @@ public double getX() {
157
135
158
136
/**
159
137
* Set the x position of the object.
160
- *
138
+ *
161
139
* @param value - new value.
162
140
*/
163
141
public void setX (double value ) {
@@ -169,7 +147,7 @@ public void setX(double value) {
169
147
* Retrieve the y position of the object.
170
148
* <p>
171
149
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
172
- *
150
+ *
173
151
* @return The current y
174
152
*/
175
153
public double getY () {
@@ -178,7 +156,7 @@ public double getY() {
178
156
179
157
/**
180
158
* Set the y position of the object.
181
- *
159
+ *
182
160
* @param value - new value.
183
161
*/
184
162
public void setY (double value ) {
@@ -190,7 +168,7 @@ public void setY(double value) {
190
168
* Retrieve the z position of the object.
191
169
* <p>
192
170
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
193
- *
171
+ *
194
172
* @return The current z
195
173
*/
196
174
public double getZ () {
@@ -199,7 +177,7 @@ public double getZ() {
199
177
200
178
/**
201
179
* Set the z position of the object.
202
- *
180
+ *
203
181
* @param value - new value.
204
182
*/
205
183
public void setZ (double value ) {
@@ -209,7 +187,7 @@ public void setZ(double value) {
209
187
210
188
/**
211
189
* Retrieve the yaw.
212
- *
190
+ *
213
191
* @return The current Yaw
214
192
*/
215
193
public float getYaw () {
@@ -218,16 +196,16 @@ public float getYaw() {
218
196
219
197
/**
220
198
* Set the yaw of the spawned mob.
221
- *
199
+ *
222
200
* @param value - new yaw.
223
201
*/
224
202
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 ));
226
204
}
227
205
228
206
/**
229
207
* Retrieve the pitch.
230
- *
208
+ *
231
209
* @return The current pitch
232
210
*/
233
211
public float getPitch () {
@@ -236,16 +214,16 @@ public float getPitch() {
236
214
237
215
/**
238
216
* Set the pitch of the spawned mob.
239
- *
217
+ *
240
218
* @param value - new pitch.
241
219
*/
242
220
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 ));
244
222
}
245
223
246
224
/**
247
225
* Retrieve the yaw of the mob's head.
248
- *
226
+ *
249
227
* @return The current yaw.
250
228
*/
251
229
public float getHeadPitch () {
@@ -254,16 +232,16 @@ public float getHeadPitch() {
254
232
255
233
/**
256
234
* Set the yaw of the mob's head.
257
- *
235
+ *
258
236
* @param value - new yaw.
259
237
*/
260
238
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 ));
262
240
}
263
241
264
242
/**
265
243
* Retrieve the velocity in the x axis.
266
- *
244
+ *
267
245
* @return The current velocity X
268
246
*/
269
247
public double getVelocityX () {
@@ -272,16 +250,16 @@ public double getVelocityX() {
272
250
273
251
/**
274
252
* Set the velocity in the x axis.
275
- *
253
+ *
276
254
* @param value - new value.
277
255
*/
278
256
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 ));
280
258
}
281
259
282
260
/**
283
261
* Retrieve the velocity in the y axis.
284
- *
262
+ *
285
263
* @return The current velocity y
286
264
*/
287
265
public double getVelocityY () {
@@ -290,16 +268,16 @@ public double getVelocityY() {
290
268
291
269
/**
292
270
* Set the velocity in the y axis.
293
- *
271
+ *
294
272
* @param value - new value.
295
273
*/
296
274
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 ));
298
276
}
299
277
300
278
/**
301
279
* Retrieve the velocity in the z axis.
302
- *
280
+ *
303
281
* @return The current velocity z
304
282
*/
305
283
public double getVelocityZ () {
@@ -308,32 +286,34 @@ public double getVelocityZ() {
308
286
309
287
/**
310
288
* Set the velocity in the z axis.
311
- *
289
+ *
312
290
* @param value - new value.
313
291
*/
314
292
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 ));
316
294
}
317
295
318
296
/**
319
- * Retrieve the data watcher. This was removed in 1.15
297
+ * Retrieve the data watcher.
320
298
* <p>
321
299
* Content varies by mob, see Entities.
322
- *
300
+ *
323
301
* @return The current Metadata
324
302
*/
325
- @ Removed
303
+ @ BackwardsCompatible ( untilMinor = 14 )
326
304
public WrappedDataWatcher getMetadata () {
305
+ if (MINOR_VERSION >= 15 ) throw new UnsupportedOperationException ("Unsupported on versions greater than 1.14" );
327
306
return handle .getDataWatcherModifier ().read (0 );
328
307
}
329
308
330
309
/**
331
- * Set the data watcher. This was removed in 1.15.
332
- *
310
+ * Set the data watcher.
311
+ *
333
312
* @param value - new value.
334
313
*/
335
- @ Removed
314
+ @ BackwardsCompatible ( untilMinor = 14 )
336
315
public void setMetadata (WrappedDataWatcher value ) {
316
+ if (MINOR_VERSION >= 15 ) throw new UnsupportedOperationException ("Unsupported on versions greater than 1.14" );
337
317
handle .getDataWatcherModifier ().write (0 , value );
338
318
}
339
319
}
0 commit comments