diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/item/trading/MerchantOffer.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/item/trading/MerchantOffer.java.patch | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/item/trading/MerchantOffer.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/item/trading/MerchantOffer.java.patch new file mode 100644 index 0000000000..83b82b1693 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/item/trading/MerchantOffer.java.patch @@ -0,0 +1,261 @@ +--- a/net/minecraft/world/item/trading/MerchantOffer.java ++++ b/net/minecraft/world/item/trading/MerchantOffer.java +@@ -5,86 +5,104 @@ + import net.minecraft.util.Mth; + import net.minecraft.world.item.ItemStack; + ++import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit ++ + public class MerchantOffer { + +- private final ItemStack baseCostA; +- private final ItemStack costB; +- private final ItemStack result; +- private int uses; +- private final int maxUses; +- private boolean rewardExp; +- private int specialPriceDiff; +- private int demand; +- private float priceMultiplier; +- private int xp; ++ public ItemStack baseCostA; ++ public ItemStack costB; ++ public final ItemStack result; ++ public int uses; ++ public int maxUses; ++ public boolean rewardExp; ++ public int specialPriceDiff; ++ public int demand; ++ public float priceMultiplier; ++ public int xp; ++ // CraftBukkit start ++ private CraftMerchantRecipe bukkitHandle; + +- public MerchantOffer(CompoundTag compoundtag) { ++ public CraftMerchantRecipe asBukkit() { ++ return (bukkitHandle == null) ? bukkitHandle = new CraftMerchantRecipe(this) : bukkitHandle; ++ } ++ ++ public MerchantOffer(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 MerchantOffer(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 MerchantOffer(CompoundTag compoundTag) { + this.rewardExp = true; + this.xp = 1; +- this.baseCostA = ItemStack.of(compoundtag.getCompound("buy")); +- this.costB = ItemStack.of(compoundtag.getCompound("buyB")); +- this.result = ItemStack.of(compoundtag.getCompound("sell")); +- this.uses = compoundtag.getInt("uses"); +- if (compoundtag.contains("maxUses", 99)) { +- this.maxUses = compoundtag.getInt("maxUses"); ++ this.baseCostA = ItemStack.of(compoundTag.getCompound("buy")); ++ this.costB = ItemStack.of(compoundTag.getCompound("buyB")); ++ this.result = ItemStack.of(compoundTag.getCompound("sell")); ++ this.uses = compoundTag.getInt("uses"); ++ if (compoundTag.contains("maxUses", 99)) { ++ this.maxUses = compoundTag.getInt("maxUses"); + } else { + this.maxUses = 4; + } + +- if (compoundtag.contains("rewardExp", 1)) { +- this.rewardExp = compoundtag.getBoolean("rewardExp"); ++ if (compoundTag.contains("rewardExp", 1)) { ++ this.rewardExp = compoundTag.getBoolean("rewardExp"); + } + +- if (compoundtag.contains("xp", 3)) { +- this.xp = compoundtag.getInt("xp"); ++ if (compoundTag.contains("xp", 3)) { ++ this.xp = compoundTag.getInt("xp"); + } + +- if (compoundtag.contains("priceMultiplier", 5)) { +- this.priceMultiplier = compoundtag.getFloat("priceMultiplier"); ++ if (compoundTag.contains("priceMultiplier", 5)) { ++ this.priceMultiplier = compoundTag.getFloat("priceMultiplier"); + } + +- this.specialPriceDiff = compoundtag.getInt("specialPrice"); +- this.demand = compoundtag.getInt("demand"); ++ this.specialPriceDiff = compoundTag.getInt("specialPrice"); ++ this.demand = compoundTag.getInt("demand"); + } + +- public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, int i, int j, float f) { +- this(itemstack, ItemStack.EMPTY, itemstack1, i, j, f); ++ public MerchantOffer(ItemStack baseCostA, ItemStack result, int maxUses, int xp, float priceMultiplier) { ++ this(baseCostA, ItemStack.EMPTY, result, maxUses, xp, priceMultiplier); + } + +- public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, float f) { +- this(itemstack, itemstack1, itemstack2, 0, i, j, f); ++ public MerchantOffer(ItemStack baseCostA, ItemStack costB, ItemStack result, int maxUses, int xp, float priceMultiplier) { ++ this(baseCostA, costB, result, 0, maxUses, xp, priceMultiplier); + } + +- public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, int k, float f) { +- this(itemstack, itemstack1, itemstack2, i, j, k, f, 0); ++ public MerchantOffer(ItemStack baseCostA, ItemStack costB, ItemStack result, int uses, int maxUses, int xp, float priceMultiplier) { ++ this(baseCostA, costB, result, uses, maxUses, xp, priceMultiplier, 0); + } + +- public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, int k, float f, int l) { ++ public MerchantOffer(ItemStack baseCostA, ItemStack costB, ItemStack result, int uses, int maxUses, int xp, float priceMultiplier, int demand) { + this.rewardExp = true; + this.xp = 1; +- this.baseCostA = itemstack; +- this.costB = itemstack1; +- this.result = itemstack2; +- this.uses = i; +- this.maxUses = j; +- this.xp = k; +- this.priceMultiplier = f; +- this.demand = l; ++ this.baseCostA = baseCostA; ++ this.costB = costB; ++ this.result = result; ++ this.uses = uses; ++ this.maxUses = maxUses; ++ this.xp = xp; ++ this.priceMultiplier = priceMultiplier; ++ this.demand = demand; + } + +- private MerchantOffer(MerchantOffer merchantoffer) { ++ private MerchantOffer(MerchantOffer merchantrecipe) { + this.rewardExp = true; + this.xp = 1; +- this.baseCostA = merchantoffer.baseCostA.copy(); +- this.costB = merchantoffer.costB.copy(); +- this.result = merchantoffer.result.copy(); +- this.uses = merchantoffer.uses; +- this.maxUses = merchantoffer.maxUses; +- this.rewardExp = merchantoffer.rewardExp; +- this.specialPriceDiff = merchantoffer.specialPriceDiff; +- this.demand = merchantoffer.demand; +- this.priceMultiplier = merchantoffer.priceMultiplier; +- this.xp = merchantoffer.xp; ++ this.baseCostA = merchantrecipe.baseCostA.copy(); ++ this.costB = merchantrecipe.costB.copy(); ++ this.result = merchantrecipe.result.copy(); ++ this.uses = merchantrecipe.uses; ++ this.maxUses = merchantrecipe.maxUses; ++ this.rewardExp = merchantrecipe.rewardExp; ++ this.specialPriceDiff = merchantrecipe.specialPriceDiff; ++ this.demand = merchantrecipe.demand; ++ this.priceMultiplier = merchantrecipe.priceMultiplier; ++ this.xp = merchantrecipe.xp; + } + + public ItemStack getBaseCostA() { +@@ -96,6 +114,7 @@ + return ItemStack.EMPTY; + } else { + int i = this.baseCostA.getCount(); ++ if (i <= 0) return ItemStack.EMPTY; // CraftBukkit - SPIGOT-5476 + int j = Math.max(0, Mth.floor((float) (i * this.demand) * this.priceMultiplier)); + + return this.baseCostA.copyWithCount(Mth.clamp(i + j + this.specialPriceDiff, 1, this.baseCostA.getItem().getMaxStackSize())); +@@ -138,8 +157,8 @@ + return this.demand; + } + +- public void addToSpecialPriceDiff(int i) { +- this.specialPriceDiff += i; ++ public void addToSpecialPriceDiff(int add) { ++ this.specialPriceDiff += add; + } + + public void resetSpecialPriceDiff() { +@@ -150,8 +169,8 @@ + return this.specialPriceDiff; + } + +- public void setSpecialPriceDiff(int i) { +- this.specialPriceDiff = i; ++ public void setSpecialPriceDiff(int price) { ++ this.specialPriceDiff = price; + } + + public float getPriceMultiplier() { +@@ -179,46 +198,50 @@ + } + + public CompoundTag createTag() { +- CompoundTag compoundtag = new CompoundTag(); ++ CompoundTag nbttagcompound = new CompoundTag(); + +- compoundtag.put("buy", this.baseCostA.save(new CompoundTag())); +- compoundtag.put("sell", this.result.save(new CompoundTag())); +- compoundtag.put("buyB", this.costB.save(new CompoundTag())); +- compoundtag.putInt("uses", this.uses); +- compoundtag.putInt("maxUses", this.maxUses); +- compoundtag.putBoolean("rewardExp", this.rewardExp); +- compoundtag.putInt("xp", this.xp); +- compoundtag.putFloat("priceMultiplier", this.priceMultiplier); +- compoundtag.putInt("specialPrice", this.specialPriceDiff); +- compoundtag.putInt("demand", this.demand); +- return compoundtag; ++ nbttagcompound.put("buy", this.baseCostA.save(new CompoundTag())); ++ nbttagcompound.put("sell", this.result.save(new CompoundTag())); ++ nbttagcompound.put("buyB", this.costB.save(new CompoundTag())); ++ nbttagcompound.putInt("uses", this.uses); ++ nbttagcompound.putInt("maxUses", this.maxUses); ++ nbttagcompound.putBoolean("rewardExp", this.rewardExp); ++ nbttagcompound.putInt("xp", this.xp); ++ nbttagcompound.putFloat("priceMultiplier", this.priceMultiplier); ++ nbttagcompound.putInt("specialPrice", this.specialPriceDiff); ++ nbttagcompound.putInt("demand", this.demand); ++ return nbttagcompound; + } + +- public boolean satisfiedBy(ItemStack itemstack, ItemStack itemstack1) { +- return this.isRequiredItem(itemstack, this.getCostA()) && itemstack.getCount() >= this.getCostA().getCount() && this.isRequiredItem(itemstack1, this.costB) && itemstack1.getCount() >= this.costB.getCount(); ++ public boolean satisfiedBy(ItemStack playerOfferA, ItemStack playerOfferB) { ++ return this.isRequiredItem(playerOfferA, this.getCostA()) && playerOfferA.getCount() >= this.getCostA().getCount() && this.isRequiredItem(playerOfferB, this.costB) && playerOfferB.getCount() >= this.costB.getCount(); + } + +- private boolean isRequiredItem(ItemStack itemstack, ItemStack itemstack1) { +- if (itemstack1.isEmpty() && itemstack.isEmpty()) { ++ private boolean isRequiredItem(ItemStack offer, ItemStack cost) { ++ if (cost.isEmpty() && offer.isEmpty()) { + return true; + } else { +- ItemStack itemstack2 = itemstack.copy(); ++ ItemStack itemstack2 = offer.copy(); + + if (itemstack2.getItem().canBeDepleted()) { + itemstack2.setDamageValue(itemstack2.getDamageValue()); + } + +- return ItemStack.isSameItem(itemstack2, itemstack1) && (!itemstack1.hasTag() || itemstack2.hasTag() && NbtUtils.compareNbt(itemstack1.getTag(), itemstack2.getTag(), false)); ++ return ItemStack.isSameItem(itemstack2, cost) && (!cost.hasTag() || itemstack2.hasTag() && NbtUtils.compareNbt(cost.getTag(), itemstack2.getTag(), false)); + } + } + +- public boolean take(ItemStack itemstack, ItemStack itemstack1) { +- if (!this.satisfiedBy(itemstack, itemstack1)) { ++ public boolean take(ItemStack playerOfferA, ItemStack playerOfferB) { ++ if (!this.satisfiedBy(playerOfferA, playerOfferB)) { + return false; + } else { +- itemstack.shrink(this.getCostA().getCount()); ++ // CraftBukkit start ++ if (!this.getCostA().isEmpty()) { ++ playerOfferA.shrink(this.getCostA().getCount()); ++ } ++ // CraftBukkit end + if (!this.getCostB().isEmpty()) { +- itemstack1.shrink(this.getCostB().getCount()); ++ playerOfferB.shrink(this.getCostB().getCount()); + } + + return true; |