Refactor entity field access with version-aware adjustments

This commit is contained in:
2025-04-27 02:53:59 +02:00
parent aeff16b7dd
commit 7e863e8062
3 changed files with 9 additions and 6 deletions
@@ -85,11 +85,12 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
@Override
public BountifulWrapper.PositionSetter getRelMoveSetter(Class<?> packetClass) {
Class<?> type = Core.getVersion() > 12 ? short.class : int.class;
Reflection.Field<?> moveX = Reflection.getField(packetClass, "b", type);
Reflection.Field<?> moveY = Reflection.getField(packetClass, "c", type);
Reflection.Field<?> moveZ = Reflection.getField(packetClass, "d", type);
Reflection.Field<Byte> moveYaw = Reflection.getField(packetClass, "e", byte.class);
Reflection.Field<Byte> movePitch = Reflection.getField(packetClass, "f", byte.class);
int fieldOffset = Core.getVersion() > 12 ? 0 : 1;
Reflection.Field<?> moveX = Reflection.getField(packetClass, type, 0 + fieldOffset);
Reflection.Field<?> moveY = Reflection.getField(packetClass, type, 1 + fieldOffset);
Reflection.Field<?> moveZ = Reflection.getField(packetClass, type, 2 + fieldOffset);
Reflection.Field<Byte> moveYaw = Reflection.getField(packetClass, byte.class, 0);
Reflection.Field<Byte> movePitch = Reflection.getField(packetClass, byte.class, 1);
return (packet, x, y, z, pitch, yaw) -> {
moveX.set(packet, (short)(x*4096));