From eb6c1bf31a29bf3880f6e496f5e4ea52e1bdf291 Mon Sep 17 00:00:00 2001 From: Xor Boole Date: Wed, 30 Nov 2016 16:40:40 +1100 Subject: [PATCH] Add some expansions to Anvil Inventory API --- nms-patches/ContainerAnvil.patch | 22 +++++++++++++++---- .../inventory/CraftInventoryAnvil.java | 22 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/nms-patches/ContainerAnvil.patch b/nms-patches/ContainerAnvil.patch index f42c2945b3..27ce994b2c 100644 --- a/nms-patches/ContainerAnvil.patch +++ b/nms-patches/ContainerAnvil.patch @@ -11,9 +11,12 @@ public class ContainerAnvil extends Container { private static final Logger f = LogManager.getLogger(); -@@ -22,8 +26,13 @@ +@@ -20,10 +24,15 @@ + private final BlockPosition j; + public int a; private int k; - private String l; +- private String l; ++ public String l; // PAIL: private -> public private final EntityHuman m; + // CraftBukkit start + private CraftInventoryView bukkitEntity; @@ -69,20 +72,31 @@ return this.i.getType(this.j).getBlock() != Blocks.ANVIL ? false : entityhuman.d((double) this.j.getX() + 0.5D, (double) this.j.getY() + 0.5D, (double) this.j.getZ() + 0.5D) <= 64.0D; } -@@ -350,4 +360,18 @@ +@@ -350,4 +360,29 @@ this.e(); } + + // CraftBukkit start + @Override ++ public void b() { ++ super.b(); ++ ++ for (int i = 0; i < this.listeners.size(); ++i) { ++ ICrafting icrafting = (ICrafting) this.listeners.get(i); ++ ++ icrafting.setContainerData(this, 0, this.a); ++ } ++ } ++ ++ @Override + public CraftInventoryView getBukkitView() { + if (bukkitEntity != null) { + return bukkitEntity; + } + + org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil( -+ new org.bukkit.Location(i.getWorld(), j.getX(), j.getY(), j.getZ()), this.h, this.g); ++ new org.bukkit.Location(i.getWorld(), j.getX(), j.getY(), j.getZ()), this.h, this.g, this); + bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this); + return bukkitEntity; + } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java index 6b415f234c..6647b167c3 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java @@ -1,19 +1,22 @@ package org.bukkit.craftbukkit.inventory; +import net.minecraft.server.ContainerAnvil; import net.minecraft.server.IInventory; import org.bukkit.Location; - import org.bukkit.inventory.AnvilInventory; import org.bukkit.inventory.ItemStack; public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory { + private final Location location; private final IInventory resultInventory; + private final ContainerAnvil container; - public CraftInventoryAnvil(Location location, IInventory inventory, IInventory resultInventory) { + public CraftInventoryAnvil(Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { super(inventory); this.location = location; this.resultInventory = resultInventory; + this.container = container; } public IInventory getResultInventory() { @@ -53,4 +56,19 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor public Location getLocation() { return location; } + + @Override + public String getRenameText() { + return container.l; // PAIL: renameText + } + + @Override + public int getRepairCost() { + return container.a; // PAIL: levelCost + } + + @Override + public void setRepairCost(int i) { + container.a = i; // PAIL:levelCost + } }