SteamWar/SpigotCore
Archiviert
13
0

Fix SpawnPacketPosition Reflection
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-01-15 18:32:46 +01:00
Ursprung 8d3037f67d
Commit d8825f0262
5 geänderte Dateien mit 33 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -66,10 +66,10 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
}
@Override
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset8) {
Reflection.FieldAccessor<Integer> posX = Reflection.getField(packetClass, int.class, fieldOffset8);
Reflection.FieldAccessor<Integer> posY = Reflection.getField(packetClass, int.class, fieldOffset8+1);
Reflection.FieldAccessor<Integer> posZ = Reflection.getField(packetClass, int.class, fieldOffset8+2);
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset) {
Reflection.FieldAccessor<Integer> posX = Reflection.getField(packetClass, int.class, fieldOffset);
Reflection.FieldAccessor<Integer> posY = Reflection.getField(packetClass, int.class, fieldOffset +1);
Reflection.FieldAccessor<Integer> posZ = Reflection.getField(packetClass, int.class, fieldOffset +2);
return (packet, x, y, z) -> {
posX.set(packet, MathHelper.floor(x * 32));

Datei anzeigen

@ -56,10 +56,10 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
}
@Override
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset8) {
Reflection.FieldAccessor<Double> posX = Reflection.getField(packetClass, double.class, 0);
Reflection.FieldAccessor<Double> posY = Reflection.getField(packetClass, double.class, 1);
Reflection.FieldAccessor<Double> posZ = Reflection.getField(packetClass, double.class, 2);
public BountifulWrapper.PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset) {
Reflection.FieldAccessor<Double> posX = Reflection.getField(packetClass, double.class, fieldOffset);
Reflection.FieldAccessor<Double> posY = Reflection.getField(packetClass, double.class, fieldOffset+1);
Reflection.FieldAccessor<Double> posZ = Reflection.getField(packetClass, double.class, fieldOffset+2);
return (packet, x, y, z) -> {
posX.set(packet, x);

Datei anzeigen

@ -38,7 +38,7 @@ public class BountifulWrapper {
Object getDataWatcherObject(int index, Class<?> type);
Object getDataWatcherItem(Object dataWatcherObject, Object value);
PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset8);
PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset);
UUIDSetter getUUIDSetter(Class<?> packetClass);
}

Datei anzeigen

@ -178,8 +178,24 @@ public class REntity {
server.removeEntity(this);
}
private static final Function<REntity, Object> livingSpawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, 2);
private static final Function<REntity, Object> spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, 1);
private static int spawnPacketOffset() {
switch (Core.getVersion()) {
case 8:
case 18:
return 1;
case 9:
case 10:
case 12:
case 14:
case 15:
return 0;
case 19:
default:
return 2;
}
}
private static final Function<REntity, Object> spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, spawnPacketOffset());
private static final Function<REntity, Object> livingSpawnPacketGenerator = Core.getVersion() >= 19 ? spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0);
void spawn(Consumer<Object> packetSink) {
if(entityType.isAlive()) {
packetSink.accept(livingSpawnPacketGenerator.apply(this));
@ -274,7 +290,7 @@ public class REntity {
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, 1);
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);
private Object getTeleportPacket(){
@ -307,9 +323,9 @@ public class REntity {
return packet;
}
private static Function<REntity, Object> entitySpawnPacketGenerator(Class<?> spawnPacket, int posOffset8) {
private static Function<REntity, Object> entitySpawnPacketGenerator(Class<?> spawnPacket, int posOffset) {
BountifulWrapper.UUIDSetter uuid = BountifulWrapper.impl.getUUIDSetter(spawnPacket);
Function<REntity, Object> packetGenerator = spawnPacketGenerator(spawnPacket, posOffset8);
Function<REntity, Object> packetGenerator = spawnPacketGenerator(spawnPacket, posOffset);
return entity -> {
Object packet = packetGenerator.apply(entity);
@ -319,9 +335,9 @@ public class REntity {
};
}
protected static Function<REntity, Object> spawnPacketGenerator(Class<?> spawnPacket, int posOffset8) {
protected static Function<REntity, Object> spawnPacketGenerator(Class<?> spawnPacket, int posOffset) {
Reflection.FieldAccessor<Integer> entityId = Reflection.getField(spawnPacket, int.class, 0);
BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset8);
BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset);
return entity -> {
Object packet = Reflection.newInstance(spawnPacket);

Datei anzeigen

@ -115,7 +115,7 @@ public class RPlayer extends REntity {
}
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Function<REntity, Object> namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, 1);
private static final Function<REntity, Object> namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0);
private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
private Object getNamedSpawnPacket() {
Object packet = namedSpawnPacketGenerator.apply(this);