From 8886cc556287ab116963b417e0f6f2f5732392ea Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 Jan 2023 18:15:30 +0100 Subject: [PATCH] Swimming, Small ArmorStand, Initial MapType --- .../de/steamwar/core/FlatteningWrapper14.java | 13 +++++++++-- .../de/steamwar/core/ProtocolWrapper18.java | 3 +++ .../de/steamwar/core/ProtocolWrapper19.java | 3 +++ .../de/steamwar/core/FlatteningWrapper8.java | 4 ++-- .../de/steamwar/core/ProtocolWrapper8.java | 6 +++++ .../de/steamwar/core/FlatteningWrapper.java | 8 ++++++- .../{RHologram.java => RArmorStand.java} | 22 +++++++++++++++---- .../src/de/steamwar/entity/REntity.java | 16 +++++++------- 8 files changed, 58 insertions(+), 17 deletions(-) rename SpigotCore_Main/src/de/steamwar/entity/{RHologram.java => RArmorStand.java} (78%) diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index 9fc2ccd..84a4dc6 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -298,10 +298,19 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper private static final Class entityPose = Reflection.getClass("{nms.world.entity}.EntityPose"); private static final Object standing = entityPose.getEnumConstants()[0]; + private static final Object swimming = entityPose.getEnumConstants()[3]; private static final Object sneaking = entityPose.getEnumConstants()[5]; @Override - public Object getPose(boolean isSneaking) { - return isSneaking ? sneaking : standing; + public Object getPose(FlatteningWrapper.EntityPose pose) { + switch (pose) { + case SNEAKING: + return sneaking; + case SWIMMING: + return swimming; + case NORMAL: + default: + return standing; + } } @Override diff --git a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index d4ea68a..2c11fb5 100644 --- a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -50,6 +50,9 @@ public class ProtocolWrapper18 implements ProtocolWrapper { case FIREBALL: spawnType.set(packet, EntityTypes.S); break; + case ITEM_FRAME: + spawnType.set(packet, EntityTypes.R); + break; case ARMOR_STAND: spawnLivingType.set(packet, 1); break; diff --git a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java index 5fcf5b4..2c35efd 100644 --- a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -49,6 +49,9 @@ public class ProtocolWrapper19 implements ProtocolWrapper { case FIREBALL: spawnType.set(packet, EntityTypes.V); break; + case ITEM_FRAME: + spawnType.set(packet, EntityTypes.U); + break; case ARMOR_STAND: spawnType.set(packet, EntityTypes.d); break; diff --git a/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index 0a3caba..44f5c1a 100644 --- a/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -66,8 +66,8 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper } @Override - public Object getPose(boolean sneaking) { - return Byte.valueOf((byte)(sneaking ? 2 : 0)); + public Object getPose(FlatteningWrapper.EntityPose pose) { + return Byte.valueOf((byte)(pose == FlatteningWrapper.EntityPose.SNEAKING ? 2 : 0)); } private static final Class dataWatcher = Reflection.getClass("{nms}.DataWatcher"); diff --git a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index f27fbfa..9540a98 100644 --- a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -47,6 +47,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { private static final Object tnt; private static final Object arrow; private static final Object fireball; + private static final Object itemFrame; private static final int armorStand; static { if(Core.getVersion() < 14) { @@ -55,12 +56,14 @@ public class ProtocolWrapper8 implements ProtocolWrapper { arrow = 60; fireball = 63; armorStand = 30; + itemFrame = 18; } 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); + itemFrame = Reflection.getField(entityTypes, "ITEM_FRAME", entityTypes).get(null); armorStand = 1; } } @@ -76,6 +79,9 @@ public class ProtocolWrapper8 implements ProtocolWrapper { case FIREBALL: spawnType.set(packet, fireball); break; + case ITEM_FRAME: + spawnType.set(packet, itemFrame); + break; case ARMOR_STAND: spawnLivingType.set(packet, armorStand); break; diff --git a/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index b307106..3f5f205 100644 --- a/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -39,8 +39,14 @@ public class FlatteningWrapper { Material getDye(int colorCode); ItemStack setSkullOwner(String player); - Object getPose(boolean sneaking); + Object getPose(EntityPose pose); void setNamedSpawnPacketDataWatcher(Object packet); Object formatDisplayName(String displayName); } + + public enum EntityPose { + NORMAL, + SNEAKING, + SWIMMING; + } } diff --git a/SpigotCore_Main/src/de/steamwar/entity/RHologram.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java similarity index 78% rename from SpigotCore_Main/src/de/steamwar/entity/RHologram.java rename to SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index de5f3c5..7e0e7a7 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RHologram.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -26,7 +26,7 @@ import org.bukkit.entity.EntityType; import java.util.function.Consumer; -public class RHologram extends REntity { +public class RArmorStand extends REntity { private static int sizeIndex() { switch(Core.getVersion()) { @@ -49,14 +49,28 @@ public class RHologram extends REntity { private static final Object sizeWatcher = BountifulWrapper.impl.getDataWatcherObject(sizeIndex(), Byte.class); - public RHologram(REntityServer server, Location location) { + private final Size size; + + public RArmorStand(REntityServer server, Location location, Size size) { super(server, EntityType.ARMOR_STAND, location); - setInvisible(true); + this.size = size; } @Override void spawn(Consumer packetSink) { super.spawn(packetSink); - packetSink.accept(getDataWatcherPacket(sizeWatcher, (byte) 0x10)); + packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value)); + } + + public enum Size { + NORMAL((byte) 0x00), + SMALL((byte) 0x01), + MARKER((byte) 0x10); + + private final byte value; + + Size(byte value) { + this.value = value; + } } } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 2053cb1..77a5512 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -34,7 +34,7 @@ import java.util.function.Function; public class REntity { private static final Object entityStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(0, Byte.class); - private static final Object sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, FlatteningWrapper.impl.getPose(true).getClass()); + private static final Object sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, FlatteningWrapper.impl.getPose(FlatteningWrapper.EntityPose.NORMAL).getClass()); private static final Object bowDrawnWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, Byte.class); private static final Object nameWatcher = BountifulWrapper.impl.getDataWatcherObject(2, Core.getVersion() > 12 ? Optional.class : String.class); // Optional private static final Object nameVisibleWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Boolean.class); @@ -55,7 +55,7 @@ public class REntity { private byte headYaw; private boolean invisible; - private boolean sneaks; + private FlatteningWrapper.EntityPose pose; private boolean bowDrawn; private int fireTick; private String displayName; @@ -133,10 +133,10 @@ public class REntity { server.updateEntity(this, packet); } - public void sneak(boolean sneaking) { - sneaks = sneaking; + public void setPose(FlatteningWrapper.EntityPose pose) { + this.pose = pose; if(Core.getVersion() > 12) { - server.updateEntity(this, getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(sneaking))); + server.updateEntity(this, getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(pose))); } else { server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus())); } @@ -195,8 +195,8 @@ public class REntity { packetSink.accept(getHeadRotationPacket()); } - if(Core.getVersion() > 12 && sneaks) { - packetSink.accept(getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(true))); + if(Core.getVersion() > 12 && pose != FlatteningWrapper.EntityPose.NORMAL) { + packetSink.accept(getDataWatcherPacket(sneakingDataWatcher, FlatteningWrapper.impl.getPose(pose))); } byte status = getEntityStatus(); @@ -245,7 +245,7 @@ public class REntity { if(fireTick != 0) status |= 1; - if(sneaks) + if(pose == FlatteningWrapper.EntityPose.SNEAKING) status |= 2; if(Core.getVersion() == 8 && bowDrawn) status |= 0x10;