SteamWar/SpigotCore
Archiviert
13
0

WIP CoreREntity
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-01-09 17:35:00 +01:00
Ursprung cc65253364
Commit cea2ffdac6
8 geänderte Dateien mit 107 neuen und 83 gelöschten Zeilen

Datei anzeigen

@ -37,6 +37,7 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
}
private static final Reflection.FieldAccessor<?> spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, EntityTypes.class, 0);
private static final Reflection.FieldAccessor<Integer> spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);
@Override
public void setSpawnPacketType(Object packet, EntityType type) {
switch(type) {
@ -49,6 +50,11 @@ public class ProtocolWrapper18 implements ProtocolWrapper {
case FIREBALL:
spawnType.set(packet, EntityTypes.S);
break;
case ARMOR_STAND:
spawnLivingType.set(packet, 1);
break;
default:
throw new IllegalArgumentException(type.name() + " is not implemented");
}
}

Datei anzeigen

@ -49,6 +49,11 @@ public class ProtocolWrapper19 implements ProtocolWrapper {
case FIREBALL:
spawnType.set(packet, EntityTypes.V);
break;
case ARMOR_STAND:
spawnType.set(packet, EntityTypes.d);
break;
default:
throw new IllegalArgumentException(type.name() + " is not implemented");
}
}

Datei anzeigen

@ -31,7 +31,6 @@ import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
@ -66,30 +65,21 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
return watchableObjectConstructor.invoke(watchableDatatypes.get(value.getClass()), dwo, value);
}
private static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
private static final Reflection.FieldAccessor<Integer> teleportX = Reflection.getField(teleportPacket, int.class, 1);
private static final Reflection.FieldAccessor<Integer> teleportY = Reflection.getField(teleportPacket, int.class, 2);
private static final Reflection.FieldAccessor<Integer> teleportZ = Reflection.getField(teleportPacket, int.class, 3);
@Override
public void setTeleportPacketPosition(Object packet, double x, double y, double z) {
teleportX.set(packet, MathHelper.floor(x * 32));
teleportY.set(packet, MathHelper.floor(y * 32));
teleportZ.set(packet, MathHelper.floor(z * 32));
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);
return (packet, x, y, z) -> {
posX.set(packet, MathHelper.floor(x * 32));
posY.set(packet, MathHelper.floor(y * 32));
posZ.set(packet, MathHelper.floor(z * 32));
};
}
@Override
public void setSpawnPacketUUID(Object packet, UUID uuid) {
// field not present
}
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Reflection.FieldAccessor<Integer> namedSpawnX = Reflection.getField(namedSpawnPacket, int.class, 0);
private static final Reflection.FieldAccessor<Integer> namedSpawnY = Reflection.getField(namedSpawnPacket, int.class, 1);
private static final Reflection.FieldAccessor<Integer> namedSpawnZ = Reflection.getField(namedSpawnPacket, int.class, 2);
@Override
public void setNamedSpawnPosition(Object packet, double x, double y, double z) {
namedSpawnX.set(packet, MathHelper.floor(x * 32));
namedSpawnY.set(packet, MathHelper.floor(y * 32));
namedSpawnZ.set(packet, MathHelper.floor(z * 32));
public BountifulWrapper.UUIDSetter getUUIDSetter(Class<?> packetClass) {
return (packet, uuid) -> {};
}
}

Datei anzeigen

@ -43,21 +43,25 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
}
private static final Reflection.FieldAccessor<?> spawnType;
private static final Reflection.FieldAccessor<Integer> spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1);
private static final Object tnt;
private static final Object arrow;
private static final Object fireball;
private static final int armorStand;
static {
if(Core.getVersion() < 14) {
spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9);
tnt = 50;
arrow = 60;
fireball = 63;
armorStand = 30;
} else {
Class<?> entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes");
spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0);
tnt = Reflection.getField(entityTypes, "TNT", entityTypes).get(null);
arrow = Reflection.getField(entityTypes, "ARROW", entityTypes).get(null);
fireball = Reflection.getField(entityTypes, "FIREBALL", entityTypes).get(null);
armorStand = 1;
}
}
@Override
@ -72,6 +76,11 @@ public class ProtocolWrapper8 implements ProtocolWrapper {
case FIREBALL:
spawnType.set(packet, fireball);
break;
case ARMOR_STAND:
spawnLivingType.set(packet, armorStand);
break;
default:
throw new IllegalArgumentException(type.name() + " is not implemented");
}
}

