diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 16a0d5e..d6ace1a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -231,12 +231,35 @@ public class REntity { } } private static final Function spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, spawnPacketOffset()); - private static final Function livingSpawnPacketGenerator = Core.getVersion() >= 19 ? spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0); + private static int objectDataOffset() { + switch (Core.getVersion()) { + case 8: + return 9; + case 9: + case 14: + case 12: + case 10: + case 15: + case 18: + return 6; + case 19: + default: + return 4; + } + } + private static final Reflection.FieldAccessor additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); + private Object spawnPacketGenerator() { + Object packet = spawnPacketGenerator.apply(this); + additionalData.set(packet, objectData); + return packet; + } + + private static final Function livingSpawnPacketGenerator = Core.getVersion() >= 19 ? REntity::spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0); void spawn(Consumer packetSink) { if(entityType.isAlive()) { packetSink.accept(livingSpawnPacketGenerator.apply(this)); } else { - packetSink.accept(spawnPacketGenerator.apply(this)); + packetSink.accept(spawnPacketGenerator()); } postSpawn(packetSink); @@ -261,7 +284,7 @@ public class REntity { } if(Core.getVersion() > 8 && noGravity) - packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,this.noGravity)); + packetSink.accept(getDataWatcherPacket(noGravityDataWatcher, true)); } void tick() { @@ -378,33 +401,11 @@ public class REntity { protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); - - int index; - switch (Core.getVersion()) { - case 8: - index = 9; - break; - case 9: - case 14: - case 12: - case 10: - case 15: - case 18: - index = 6; - break; - case 19: - default: - index = 4; - break; - } - - Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, index); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { Object packet = Reflection.newInstance(spawnPacket); entityId.set(packet, entity.entityId); - additionalData.set(packet,entity.objectData); position.set(packet, entity.x, entity.y, entity.z); return packet; };