From 4e75868a737496706264930a6a2c66ae8bd3f424 Mon Sep 17 00:00:00 2001 From: D3v1s0m Date: Tue, 30 Apr 2024 20:47:55 +0530 Subject: [PATCH] villager_profession property for 1.13 and below --- .../znpcsplus/util/VillagerProfession.java | 39 ++++++++++++------- .../entity/EntityPropertyRegistryImpl.java | 13 +++++-- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java index f02a53c..939f425 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java +++ b/api/src/main/java/lol/pyr/znpcsplus/util/VillagerProfession.java @@ -1,29 +1,40 @@ package lol.pyr.znpcsplus.util; public enum VillagerProfession { - NONE(0), - ARMORER(1), - BUTCHER(2), - CARTOGRAPHER(3), - CLERIC(4), - FARMER(5), - FISHERMAN(6), - FLETCHER(7), - LEATHER_WORKER(8), - LIBRARIAN(9), + NONE(0, 0), + ARMORER(1, 3), + BUTCHER(2, 4), + CARTOGRAPHER(3, 1), + CLERIC(4, 2), + FARMER(5, 0), + FISHERMAN(6, 0), + FLETCHER(7, 0), + LEATHER_WORKER(8, 4), + LIBRARIAN(9, 1), MASON(10), - NITWIT(11), - SHEPHERD(12), - TOOL_SMITH(13), - WEAPON_SMITH(14); + NITWIT(11, 5), + SHEPHERD(12, 0), + TOOL_SMITH(13, 3), + WEAPON_SMITH(14, 3); private final int id; + private final int legacyId; VillagerProfession(int id) { this.id = id; + this.legacyId = 0; + } + + VillagerProfession(int id, int legacyId) { + this.id = id; + this.legacyId = legacyId; } public int getId() { return id; } + + public int getLegacyId() { + return legacyId; + } } 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 ade327e..adf1b35 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -373,6 +373,15 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new EncodedByteProperty<>("sheep_color", DyeColor.WHITE, sheepIndex, DyeColor::getWoolData)); register(new BitsetProperty("sheep_sheared", sheepIndex, 0x10, false, legacyBooleans)); // no need to link because sheep_sheared is only visible when sheep_color is WHITE + // Villager + int villagerIndex; + if (ver.isOlderThan(ServerVersion.V_1_14)) { + if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) villagerIndex = 13; + else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) villagerIndex = 12; + else villagerIndex = 16; + register(new EncodedIntegerProperty<>("villager_profession", VillagerProfession.NONE, villagerIndex, VillagerProfession::getLegacyId)); + } + // Wolf int wolfIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) wolfIndex = 19; @@ -501,12 +510,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { register(new CustomTypeProperty<>("pose", 6, NpcPose.STANDING, EntityDataTypes.ENTITY_POSE, npcPose -> EntityPose.valueOf(npcPose.name()))); // Villager - final int villagerIndex; if (ver.isNewerThanOrEquals(ServerVersion.V_1_17)) villagerIndex = 18; else if (ver.isNewerThanOrEquals(ServerVersion.V_1_15)) villagerIndex = 17; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) villagerIndex = 16; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) villagerIndex = 13; - else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) villagerIndex = 12; else villagerIndex = 16; register(new VillagerTypeProperty("villager_type", villagerIndex, VillagerType.PLAINS)); register(new VillagerProfessionProperty("villager_profession", villagerIndex, VillagerProfession.NONE));