mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 18:27:17 +01:00
SPIGOT-6836: Add more API methods in MerchantRecipe
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
13aa9b7211
commit
3736fd83de
2 changed files with 56 additions and 5 deletions
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue