From 7e863e806223c889e529e1de447ae9ebd7916951 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 27 Apr 2025 02:53:59 +0200 Subject: [PATCH] Refactor entity field access with version-aware adjustments --- .../src/de/steamwar/core/BountifulWrapper9.java | 11 ++++++----- .../SpigotCore_Main/src/de/steamwar/Reflection.java | 1 + .../src/de/steamwar/entity/REntityServer.java | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index ce7f6170..156662a8 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -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 moveYaw = Reflection.getField(packetClass, "e", byte.class); - Reflection.Field 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 moveYaw = Reflection.getField(packetClass, byte.class, 0); + Reflection.Field movePitch = Reflection.getField(packetClass, byte.class, 1); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (short)(x*4096)); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 92e3d3fd..86dca0bf 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -94,6 +94,7 @@ public final class Reflection { spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$b"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index d5ced550..9296fc76 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -50,11 +50,12 @@ public class REntityServer implements Listener { private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); + private static final Class useEntityEnumActionType = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$ActionType"); private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { if(Core.getVersion() > 15) { - Reflection.Method useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); + Reflection.Method useEntityGetAction = Reflection.getTypedMethod(useEntityEnumAction, null, useEntityEnumActionType); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { getEntityAction = value -> ((Enum) value).ordinal();