Datei anzeigen

@ -55,32 +55,23 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper {
return itemConstructor.invoke(dwo, value);
}
private static final Class<?> teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport");
private static final Reflection.FieldAccessor<Double> teleportX = Reflection.getField(teleportPacket, double.class, 0);
private static final Reflection.FieldAccessor<Double> teleportY = Reflection.getField(teleportPacket, double.class, 1);
private static final Reflection.FieldAccessor<Double> teleportZ = Reflection.getField(teleportPacket, double.class, 2);
@Override
public void setTeleportPacketPosition(Object packet, double x, double y, double z) {
teleportX.set(packet, x);
teleportY.set(packet, y);
teleportZ.set(packet, z);
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);
return (packet, x, y, z) -> {
posX.set(packet, x);
posY.set(packet, y);
posZ.set(packet, z);
};
}
private static final Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
private static final Reflection.FieldAccessor<UUID> spawnUUID = Reflection.getField(spawnPacket, UUID.class, 0);
@Override
public void setSpawnPacketUUID(Object packet, UUID uuid) {
spawnUUID.set(packet, uuid);
}
public BountifulWrapper.UUIDSetter getUUIDSetter(Class<?> packetClass) {
Reflection.FieldAccessor<UUID> uuidField = Reflection.getField(packetClass, UUID.class, 0);
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Reflection.FieldAccessor<Double> namedSpawnX = Reflection.getField(namedSpawnPacket, double.class, 0);
private static final Reflection.FieldAccessor<Double> namedSpawnY = Reflection.getField(namedSpawnPacket, double.class, 1);
private static final Reflection.FieldAccessor<Double> namedSpawnZ = Reflection.getField(namedSpawnPacket, double.class, 2);
@Override
public void setNamedSpawnPosition(Object packet, double x, double y, double z) {
namedSpawnX.set(packet, x);
namedSpawnY.set(packet, y);
namedSpawnZ.set(packet, z);
return uuidField::set;
}
}

Datei anzeigen

@ -37,8 +37,16 @@ public class BountifulWrapper {
Object getDataWatcherObject(int index, Class<?> type);
Object getDataWatcherItem(Object dataWatcherObject, Object value);
void setTeleportPacketPosition(Object packet, double x, double y, double z);
void setSpawnPacketUUID(Object packet, UUID uuid);
void setNamedSpawnPosition(Object packet, double x, double y, double z);
PositionSetter getPositionSetter(Class<?> packetClass, int fieldOffset8);
UUIDSetter getUUIDSetter(Class<?> packetClass);
}
public interface PositionSetter {
void set(Object packet, double x, double y, double z);
}
public interface UUIDSetter {
void set(Object packet, UUID uuid);
}
}

Datei anzeigen

