Skip to content

Commit f88320f

Browse files
committed
BackwardsCompat: WrapperPlayServerSpawnEntityExperienceOrb
1 parent 8f446c3 commit f88320f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

PacketWrapper/src/main/java/com/comphenix/packetwrapper/ConversionUtil.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ private ConversionUtil() {
3434
* @return number floored
3535
*/
3636
public static int floor(double number) {
37-
int intNumber = (int) number;
38-
39-
return number < (double) intNumber ? intNumber - 1 : intNumber;
37+
final int intNumber;
38+
return number < (double) (intNumber = (int) number) ? intNumber - 1 : intNumber;
4039
}
4140
}

PacketWrapper/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerSpawnEntityExperienceOrb.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Entity getEntity(PacketEvent event) {
8585
* @return The current X
8686
*/
8787
public double getX() {
88-
return handle.getDoubles().read(0);
88+
return MAJOR_VERSION >= 9 ? handle.getDoubles().read(0) : handle.getIntegers().read(1) / 32D;
8989
}
9090

9191
/**
@@ -94,7 +94,8 @@ public double getX() {
9494
* @param value - new value.
9595
*/
9696
public void setX(double value) {
97-
handle.getDoubles().write(0, value);
97+
if (MAJOR_VERSION >= 9) handle.getDoubles().write(0, value);
98+
else handle.getIntegers().write(1, ConversionUtil.floor(value * 32));
9899
}
99100

100101
/**
@@ -105,7 +106,7 @@ public void setX(double value) {
105106
* @return The current y
106107
*/
107108
public double getY() {
108-
return handle.getDoubles().read(1);
109+
return MAJOR_VERSION >= 9 ? handle.getDoubles().read(1) : handle.getIntegers().read(2) / 32D;
109110
}
110111

111112
/**
@@ -114,7 +115,8 @@ public double getY() {
114115
* @param value - new value.
115116
*/
116117
public void setY(double value) {
117-
handle.getDoubles().write(1, value);
118+
if (MAJOR_VERSION >= 9) handle.getDoubles().write(1, value);
119+
else handle.getIntegers().write(2, ConversionUtil.floor(value * 32));
118120
}
119121

120122
/**
@@ -125,7 +127,7 @@ public void setY(double value) {
125127
* @return The current z
126128
*/
127129
public double getZ() {
128-
return handle.getDoubles().read(2);
130+
return MAJOR_VERSION >= 9 ? handle.getDoubles().read(2) : handle.getIntegers().read(3) / 32D;
129131
}
130132

131133
/**
@@ -134,7 +136,8 @@ public double getZ() {
134136
* @param value - new value.
135137
*/
136138
public void setZ(double value) {
137-
handle.getDoubles().write(2, value);
139+
if (MAJOR_VERSION >= 9) handle.getDoubles().write(2, value);
140+
else handle.getIntegers().write(3, ConversionUtil.floor(value * 32));
138141
}
139142

140143
/**
@@ -145,7 +148,7 @@ public void setZ(double value) {
145148
* @return The current Count
146149
*/
147150
public int getCount() {
148-
return handle.getIntegers().read(1);
151+
return handle.getIntegers().read(MAJOR_VERSION >= 9 ? 1 : 4);
149152
}
150153

151154
/**
@@ -154,6 +157,6 @@ public int getCount() {
154157
* @param value - new value.
155158
*/
156159
public void setCount(int value) {
157-
handle.getIntegers().write(1, value);
160+
handle.getIntegers().write(MAJOR_VERSION >= 9 ? 1 : 4, value);
158161
}
159162
}

0 commit comments

Comments
 (0)