From 81a77fd1defcaea810b144db737bdd79bb3be06e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 Jan 2023 19:08:37 +0100 Subject: [PATCH] Add FallingBlock --- .../de/steamwar/core/ProtocolWrapper18.java | 3 ++ .../de/steamwar/core/ProtocolWrapper19.java | 3 ++ .../de/steamwar/core/ProtocolWrapper8.java | 52 +++++++------------ 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 2c11fb5..2a88cb4 100644 --- a/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -53,6 +53,9 @@ public class ProtocolWrapper18 implements ProtocolWrapper { case ITEM_FRAME: spawnType.set(packet, EntityTypes.R); break; + case FALLING_BLOCK: + spawnType.set(packet, EntityTypes.C); + 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 2c35efd..66cc47c 100644 --- a/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -55,6 +55,9 @@ public class ProtocolWrapper19 implements ProtocolWrapper { case ARMOR_STAND: spawnType.set(packet, EntityTypes.d); break; + case FALLING_BLOCK: + spawnType.set(packet, EntityTypes.E); + break; default: throw new IllegalArgumentException(type.name() + " is not implemented"); } diff --git a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index 9540a98..d0e0e03 100644 --- a/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -23,6 +23,9 @@ import com.comphenix.tinyprotocol.Reflection; import com.mojang.authlib.GameProfile; import org.bukkit.entity.EntityType; +import java.util.HashMap; +import java.util.Map; + public class ProtocolWrapper8 implements ProtocolWrapper { private static final Reflection.FieldAccessor equipmentSlot; @@ -44,50 +47,31 @@ public class ProtocolWrapper8 implements ProtocolWrapper { private static final Reflection.FieldAccessor spawnType; private static final Reflection.FieldAccessor 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 Object itemFrame; - private static final int armorStand; + private static final Map types = new HashMap<>(); + 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; - itemFrame = 18; + types.put(EntityType.PRIMED_TNT, 50); + types.put(EntityType.ARMOR_STAND, 30); + types.put(EntityType.ARROW, 60); + types.put(EntityType.FIREBALL, 63); + types.put(EntityType.ITEM_FRAME, 18); + types.put(EntityType.FALLING_BLOCK, 21); } 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; + types.put(EntityType.ARMOR_STAND, 1); + for(EntityType type : new EntityType[]{EntityType.PRIMED_TNT, EntityType.ARROW, EntityType.FIREBALL, EntityType.ITEM_FRAME, EntityType.FALLING_BLOCK}) + types.put(type, Reflection.getField(entityTypes, type.name(), entityTypes).get(null)); } } @Override public void setSpawnPacketType(Object packet, EntityType type) { - switch(type) { - case PRIMED_TNT: - spawnType.set(packet, tnt); - break; - case ARROW: - spawnType.set(packet, arrow); - break; - case FIREBALL: - spawnType.set(packet, fireball); - break; - case ITEM_FRAME: - spawnType.set(packet, itemFrame); - break; - case ARMOR_STAND: - spawnLivingType.set(packet, armorStand); - break; - default: - throw new IllegalArgumentException(type.name() + " is not implemented"); - } + if(type.isAlive()) + spawnLivingType.set(packet, types.get(type)); + else + spawnType.set(packet, types.get(type)); } private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);