diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java index e01a06fc..3bd27a0d 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java @@ -33,7 +33,7 @@ public class BountifulWrapper21 extends BountifulWrapper9 { return (packet, x, y, z, pitch, yaw) -> { PositionMoveRotation pos = field.get(packet); - field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), yaw, pitch)); + field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos == null ? new Vec3D(0, 0, 0) : pos.b(), yaw, pitch)); }; } catch (IllegalArgumentException e) { return super.getPositionSetter(packetClass, fieldOffset); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java index 92e3d3fd..e9144f26 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -177,9 +177,30 @@ public final class Reflection { } public void set(Object target, Object value) { + // This now works for Fields in records! try { - f.set(target, value); - } catch (IllegalAccessException e) { + long offset = Unsafe.getUnsafe().objectFieldOffset(f); + Class type = f.getType(); + if (type == int.class) { + Unsafe.getUnsafe().putInt(target, offset, (Integer) value); + } else if (type == float.class) { + Unsafe.getUnsafe().putFloat(target, offset, (Float) value); + } else if (type == double.class) { + Unsafe.getUnsafe().putDouble(target, offset, (Double) value); + } else if (type == boolean.class) { + Unsafe.getUnsafe().putBoolean(target, offset, (Boolean) value); + } else if (type == byte.class) { + Unsafe.getUnsafe().putByte(target, offset, (Byte) value); + } else if (type == char.class) { + Unsafe.getUnsafe().putChar(target, offset, (Character) value); + } else if (type == short.class) { + Unsafe.getUnsafe().putShort(target, offset, (Short) value); + } else if (type == long.class) { + Unsafe.getUnsafe().putLong(target, offset, (Long) value); + } else { + Unsafe.getUnsafe().putReference(target, offset, value); + } + } catch (Exception e) { throw new IllegalArgumentException("Cannot write field", e); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 0c02a889..45767e5f 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -396,10 +396,26 @@ public class REntity { public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); + public static final Class relative; + public static final Reflection.Field relatives; + static { + if (Core.getVersion() >= 21) { + relative = Reflection.getClass("net.minecraft.world.entity.Relative"); + relatives = Reflection.getField(teleportPacket, Set.class, 0); + } else { + relative = null; + relatives = null; + } + } private Object getTeleportPacket(){ Object packet = Reflection.newInstance(teleportPacket); teleportEntity.set(packet, entityId); teleportPosition.set(packet, x, y, z, pitch, yaw); + if (Core.getVersion() >= 21) { + // https://mappings.dev/1.21.3/net/minecraft/world/entity/Relative.html + Object[] constants = relative.getEnumConstants(); + relatives.set(packet, new HashSet<>(Arrays.asList(constants[0], constants[1], constants[2], constants[3], constants[4], constants[5]))); + } return packet; }