From 81df67a179ef6c57ab9a3a77c755d966e4828546 Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Fri, 24 Jan 2025 05:28:31 -0500 Subject: [PATCH] Patch `EmeraldsForVillagerTypeItem` to allow modders to make Custom `VillagerType`s (#1875) --- .../entity/npc/VillagerTrades.java.patch | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 patches/net/minecraft/world/entity/npc/VillagerTrades.java.patch diff --git a/patches/net/minecraft/world/entity/npc/VillagerTrades.java.patch b/patches/net/minecraft/world/entity/npc/VillagerTrades.java.patch new file mode 100644 index 0000000000..3af5167c93 --- /dev/null +++ b/patches/net/minecraft/world/entity/npc/VillagerTrades.java.patch @@ -0,0 +1,21 @@ +--- a/net/minecraft/world/entity/npc/VillagerTrades.java ++++ b/net/minecraft/world/entity/npc/VillagerTrades.java +@@ -1484,6 +_,7 @@ + private final int villagerXp; + + public EmeraldsForVillagerTypeItem(int p_35669_, int p_35670_, int p_35671_, Map p_35672_) { ++ if (false) // Neo: disable this check so that mods can add custom villager types + BuiltInRegistries.VILLAGER_TYPE.stream().filter(p_35680_ -> !p_35672_.containsKey(p_35680_)).findAny().ifPresent(p_339515_ -> { + throw new IllegalStateException("Missing trade for villager type: " + BuiltInRegistries.VILLAGER_TYPE.getKey(p_339515_)); + }); +@@ -1497,7 +_,9 @@ + @Override + public MerchantOffer getOffer(Entity p_219685_, RandomSource p_219686_) { + if (p_219685_ instanceof VillagerDataHolder villagerdataholder) { +- ItemCost itemcost = new ItemCost(this.trades.get(villagerdataholder.getVillagerData().getType()), this.cost); ++ Item item = this.trades.get(villagerdataholder.getVillagerData().getType()); ++ if (item == null) return null; // Neo: add a check for unknown villager types ++ ItemCost itemcost = new ItemCost(item, this.cost); + return new MerchantOffer(itemcost, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, 0.05F); + } else { + return null;