PaperMC/nms-patches/ContainerAnvil.patch

131 lines
4.9 KiB
Diff

--- a/net/minecraft/server/ContainerAnvil.java
+++ b/net/minecraft/server/ContainerAnvil.java
@@ -6,6 +6,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerAnvil extends Container {
private static final Logger f = LogManager.getLogger();
@@ -22,8 +26,15 @@
private int k;
public String renameText;
private final EntityHuman m;
+ // CraftBukkit start
+ public int maximumRepairCost = 40;
+ private int lastLevelCost;
+ private CraftInventoryView bukkitEntity;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerAnvil(PlayerInventory playerinventory, final World world, final BlockPosition blockposition, EntityHuman entityhuman) {
+ this.player = playerinventory; // CraftBukkit
this.j = blockposition;
this.i = world;
this.m = entityhuman;
@@ -111,7 +122,7 @@
byte b1 = 0;
if (itemstack.isEmpty()) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
this.levelCost = 0;
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
@@ -129,7 +140,7 @@
if (itemstack1.e() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.getDamage(), itemstack1.h() / 4);
if (k <= 0) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
this.levelCost = 0;
return;
}
@@ -144,7 +155,7 @@
this.k = l;
} else {
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.e())) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
this.levelCost = 0;
return;
}
@@ -237,7 +248,7 @@
}
if (flag2 && !flag1) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
this.levelCost = 0;
return;
}
@@ -261,11 +272,11 @@
itemstack1 = ItemStack.a;
}
- if (b1 == i && b1 > 0 && this.levelCost >= 40) {
- this.levelCost = 39;
+ if (b1 == i && b1 > 0 && this.levelCost >= maximumRepairCost) { // CraftBukkit
+ this.levelCost = maximumRepairCost - 1; // CraftBukkit
}
- if (this.levelCost >= 40 && !this.m.abilities.canInstantlyBuild) {
+ if (this.levelCost >= maximumRepairCost && !this.m.abilities.canInstantlyBuild) { // CraftBukkit
itemstack1 = ItemStack.a;
}
@@ -284,7 +295,7 @@
EnchantmentManager.a(map, itemstack1);
}
- this.g.setItem(0, itemstack1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
this.b();
}
}
@@ -302,6 +313,7 @@
}
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return !this.i.getType(this.j).a(TagsBlock.ANVIL) ? false : entityhuman.d((double) this.j.getX() + 0.5D, (double) this.j.getY() + 0.5D, (double) this.j.getZ() + 0.5D) <= 64.0D;
}
@@ -357,4 +369,33 @@
this.d();
}
+
+ // CraftBukkit start
+ @Override
+ public void b() {
+ super.b();
+
+ for (int i = 0; i < this.listeners.size(); ++i) {
+ ICrafting icrafting = (ICrafting) this.listeners.get(i);
+
+ if (this.lastLevelCost != this.levelCost) {
+ icrafting.setContainerData(this, 0, this.levelCost);
+ }
+ }
+
+ this.lastLevelCost = this.levelCost;
+ }
+
+ @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, this);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}