diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/inventory/MerchantContainer.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/inventory/MerchantContainer.java.patch | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/inventory/MerchantContainer.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/inventory/MerchantContainer.java.patch new file mode 100644 index 0000000000..4ce4a4d409 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/inventory/MerchantContainer.java.patch @@ -0,0 +1,196 @@ +--- a/net/minecraft/world/inventory/MerchantContainer.java ++++ b/net/minecraft/world/inventory/MerchantContainer.java +@@ -1,24 +1,76 @@ + package net.minecraft.world.inventory; + ++import java.util.Iterator; + import javax.annotation.Nullable; + import net.minecraft.core.NonNullList; + import net.minecraft.world.Container; + import net.minecraft.world.ContainerHelper; ++import net.minecraft.world.entity.npc.AbstractVillager; ++import net.minecraft.world.entity.npc.Villager; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.item.trading.Merchant; + import net.minecraft.world.item.trading.MerchantOffer; + import net.minecraft.world.item.trading.MerchantOffers; ++// CraftBukkit start ++import java.util.List; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; ++import org.bukkit.craftbukkit.entity.CraftAbstractVillager; ++import org.bukkit.entity.HumanEntity; ++// CraftBukkit end + + public class MerchantContainer implements Container { ++ + private final Merchant merchant; +- private final NonNullList<ItemStack> itemStacks = NonNullList.withSize(3, ItemStack.EMPTY); ++ private final NonNullList<ItemStack> itemStacks; + @Nullable + private MerchantOffer activeOffer; +- private int selectionHint; ++ public int selectionHint; + private int futureXp; + ++ // CraftBukkit start - add fields and methods ++ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>(); ++ private int maxStack = MAX_STACK; ++ ++ public List<ItemStack> getContents() { ++ return this.itemStacks; ++ } ++ ++ public void onOpen(CraftHumanEntity who) { ++ transaction.add(who); ++ } ++ ++ public void onClose(CraftHumanEntity who) { ++ transaction.remove(who); ++ merchant.setTradingPlayer((Player) null); // SPIGOT-4860 ++ } ++ ++ public List<HumanEntity> getViewers() { ++ return transaction; ++ } ++ ++ @Override ++ public int getMaxStackSize() { ++ return maxStack; ++ } ++ ++ public void setMaxStackSize(int i) { ++ maxStack = i; ++ } ++ ++ public org.bukkit.inventory.InventoryHolder getOwner() { ++ return (merchant instanceof AbstractVillager) ? (CraftAbstractVillager) ((AbstractVillager) this.merchant).getBukkitEntity() : null; ++ } ++ ++ @Override ++ public Location getLocation() { ++ return (merchant instanceof Villager) ? ((Villager) this.merchant).getBukkitEntity().getLocation() : null; ++ } ++ // CraftBukkit end ++ + public MerchantContainer(Merchant merchant) { ++ this.itemStacks = NonNullList.withSize(3, ItemStack.EMPTY); + this.merchant = merchant; + } + +@@ -29,32 +81,40 @@ + + @Override + public boolean isEmpty() { +- for (ItemStack itemStack : this.itemStacks) { +- if (!itemStack.isEmpty()) { +- return false; ++ Iterator iterator = this.itemStacks.iterator(); ++ ++ ItemStack itemstack; ++ ++ do { ++ if (!iterator.hasNext()) { ++ return true; + } +- } + +- return true; ++ itemstack = (ItemStack) iterator.next(); ++ } while (itemstack.isEmpty()); ++ ++ return false; + } + + @Override + public ItemStack getItem(int index) { +- return this.itemStacks.get(index); ++ return (ItemStack) this.itemStacks.get(index); + } + + @Override + public ItemStack removeItem(int index, int count) { +- ItemStack itemStack = this.itemStacks.get(index); +- if (index == 2 && !itemStack.isEmpty()) { +- return ContainerHelper.removeItem(this.itemStacks, index, itemStack.getCount()); ++ ItemStack itemstack = (ItemStack) this.itemStacks.get(index); ++ ++ if (index == 2 && !itemstack.isEmpty()) { ++ return ContainerHelper.removeItem(this.itemStacks, index, itemstack.getCount()); + } else { +- ItemStack itemStack1 = ContainerHelper.removeItem(this.itemStacks, index, count); +- if (!itemStack1.isEmpty() && this.isPaymentSlot(index)) { ++ ItemStack itemstack1 = ContainerHelper.removeItem(this.itemStacks, index, count); ++ ++ if (!itemstack1.isEmpty() && this.isPaymentSlot(index)) { + this.updateSellItem(); + } + +- return itemStack1; ++ return itemstack1; + } + } + +@@ -77,6 +137,7 @@ + if (this.isPaymentSlot(index)) { + this.updateSellItem(); + } ++ + } + + @Override +@@ -91,32 +152,35 @@ + + public void updateSellItem() { + this.activeOffer = null; +- ItemStack itemStack; +- ItemStack itemStack1; +- if (this.itemStacks.get(0).isEmpty()) { +- itemStack = this.itemStacks.get(1); +- itemStack1 = ItemStack.EMPTY; ++ ItemStack itemstack; ++ ItemStack itemstack1; ++ ++ if (((ItemStack) this.itemStacks.get(0)).isEmpty()) { ++ itemstack = (ItemStack) this.itemStacks.get(1); ++ itemstack1 = ItemStack.EMPTY; + } else { +- itemStack = this.itemStacks.get(0); +- itemStack1 = this.itemStacks.get(1); ++ itemstack = (ItemStack) this.itemStacks.get(0); ++ itemstack1 = (ItemStack) this.itemStacks.get(1); + } + +- if (itemStack.isEmpty()) { ++ if (itemstack.isEmpty()) { + this.setItem(2, ItemStack.EMPTY); + this.futureXp = 0; + } else { +- MerchantOffers offers = this.merchant.getOffers(); +- if (!offers.isEmpty()) { +- MerchantOffer recipeFor = offers.getRecipeFor(itemStack, itemStack1, this.selectionHint); +- if (recipeFor == null || recipeFor.isOutOfStock()) { +- this.activeOffer = recipeFor; +- recipeFor = offers.getRecipeFor(itemStack1, itemStack, this.selectionHint); ++ MerchantOffers merchantrecipelist = this.merchant.getOffers(); ++ ++ if (!merchantrecipelist.isEmpty()) { ++ MerchantOffer merchantrecipe = merchantrecipelist.getRecipeFor(itemstack, itemstack1, this.selectionHint); ++ ++ if (merchantrecipe == null || merchantrecipe.isOutOfStock()) { ++ this.activeOffer = merchantrecipe; ++ merchantrecipe = merchantrecipelist.getRecipeFor(itemstack1, itemstack, this.selectionHint); + } + +- if (recipeFor != null && !recipeFor.isOutOfStock()) { +- this.activeOffer = recipeFor; +- this.setItem(2, recipeFor.assemble()); +- this.futureXp = recipeFor.getXp(); ++ if (merchantrecipe != null && !merchantrecipe.isOutOfStock()) { ++ this.activeOffer = merchantrecipe; ++ this.setItem(2, merchantrecipe.assemble()); ++ this.futureXp = merchantrecipe.getXp(); + } else { + this.setItem(2, ItemStack.EMPTY); + this.futureXp = 0; |