From dd3c88efce1eb1c34d2ddad2555621dbadb19957 Mon Sep 17 00:00:00 2001 From: D3v1s0m <49519439+D3v1s0m@users.noreply.github.com> Date: Wed, 28 Jun 2023 17:24:44 +0530 Subject: [PATCH] Implemented Axolotl properties --- .../entity/EntityPropertyRegistryImpl.java | 8 +++--- .../znpcsplus/metadata/MetadataFactory.java | 6 +++++ .../metadata/V1_17MetadataFactory.java | 10 ++++++++ .../metadata/V1_8MetadataFactory.java | 10 ++++++++ .../znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ++- .../znpcsplus/packets/V1_8PacketFactory.java | 25 +++++++++++-------- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index efcbe7c..f1f2e41 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -84,6 +84,10 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("left_leg_rotation", new Vector3f(-1 , 0, -1)); registerType("right_leg_rotation", new Vector3f(1, 0, 1)); + // Axolotl + registerType("axolotl_variant", 0); + registerType("playing_dead", false); // TODO fix disabling + // Bat registerType("hanging", false); // TODO @@ -105,10 +109,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerType("carpet_color", DyeColor.class); // TODO registerType("llama_variant", 0); // TODO - // Axolotl - registerType("axolotl_variant", 0); // TODO - registerType("playing_dead", false); // TODO - // Bee registerType("angry", false); // TODO registerType("has_nectar", false); // TODO diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java index 1fd2318..16a1a4d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/MetadataFactory.java @@ -30,6 +30,8 @@ public interface MetadataFactory { EntityData usingItem(boolean enabled, boolean offhand, boolean riptide); EntityData potionColor(int color); EntityData potionAmbient(boolean ambient); + + // Armor Stand EntityData armorStandProperties(boolean small, boolean arms, boolean noBasePlate); EntityData armorStandHeadRotation(Vector3f headRotation); EntityData armorStandBodyRotation(Vector3f bodyRotation); @@ -37,4 +39,8 @@ public interface MetadataFactory { EntityData armorStandRightArmRotation(Vector3f rightArmRotation); EntityData armorStandLeftLegRotation(Vector3f leftLegRotation); EntityData armorStandRightLegRotation(Vector3f rightLegRotation); + + // Axolotl + EntityData axolotlVariant(int variant); + EntityData playingDead(boolean playingDead); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java index 07d07bd..cf71406 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_17MetadataFactory.java @@ -69,4 +69,14 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory { public EntityData armorStandRightLegRotation(Vector3f rightLegRotation) { return createRotations(21, rightLegRotation); } + + @Override + public EntityData axolotlVariant(int variant) { + return newEntityData(17, EntityDataTypes.INT, variant); + } + + @Override + public EntityData playingDead(boolean playingDead) { + return newEntityData(18, EntityDataTypes.BOOLEAN, playingDead); + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java index 6f6cfeb..6f8465a 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/metadata/V1_8MetadataFactory.java @@ -94,6 +94,16 @@ public class V1_8MetadataFactory implements MetadataFactory { return createRotations(16, rightLegRotation); } + @Override + public EntityData axolotlVariant(int variant) { + throw new UnsupportedOperationException("The axolotl variant entity data isn't supported on this version"); + } + + @Override + public EntityData playingDead(boolean playingDead) { + throw new UnsupportedOperationException("The playing dead entity data isn't supported on this version"); + } + @Override public EntityData silent(boolean enabled) { return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java index 380f3c3..4feab9b 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java @@ -290,7 +290,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry { if (!version.isNewerThanOrEquals(ServerVersion.V_1_17)) return; register(builder(p, "axolotl", EntityTypes.AXOLOTL) - .setHologramOffset(-1.555)); + .setHologramOffset(-1.555) + .addProperties("axolotl_variant", "playing_dead")); register(builder(p, "glow_squid", EntityTypes.GLOW_SQUID) .setHologramOffset(-1.175)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 6d5be06..478f270 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -130,15 +130,6 @@ public class V1_8PacketFactory implements PacketFactory { @Override public Map generateMetadata(Player player, PacketEntity entity, PropertyHolder properties) { HashMap data = new HashMap<>(); - if (entity.getType() == EntityTypes.PLAYER) add(data, metadataFactory.skinLayers( - properties.getProperty(propertyRegistry.getByName("skin_cape", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_jacket", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_left_sleeve", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_right_sleeve", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_left_leg", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_right_leg", Boolean.class)), - properties.getProperty(propertyRegistry.getByName("skin_hat", Boolean.class)) - )); add(data, metadataFactory.effects( properties.getProperty(propertyRegistry.getByName("fire", Boolean.class)), false, @@ -149,7 +140,18 @@ public class V1_8PacketFactory implements PacketFactory { add(data, metadataFactory.silent(properties.getProperty(propertyRegistry.getByName("silent", Boolean.class)))); add(data, metadataFactory.potionColor(properties.getProperty(propertyRegistry.getByName("potion_color", Color.class)).asRGB())); add(data, metadataFactory.potionAmbient(properties.getProperty(propertyRegistry.getByName("potion_ambient", Boolean.class)))); - if (entity.getType() == EntityTypes.ARMOR_STAND) { + if (entity.getType().equals(EntityTypes.PLAYER)) { + add(data, metadataFactory.skinLayers( + properties.getProperty(propertyRegistry.getByName("skin_cape", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_jacket", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_left_sleeve", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_right_sleeve", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_left_leg", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_right_leg", Boolean.class)), + properties.getProperty(propertyRegistry.getByName("skin_hat", Boolean.class)) + )); + } + else if (entity.getType().equals(EntityTypes.ARMOR_STAND)) { add(data, metadataFactory.armorStandProperties( properties.getProperty(propertyRegistry.getByName("small", Boolean.class)), properties.getProperty(propertyRegistry.getByName("arms", Boolean.class)), @@ -161,6 +163,9 @@ public class V1_8PacketFactory implements PacketFactory { add(data, metadataFactory.armorStandRightArmRotation(properties.getProperty(propertyRegistry.getByName("right_arm_rotation", Vector3f.class)))); add(data, metadataFactory.armorStandLeftLegRotation(properties.getProperty(propertyRegistry.getByName("left_leg_rotation", Vector3f.class)))); add(data, metadataFactory.armorStandRightLegRotation(properties.getProperty(propertyRegistry.getByName("right_leg_rotation", Vector3f.class)))); + } else if (entity.getType().equals(EntityTypes.AXOLOTL)) { + add(data, metadataFactory.axolotlVariant(properties.getProperty(propertyRegistry.getByName("axolotl_variant", Integer.class)))); + add(data, metadataFactory.playingDead(properties.getProperty(propertyRegistry.getByName("playing_dead", Boolean.class)))); } if (properties.hasProperty(propertyRegistry.getByName("name"))) { add(data, metadataFactory.name(PapiUtil.set(textSerializer, player, properties.getProperty(propertyRegistry.getByName("name", Component.class)))));