--- a/net/minecraft/world/inventory/ContainerAnvil.java +++ b/net/minecraft/world/inventory/ContainerAnvil.java @@ -17,12 +17,16 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftInventoryView; +// CraftBukkit end + public class ContainerAnvil extends ContainerAnvilAbstract { private static final Logger LOGGER = LogUtils.getLogger(); private static final boolean DEBUG_COST = false; public static final int MAX_NAME_LENGTH = 50; - private int repairItemCountCost; + public int repairItemCountCost; // PAIL private -> public public String itemName; public final ContainerProperty cost; private static final int COST_FAIL = 0; @@ -32,6 +36,10 @@ private static final int COST_REPAIR_SACRIFICE = 2; private static final int COST_INCOMPATIBLE_PENALTY = 1; private static final int COST_RENAME = 1; + // CraftBukkit start + public int maximumRepairCost = 40; + private CraftInventoryView bukkitEntity; + // CraftBukkit end public ContainerAnvil(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); @@ -104,7 +112,7 @@ byte b1 = 0; if (itemstack.isEmpty()) { - this.resultSlots.setItem(0, ItemStack.EMPTY); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit this.cost.set(0); } else { ItemStack itemstack1 = itemstack.copy(); @@ -122,7 +130,7 @@ if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) { k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); if (k <= 0) { - this.resultSlots.setItem(0, ItemStack.EMPTY); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit this.cost.set(0); return; } @@ -137,7 +145,7 @@ this.repairItemCountCost = i1; } else { if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) { - this.resultSlots.setItem(0, ItemStack.EMPTY); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit this.cost.set(0); return; } @@ -227,7 +235,7 @@ } if (flag2 && !flag1) { - this.resultSlots.setItem(0, ItemStack.EMPTY); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit this.cost.set(0); return; } @@ -251,11 +259,11 @@ itemstack1 = ItemStack.EMPTY; } - if (b1 == i && b1 > 0 && this.cost.get() >= 40) { - this.cost.set(39); + if (b1 == i && b1 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit + this.cost.set(maximumRepairCost - 1); // CraftBukkit } - if (this.cost.get() >= 40 && !this.player.getAbilities().instabuild) { + if (this.cost.get() >= maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit itemstack1 = ItemStack.EMPTY; } @@ -274,7 +282,8 @@ EnchantmentManager.setEnchantments(map, itemstack1); } - this.resultSlots.setItem(0, itemstack1); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit + sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client this.broadcastChanges(); } } @@ -301,4 +310,18 @@ public int getCost() { return this.cost.get(); } + + // CraftBukkit start + @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity != null) { + return bukkitEntity; + } + + org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil( + access.getLocation(), this.inputSlots, this.resultSlots, this); + bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this); + return bukkitEntity; + } + // CraftBukkit end }