From 3736fd83de39631faaf36bcd68a44f61b1ca0bd9 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 18 Dec 2021 11:44:34 +1100 Subject: [PATCH] SPIGOT-6836: Add more API methods in MerchantRecipe By: Doc --- .../world/item/trading/MerchantRecipe.patch | 31 ++++++++++++++++--- .../inventory/CraftMerchantRecipe.java | 30 +++++++++++++++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch index 3652bc29f6..775e5521c9 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch @@ -9,8 +9,14 @@ public class MerchantRecipe { public ItemStack baseCostA; -@@ -17,6 +19,18 @@ - private int demand; +@@ -13,10 +15,26 @@ + public int uses; + public int maxUses; + public boolean rewardExp; +- private int specialPriceDiff; +- private int demand; ++ public int specialPriceDiff; // PAIL private -> public ++ public int demand; // PAIL private -> public public float priceMultiplier; public int xp; + // CraftBukkit start @@ -21,14 +27,18 @@ + } + + public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, CraftMerchantRecipe bukkit) { -+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier); ++ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, 0, bukkit); ++ } ++ ++ public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) { ++ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand); + this.bukkitHandle = bukkit; + } + // CraftBukkit end public MerchantRecipe(NBTTagCompound nbttagcompound) { this.rewardExp = true; -@@ -78,6 +92,7 @@ +@@ -78,6 +96,7 @@ public ItemStack getCostA() { int i = this.baseCostA.getCount(); @@ -36,3 +46,16 @@ ItemStack itemstack = this.baseCostA.copy(); int j = Math.max(0, MathHelper.floor((float) (i * this.demand) * this.priceMultiplier)); +@@ -199,7 +218,11 @@ + if (!this.satisfiedBy(itemstack, itemstack1)) { + return false; + } else { +- itemstack.shrink(this.getCostA().getCount()); ++ // CraftBukkit start ++ if (!this.getCostA().isEmpty()) { ++ itemstack.shrink(this.getCostA().getCount()); ++ } ++ // CraftBukkit end + if (!this.getCostB().isEmpty()) { + itemstack1.shrink(this.getCostB().getCount()); + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java index 79e286ebe3..707c89f706 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java @@ -2,6 +2,8 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import java.util.List; +import net.minecraft.util.MathHelper; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.MerchantRecipe; @@ -17,7 +19,11 @@ public class CraftMerchantRecipe extends MerchantRecipe { } public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier) { - super(result, uses, maxUses, experienceReward, experience, priceMultiplier); + this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0); + } + + public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, int demand, int specialPrice) { + super(result, uses, maxUses, experienceReward, experience, priceMultiplier, demand, specialPrice); this.handle = new net.minecraft.world.item.trading.MerchantRecipe( net.minecraft.world.item.ItemStack.EMPTY, net.minecraft.world.item.ItemStack.EMPTY, @@ -26,11 +32,33 @@ public class CraftMerchantRecipe extends MerchantRecipe { maxUses, experience, priceMultiplier, + demand, this ); + this.setSpecialPrice(specialPrice); this.setExperienceReward(experienceReward); } + @Override + public int getSpecialPrice() { + return handle.getSpecialPriceDiff(); + } + + @Override + public void setSpecialPrice(int specialPrice) { + handle.specialPriceDiff = specialPrice; + } + + @Override + public int getDemand() { + return handle.demand; + } + + @Override + public void setDemand(int demand) { + handle.demand = demand; + } + @Override public int getUses() { return handle.uses;