@ -27,6 +27,7 @@ public interface ProtocolWrapper {
Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
Class<?> spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity");
Class<?> spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving");
Class<?> equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment");
// 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head

Datei anzeigen

@ -74,6 +74,7 @@ public class REntity {
private boolean invisible;
private boolean sneaks;
private boolean bowDrawn;
private int fireTick;
private String displayName;
private final Map<Object, ItemStack> itemSlots;
@ -157,24 +158,29 @@ public class REntity {
public void sneak(boolean sneaking) {
sneaks = sneaking;
server.updateEntity(this, getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(sneaking))); //TODO entityStatusData in 1.8!
if(Core.getVersion() > 12) {
server.updateEntity(this, getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(sneaking)));
} else {
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
}
public void setOnFire(boolean perma) {
fireTick = perma ? -1 : 21;
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, (byte) 1));
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, (byte) 0x20));
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
public void setBowDrawn(boolean drawn, boolean offHand) {
bowDrawn = drawn;
if(Core.getVersion() > 8){
server.updateEntity(this, getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
}else{
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, (byte)0x10));
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
}
@ -217,7 +223,7 @@ public class REntity {
server.updateEntity(this, getEquipmentPacket(slot, stack));
}
public void close() {
public void die() {
server.removeEntity(this);
}
@ -229,30 +235,27 @@ public class REntity {
packetSink.accept(getEquipmentPacket(entry.getKey(), entry.getValue()));
}
packetSink.accept(getDataWatcherPacket(skinPartsDataWatcher, (byte) 0x7F)); //TODO multiversioning
} else if(entityType == EntityType.ARMOR_STAND) {
} else if(entityType.isAlive()) {
packetSink.accept(getSpawnLivingEntityPacket());
packetSink.accept(getDataWatcherPacket(sizeWatcher, (byte) 0x10)); // small size //TODO multiversioning
packetSink.accept(getDataWatcherPacket(sizeWatcher, (byte) 0x10)); // small size //TODO multiversioning TODO only on ArmorStands
for (Map.Entry<Object, ItemStack> entry : itemSlots.entrySet()) {
packetSink.accept(getEquipmentPacket(entry.getKey(), entry.getValue()));
}
} else {
packetSink.accept(getSpawnEntityPacket());
}
packetSink.accept(getTeleportPacket()); //TODO teleport necessary
//packetSink.accept(getTeleportPacket());
packetSink.accept(getHeadRotationPacket()); //TODO head rotation for all types?
//TODO merge MetadataPacket (DataWatcherPackets)
if(sneaks) {
packetSink.accept(getDataWatcherPacket(entityStatusWatcher, FlatteningWrapper.impl.getPose(true)));
if(Core.getVersion() > 12 && sneaks) {
packetSink.accept(getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(true)));
}
if(fireTick != 0) {
packetSink.accept(getDataWatcherPacket(sneakingDataWatcher, getDataWatcherPacket(entityStatusWatcher, (byte)1)));
}
if(invisible) {
packetSink.accept(getDataWatcherPacket(entityStatusWatcher, (byte) 0x20));
byte status = getEntityStatus();
if(status != 0) {
packetSink.accept(getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
if(displayName != null) {
@ -265,7 +268,7 @@ public class REntity {
if(fireTick > 0) {
fireTick--;
if(fireTick == 0) {
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, (byte)0));
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
}
}
}
@ -297,6 +300,21 @@ public class REntity {
return z;
}
private byte getEntityStatus() {
byte status = 0;
if(fireTick != 0)
status |= 1;
if(Core.getVersion() <= 12 && sneaks)
status |= 2;
if(Core.getVersion() == 8 && bowDrawn)
status |= 0x10;
if(invisible)
status |= 0x20;
return status;
}
private static final Class<?> metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata");
private static final Reflection.FieldAccessor<Integer> metadataEntity = Reflection.getField(metadataPacket, int.class, 0);
private static final Reflection.FieldAccessor<List> metadataMetadata = Reflection.getField(metadataPacket, List.class, 0);
@ -316,12 +334,13 @@ 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 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(){
Object packet = Reflection.newInstance(teleportPacket);
teleportEntity.set(packet, entityId);
BountifulWrapper.impl.setTeleportPacketPosition(packet, x, y, z);
teleportPosition.set(packet, x, y, z);
teleportYaw.set(packet, yaw);
teleportPitch.set(packet, pitch);
return packet;
@ -366,42 +385,37 @@ public class REntity {
private static final Class<?> namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn");
private static final Reflection.FieldAccessor<Integer> namedSpawnEntity = Reflection.getField(namedSpawnPacket, int.class, 0);
private static final Reflection.FieldAccessor<UUID> namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
private static final BountifulWrapper.PositionSetter namedSpawnPosition = BountifulWrapper.impl.getPositionSetter(namedSpawnPacket, 1);
private Object getNamedSpawnPacket() {
Object packet = Reflection.newInstance(namedSpawnPacket);
namedSpawnEntity.set(packet, entityId);
namedSpawnUUID.set(packet, uuid);
BountifulWrapper.impl.setNamedSpawnPosition(packet, x, y, z);
namedSpawnPosition.set(packet, x, y, z);
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
return packet;
}
private static final Class<?> spawnLivingPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving"); //TODO not existing in 1.19
private static final Reflection.ConstructorInvoker spawnLivingPacketConstructor = Reflection.getConstructor(spawnLivingPacket); //TODO multiversioning
private static final Reflection.FieldAccessor<Integer> spawnLivingEntityId = Reflection.getField(spawnLivingPacket, int.class, 0); //TODO multiversioning
private static final Reflection.FieldAccessor<UUID> spawnLivingUUID = Reflection.getField(spawnLivingPacket, UUID.class, 0); //TODO not existing in 1.8
private static final Reflection.FieldAccessor<Integer> spawnLivingEntityType = Reflection.getField(spawnLivingPacket, int.class, 1); //TODO multiversioning
private static final Reflection.FieldAccessor<Double> spawnLivingEntityX = Reflection.getField(spawnLivingPacket, double.class, 0); //TODO int in 1.8
private static final Reflection.FieldAccessor<Double> spawnLivingEntityY = Reflection.getField(spawnLivingPacket, double.class, 1); //TODO int in 1.8
private static final Reflection.FieldAccessor<Double> spawnLivingEntityZ = Reflection.getField(spawnLivingPacket, double.class, 2); //TODO int in 1.8
private static final Reflection.FieldAccessor<Integer> spawnLivingEntityId = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 0);
private static final BountifulWrapper.UUIDSetter livingSpawnUUID = BountifulWrapper.impl.getUUIDSetter(ProtocolWrapper.spawnLivingPacket);
private static final BountifulWrapper.PositionSetter livingSpawnPosition = BountifulWrapper.impl.getPositionSetter(ProtocolWrapper.spawnLivingPacket, 2); //TODO only diff to spawnEntity, simplify code
private Object getSpawnLivingEntityPacket() {
Object packet = spawnLivingPacketConstructor.invoke();
Object packet = Reflection.newInstance(ProtocolWrapper.spawnLivingPacket);
spawnLivingEntityId.set(packet, entityId);
spawnLivingUUID.set(packet, uuid);
spawnLivingEntityType.set(packet, 1); //TODO set correct type
spawnLivingEntityX.set(packet, x);
spawnLivingEntityY.set(packet, y);
spawnLivingEntityZ.set(packet, z);
livingSpawnUUID.set(packet, uuid);
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
livingSpawnPosition.set(packet, x, y, z);
return packet;
}
private static final Reflection.FieldAccessor<Integer> spawnEntity = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, 0);
private static final BountifulWrapper.UUIDSetter spawnUUID = BountifulWrapper.impl.getUUIDSetter(ProtocolWrapper.spawnPacket);
private static final BountifulWrapper.PositionSetter spawnPosition = BountifulWrapper.impl.getPositionSetter(ProtocolWrapper.spawnPacket, 1);
private Object getSpawnEntityPacket() {
Object packet = Reflection.newInstance(ProtocolWrapper.spawnPacket);
spawnEntity.set(packet, entityId);
BountifulWrapper.impl.setSpawnPacketUUID(packet, uuid);
spawnUUID.set(packet, uuid);
ProtocolWrapper.impl.setSpawnPacketType(packet, entityType);
//TODO set position
spawnPosition.set(packet, x, y, z);
return packet;
}