Paper/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch
CraftBukkit/Spigot 3736fd83de SPIGOT-6836: Add more API methods in MerchantRecipe
By: Doc <nachito94@msn.com>
2021-12-18 11:44:34 +11:00

62 lines
2.4 KiB
Diff

--- a/net/minecraft/world/item/trading/MerchantRecipe.java
+++ b/net/minecraft/world/item/trading/MerchantRecipe.java
@@ -5,6 +5,8 @@
import net.minecraft.util.MathHelper;
import net.minecraft.world.item.ItemStack;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit
+
public class MerchantRecipe {
public ItemStack baseCostA;
@@ -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
+ private CraftMerchantRecipe bukkitHandle;
+
+ public CraftMerchantRecipe asBukkit() {
+ return (bukkitHandle == null) ? bukkitHandle = new CraftMerchantRecipe(this) : bukkitHandle;
+ }
+
+ 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, 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 +96,7 @@
public ItemStack getCostA() {
int i = this.baseCostA.getCount();
+ if (i <= 0) return ItemStack.EMPTY; // CraftBukkit - SPIGOT-5476
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());
}