From 630c815714d7b416a55067718555f05bb7d58f2f Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 14 Dec 2024 14:45:10 -0800 Subject: [PATCH] net.minecraft.world.item.trading --- .../world/item/trading/Merchant.java.patch | 4 +- .../item/trading/MerchantOffer.java.patch | 87 ++++++++++++++++++ .../item/trading/MerchantOffer.java.patch | 90 ------------------- 3 files changed, 89 insertions(+), 92 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/world/item/trading/Merchant.java.patch (94%) create mode 100644 paper-server/patches/sources/net/minecraft/world/item/trading/MerchantOffer.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/item/trading/MerchantOffer.java.patch diff --git a/paper-server/patches/unapplied/net/minecraft/world/item/trading/Merchant.java.patch b/paper-server/patches/sources/net/minecraft/world/item/trading/Merchant.java.patch similarity index 94% rename from paper-server/patches/unapplied/net/minecraft/world/item/trading/Merchant.java.patch rename to paper-server/patches/sources/net/minecraft/world/item/trading/Merchant.java.patch index a8626b121e..36c879841f 100644 --- a/paper-server/patches/unapplied/net/minecraft/world/item/trading/Merchant.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/trading/Merchant.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/trading/Merchant.java +++ b/net/minecraft/world/item/trading/Merchant.java -@@ -20,6 +20,7 @@ +@@ -19,6 +_,7 @@ void overrideOffers(MerchantOffers offers); @@ -8,7 +8,7 @@ void notifyTrade(MerchantOffer offer); void notifyTradeUpdated(ItemStack stack); -@@ -54,4 +55,6 @@ +@@ -50,4 +_,6 @@ boolean isClientSide(); boolean stillValid(Player player); diff --git a/paper-server/patches/sources/net/minecraft/world/item/trading/MerchantOffer.java.patch b/paper-server/patches/sources/net/minecraft/world/item/trading/MerchantOffer.java.patch new file mode 100644 index 0000000000..05eb5597d3 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/item/trading/MerchantOffer.java.patch @@ -0,0 +1,87 @@ +--- a/net/minecraft/world/item/trading/MerchantOffer.java ++++ b/net/minecraft/world/item/trading/MerchantOffer.java +@@ -21,6 +_,7 @@ + Codec.INT.lenientOptionalFieldOf("demand", Integer.valueOf(0)).forGetter(merchantOffer -> merchantOffer.demand), + Codec.FLOAT.lenientOptionalFieldOf("priceMultiplier", Float.valueOf(0.0F)).forGetter(merchantOffer -> merchantOffer.priceMultiplier), + Codec.INT.lenientOptionalFieldOf("xp", Integer.valueOf(1)).forGetter(merchantOffer -> merchantOffer.xp) ++ , Codec.BOOL.lenientOptionalFieldOf("Paper.IgnoreDiscounts", false).forGetter(merchantOffer -> merchantOffer.ignoreDiscounts) // Paper + ) + .apply(instance, MerchantOffer::new) + ); +@@ -37,6 +_,21 @@ + public int demand; + public float priceMultiplier; + public int xp; ++ public boolean ignoreDiscounts; // Paper - Add ignore discounts API ++ ++ // CraftBukkit start ++ private org.bukkit.craftbukkit.inventory.@org.jspecify.annotations.Nullable CraftMerchantRecipe bukkitHandle; ++ ++ public org.bukkit.craftbukkit.inventory.CraftMerchantRecipe asBukkit() { ++ return (this.bukkitHandle == null) ? this.bukkitHandle = new org.bukkit.craftbukkit.inventory.CraftMerchantRecipe(this) : this.bukkitHandle; ++ } ++ ++ public MerchantOffer(ItemCost baseCostA, Optional costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, final boolean ignoreDiscounts, org.bukkit.craftbukkit.inventory.CraftMerchantRecipe bukkit) { // Paper ++ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand); ++ this.ignoreDiscounts = ignoreDiscounts; // Paper ++ this.bukkitHandle = bukkit; ++ } ++ // CraftBukkit end + + private MerchantOffer( + ItemCost baseCostA, +@@ -49,6 +_,7 @@ + int demand, + float priceMultiplier, + int xp ++ , final boolean ignoreDiscounts // Paper + ) { + this.baseCostA = baseCostA; + this.costB = costB; +@@ -60,6 +_,7 @@ + this.demand = demand; + this.priceMultiplier = priceMultiplier; + this.xp = xp; ++ this.ignoreDiscounts = ignoreDiscounts; // Paper + } + + public MerchantOffer(ItemCost baseCostA, ItemStack result, int maxUses, int xp, float priceMultiplier) { +@@ -75,7 +_,7 @@ + } + + public MerchantOffer(ItemCost baseCostA, Optional costB, ItemStack result, int _uses, int maxUses, int xp, float priceMultiplier, int demand) { +- this(baseCostA, costB, result, _uses, maxUses, true, 0, demand, priceMultiplier, xp); ++ this(baseCostA, costB, result, _uses, maxUses, true, 0, demand, priceMultiplier, xp, false); // Paper + } + + private MerchantOffer(MerchantOffer other) { +@@ -90,6 +_,7 @@ + other.demand, + other.priceMultiplier, + other.xp ++ , other.ignoreDiscounts // Paper + ); + } + +@@ -124,7 +_,7 @@ + } + + public void updateDemand() { +- this.demand = this.demand + this.uses - (this.maxUses - this.uses); ++ this.demand = Math.max(0, this.demand + this.uses - (this.maxUses - this.uses)); // Paper - Fix MC-163962 + } + + public ItemStack assemble() { +@@ -205,7 +_,11 @@ + if (!this.satisfiedBy(playerOfferA, playerOfferB)) { + return false; + } else { +- playerOfferA.shrink(this.getCostA().getCount()); ++ // CraftBukkit start ++ if (!this.getCostA().isEmpty()) { ++ playerOfferA.shrink(this.getCostA().getCount()); ++ } ++ // CraftBukkit end + if (!this.getCostB().isEmpty()) { + playerOfferB.shrink(this.getCostB().getCount()); + } diff --git a/paper-server/patches/unapplied/net/minecraft/world/item/trading/MerchantOffer.java.patch b/paper-server/patches/unapplied/net/minecraft/world/item/trading/MerchantOffer.java.patch deleted file mode 100644 index bf956ac4ae..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/item/trading/MerchantOffer.java.patch +++ /dev/null @@ -1,90 +0,0 @@ ---- a/net/minecraft/world/item/trading/MerchantOffer.java -+++ b/net/minecraft/world/item/trading/MerchantOffer.java -@@ -8,6 +8,8 @@ - import net.minecraft.util.Mth; - import net.minecraft.world.item.ItemStack; - -+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit -+ - public class MerchantOffer { - - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { -@@ -31,6 +33,10 @@ - return merchantrecipe.priceMultiplier; - }), Codec.INT.lenientOptionalFieldOf("xp", 1).forGetter((merchantrecipe) -> { - return merchantrecipe.xp; -+ // Paper start -+ }), Codec.BOOL.lenientOptionalFieldOf("Paper.IgnoreDiscounts", false).forGetter((merchantrecipe) -> { -+ return merchantrecipe.ignoreDiscounts; -+ // Paper end - })).apply(instance, MerchantOffer::new); - }); - public static final StreamCodec STREAM_CODEC = StreamCodec.of(MerchantOffer::writeToStream, MerchantOffer::createFromStream); -@@ -44,8 +50,22 @@ - public int demand; - public float priceMultiplier; - public int xp; -+ public boolean ignoreDiscounts; // Paper - Add ignore discounts API -+ // CraftBukkit start -+ private CraftMerchantRecipe bukkitHandle; - -- private MerchantOffer(ItemCost firstBuyItem, Optional secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience) { -+ public CraftMerchantRecipe asBukkit() { -+ return (this.bukkitHandle == null) ? this.bukkitHandle = new CraftMerchantRecipe(this) : this.bukkitHandle; -+ } -+ -+ public MerchantOffer(ItemCost baseCostA, Optional costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, final boolean ignoreDiscounts, CraftMerchantRecipe bukkit) { // Paper -+ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand); -+ this.ignoreDiscounts = ignoreDiscounts; // Paper -+ this.bukkitHandle = bukkit; -+ } -+ // CraftBukkit end -+ -+ private MerchantOffer(ItemCost firstBuyItem, Optional secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience, final boolean ignoreDiscounts) { // Paper - this.baseCostA = firstBuyItem; - this.costB = secondBuyItem; - this.result = sellItem; -@@ -56,6 +76,7 @@ - this.demand = demandBonus; - this.priceMultiplier = priceMultiplier; - this.xp = merchantExperience; -+ this.ignoreDiscounts = ignoreDiscounts; // Paper - } - - public MerchantOffer(ItemCost buyItem, ItemStack sellItem, int maxUses, int merchantExperience, float priceMultiplier) { -@@ -71,11 +92,11 @@ - } - - public MerchantOffer(ItemCost firstBuyItem, Optional secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, int demandBonus) { -- this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, true, 0, demandBonus, priceMultiplier, merchantExperience); -+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, true, 0, demandBonus, priceMultiplier, merchantExperience, false); // Paper - } - - private MerchantOffer(MerchantOffer offer) { -- this(offer.baseCostA, offer.costB, offer.result.copy(), offer.uses, offer.maxUses, offer.rewardExp, offer.specialPriceDiff, offer.demand, offer.priceMultiplier, offer.xp); -+ this(offer.baseCostA, offer.costB, offer.result.copy(), offer.uses, offer.maxUses, offer.rewardExp, offer.specialPriceDiff, offer.demand, offer.priceMultiplier, offer.xp, offer.ignoreDiscounts); // Paper - } - - public ItemStack getBaseCostA() { -@@ -110,7 +131,7 @@ - } - - public void updateDemand() { -- this.demand = this.demand + this.uses - (this.maxUses - this.uses); -+ this.demand = Math.max(0, this.demand + this.uses - (this.maxUses - this.uses)); // Paper - Fix MC-163962 - } - - public ItemStack assemble() { -@@ -185,7 +206,11 @@ - if (!this.satisfiedBy(firstBuyStack, secondBuyStack)) { - return false; - } else { -- firstBuyStack.shrink(this.getCostA().getCount()); -+ // CraftBukkit start -+ if (!this.getCostA().isEmpty()) { -+ firstBuyStack.shrink(this.getCostA().getCount()); -+ } -+ // CraftBukkit end - if (!this.getCostB().isEmpty()) { - secondBuyStack.shrink(this.getCostB().getCount()); - }