From 4401d58269cd42a076dfbb28e0a6d93047a11a9c Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Sat, 18 Jan 2025 21:02:33 -0500 Subject: [PATCH] Patch VillagerTrades.EmeraldsForVillagerTypeItem to allow modders to make Custom Villager Types --- .../entity/npc/VillagerTrades.java.patch | 22 +++++++++++++++++++ 1 file changed, 22 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..615a9b1e58 --- /dev/null +++ b/patches/net/minecraft/world/entity/npc/VillagerTrades.java.patch @@ -0,0 +1,22 @@ +--- a/net/minecraft/world/entity/npc/VillagerTrades.java ++++ b/net/minecraft/world/entity/npc/VillagerTrades.java +@@ -1484,9 +_,6 @@ + private final int villagerXp; + + public EmeraldsForVillagerTypeItem(int p_35669_, int p_35670_, int p_35671_, Map p_35672_) { +- 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_)); +- }); + this.trades = p_35672_; + this.cost = p_35669_; + this.maxUses = p_35670_; +@@ -1498,6 +_,9 @@ + 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); ++ if (itemcost.itemStack().isEmpty()) { ++ return null; ++ } + return new MerchantOffer(itemcost, new ItemStack(Items.EMERALD), this.maxUses, this.villagerXp, 0.05F); + } else { + return null;