This commit is contained in:
retrooper committed 2024-05-30 22:52:04 +02:00
1 parent 239d712b5f
commit 72e617624a
3 files changed
+27 -6

No files matched your search

@@ -180,14 +180,14 @@ public class PacketTypeClasses {
GROUND = SubclassUtil.getSubClass(FLYING, 0);
}
if (POSITION == null) {
GROUND = SubclassUtil.getSubClass(FLYING, 2);
POSITION = SubclassUtil.getSubClass(FLYING, 2);
}
if (POSITION_LOOK == null) {
GROUND = SubclassUtil.getSubClass(FLYING, 3);
POSITION_LOOK = SubclassUtil.getSubClass(FLYING, 3);
}
if (LOOK == null) {
GROUND = SubclassUtil.getSubClass(FLYING, 1);
LOOK = SubclassUtil.getSubClass(FLYING, 1);
}
}
else {
@@ -416,9 +416,17 @@ public class WrappedPacket implements WrapperPacketReader, WrapperPacketWriter {
public Vector3i readBlockPosition(int index) {
Object blockPosObj = readObject(index, NMSUtils.blockPosClass);
try {
int x = (Integer) NMSUtils.getBlockPosX.invoke(blockPosObj);
int y = (Integer) NMSUtils.getBlockPosY.invoke(blockPosObj);
int z = (Integer) NMSUtils.getBlockPosZ.invoke(blockPosObj);
int x, y, z;
if (version.isNewerThanOrEquals(ServerVersion.v_1_20_5)) {
x = (int) NMSUtils.getBaseBlockPosX.get(blockPosObj);
y = (int) NMSUtils.getBaseBlockPosY.get(blockPosObj);
z = (int) NMSUtils.getBaseBlockPosZ.get(blockPosObj);
}
else {
x = (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
y = (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
z = (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
}
return new Vector3i(x, y, z);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
@@ -59,6 +59,7 @@ public final class NMSUtils {
asNMSCopy, getMessageMethod, chatFromStringMethod, getMaterialFromNMSBlock, getNMSBlockFromMaterial,
getMobEffectListId, getMobEffectListById, getItemId, getItemById, getBukkitEntity;
private static Field entityPlayerPingField, entityBoundingBoxField, mobEffectsRegistryField;
public static Field getBaseBlockPosX, getBaseBlockPosY, getBaseBlockPosZ;
private static Object minecraftServer;
private static Object minecraftServerConnection;
@@ -258,6 +259,15 @@ public final class NMSUtils {
}
}
Class<?> baseBlockPosClass = NMSUtils.getNMSClassWithoutException("BaseBlockPosition");
if (baseBlockPosClass == null) {
baseBlockPosClass = getNMClassWithoutException("core.BaseBlockPosition");
}
if (baseBlockPosClass != null) {
getBaseBlockPosX = Reflection.getField(baseBlockPosClass, int.class, 0);
getBaseBlockPosY = Reflection.getField(baseBlockPosClass, int.class, 1);
getBaseBlockPosZ = Reflection.getField(baseBlockPosClass, int.class, 2);
}
vec3DClass = NMSUtils.getNMSClassWithoutException("Vec3D");
if (vec3DClass == null) {
vec3DClass = getNMClassWithoutException("world.phys.Vec3D");
@@ -379,6 +389,9 @@ public final class NMSUtils {
// Mappings changed with 1.18
if (getBlockPosX == null) {
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass, "u", int.class);
if (getBlockPosX == null) {
}
}
if (getBlockPosY == null) {
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass, "v", int.class);