Paper/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch
CraftBukkit/Spigot b3a8254758 Update to Minecraft 1.17
By: md_5 <git@md-5.net>
2021-06-11 15:00:00 +10:00

104 lines
4.2 KiB
Diff

--- a/net/minecraft/world/inventory/ContainerAnvil.java
+++ b/net/minecraft/world/inventory/ContainerAnvil.java
@@ -19,6 +19,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 ContainerAnvilAbstract {
private static final Logger LOGGER = LogManager.getLogger();
@@ -34,6 +38,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);
@@ -107,7 +115,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.cloneItemStack();
@@ -125,7 +133,7 @@
if (itemstack1.f() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.getDamage(), itemstack1.i() / 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;
}
@@ -140,7 +148,7 @@
this.repairItemCountCost = i1;
} else {
if (!flag && (!itemstack1.a(itemstack2.getItem()) || !itemstack1.f())) {
- this.resultSlots.setItem(0, ItemStack.EMPTY);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit
this.cost.set(0);
return;
}
@@ -230,7 +238,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;
}
@@ -254,11 +262,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;
}
@@ -277,7 +285,7 @@
EnchantmentManager.a(map, itemstack1);
}
- this.resultSlots.setItem(0, itemstack1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
this.d();
}
}
@@ -304,4 +312,18 @@
public int j() {
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
}