Fix REntity for 1.15.2-1.21.3

<1.15.2: Untested
This commit is contained in:
2024-12-01 11:39:23 +01:00
parent 41233b7710
commit 7927a195d6
15 changed files with 127 additions and 73 deletions
@@ -44,7 +44,7 @@ public class BountifulWrapper {
}
public interface PositionSetter {
void set(Object packet, double x, double y, double z);
void set(Object packet, double x, double y, double z, float pitch, float yaw);
}
public interface UUIDSetter {
@@ -77,7 +77,7 @@ public class ErrorHandler extends Handler {
return;
try {
SWException.log(message, stacktrace);
//SWException.log(message, stacktrace);
} catch (SecurityException e) {
Core.getInstance().getLogger().log(Level.INFO, "Could not log error in database", e);
}
@@ -68,7 +68,7 @@ public class WorldEditRenderer {
Transform transform = session.getClipboard().getTransform();
Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), Particle.VILLAGER_HAPPY, player);
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyTrialsWrapper.impl.getVillagerHappyParticle(), player);
} catch (EmptyClipboardException e) {
//ignore
}
@@ -393,25 +393,19 @@ public class REntity {
return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues);
}
private static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
private static final Reflection.FieldAccessor<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
private static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0);
private static final Reflection.FieldAccessor<Byte> teleportYaw = Reflection.getField(teleportPacket, byte.class, 0);
private static final Reflection.FieldAccessor<Byte> teleportPitch = Reflection.getField(teleportPacket, byte.class, 1);
public static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
public static final Reflection.FieldAccessor<Integer> teleportEntity = Reflection.getField(teleportPacket, int.class, 0);
public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0);
private Object getTeleportPacket(){
Object packet = Reflection.newInstance(teleportPacket);
teleportEntity.set(packet, entityId);
teleportPosition.set(packet, x, y, z);
teleportYaw.set(packet, yaw);
teleportPitch.set(packet, pitch);
teleportPosition.set(packet, x, y, z, pitch, yaw);
return packet;
}
private static final Class<?> entityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity");
private static final Reflection.FieldAccessor<Integer> moveEntityId = Reflection.getField(entityPacket, int.class, 0);
private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket);
private static final Reflection.FieldAccessor<Byte> lookYaw = Reflection.getField(entityPacket, "e", byte.class);
private static final Reflection.FieldAccessor<Byte> lookPitch = Reflection.getField(entityPacket, "f", byte.class);
private static final Class<?> lookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutEntityLook");
private static final Class<?> movePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMove");
private static final Class<?> moveLookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook");
@@ -430,9 +424,7 @@ public class REntity {
Object packet = Reflection.newInstance(clazz);
moveEntityId.set(packet, entityId);
movePosition.set(packet, diffX, diffY, diffZ);
lookYaw.set(packet, yaw);
lookPitch.set(packet, pitch);
movePosition.set(packet, diffX, diffY, diffZ, pitch, yaw);
return packet;
}
@@ -476,7 +468,7 @@ public class REntity {
return entity -> {
Object packet = Reflection.newInstance(spawnPacket);
entityId.set(packet, entity.entityId);
position.set(packet, entity.x, entity.y, entity.z);
position.set(packet, entity.x, entity.y, entity.z, entity.pitch, entity.yaw);
return packet;
};
}