From 1008d31df082b3b06a1fac19e6074f7a57f261fb Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Mon, 11 Sep 2023 18:11:36 +0530 Subject: [PATCH] Added ocelot_type property --- .../java/lol/pyr/znpcsplus/util/OcelotType.java | 8 ++++++++ .../src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 13 ++++++++++++- .../java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java b/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java new file mode 100644 index 0000000..593ec57 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/OcelotType.java @@ -0,0 +1,8 @@ +package lol.pyr.znpcsplus.util; + +public enum OcelotType { + OCELOT, + TUXEDO, + TABBY, + SIAMESE, +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 03d4202..04458b4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -272,6 +272,7 @@ public class ZNpcsPlus extends JavaPlugin { registerEnumParser(manager, HorseArmor.class, incorrectUsageMessage); registerEnumParser(manager, LlamaVariant.class, incorrectUsageMessage); registerEnumParser(manager, MooshroomVariant.class, incorrectUsageMessage); + registerEnumParser(manager, OcelotType.class, incorrectUsageMessage); manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) 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 cc44222..f60a9fe 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -66,6 +66,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { registerEnumSerializer(HorseArmor.class); registerEnumSerializer(LlamaVariant.class); registerEnumSerializer(MooshroomVariant.class); + registerEnumSerializer(OcelotType.class); /* registerType("using_item", false); // TODO: fix it for 1.8 and add new property to use offhand item and riptide animation @@ -328,7 +329,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { linkProperties("is_saddled", "is_eating", "is_rearing", "has_mouth_open"); } - // Slime and Magma Cube + // Slime, Magma Cube and Phantom int sizeIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) sizeIndex = 16; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) sizeIndex = 15; @@ -338,6 +339,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else sizeIndex = 16; register(new IntegerProperty("size", sizeIndex, 1, v1_8)); + // Ocelot + if (ver.isOlderThan(ServerVersion.V_1_14)) { + int ocelotIndex; + if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) ocelotIndex = 15; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) ocelotIndex = 14; + else ocelotIndex = 18; + if (v1_8) register(new EncodedByteProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, obj -> (byte) obj.ordinal())); + else register(new EncodedIntegerProperty<>("ocelot_type", OcelotType.OCELOT, ocelotIndex, Enum::ordinal)); + } + if (!ver.isNewerThanOrEquals(ServerVersion.V_1_11)) return; // Spellcaster Illager int spellIndex = 12; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java index 5d72cbf..d86bede 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java @@ -110,6 +110,7 @@ public class NpcTypeImpl implements NpcType { ServerVersion version = PacketEvents.getAPI().getServerManager().getVersion(); addProperties("fire", "invisible", "silent", "look", "potion_color", "potion_ambient", "dinnerbone"); + // TODO: make this look nicer after completing the rest of the properties if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow"); if (version.isNewerThanOrEquals(ServerVersion.V_1_14)) { addProperties("pose"); @@ -138,6 +139,11 @@ public class NpcTypeImpl implements NpcType { if (EntityTypes.isTypeInstanceOf(type, EntityTypes.SLIME) || EntityTypes.isTypeInstanceOf(type, EntityTypes.PHANTOM)) { addProperties("size"); } + if (version.isOlderThan(ServerVersion.V_1_14)) { + if (EntityTypes.isTypeInstanceOf(type, EntityTypes.OCELOT)) { + addProperties("ocelot_type"); + } + } return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties); } }