3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/nms-patches/ContainerAnvil.patch

103 Zeilen
4.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ContainerAnvil.java
+++ b/net/minecraft/server/ContainerAnvil.java
2020-06-25 02:00:00 +02:00
@@ -6,12 +6,20 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-11-17 02:41:03 +01:00
+// CraftBukkit start
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public class ContainerAnvil extends ContainerAnvilAbstract {
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2019-04-23 04:00:00 +02:00
private int h;
2017-05-14 04:00:00 +02:00
public String renameText;
2020-06-25 02:00:00 +02:00
public final ContainerProperty levelCost;
+ // CraftBukkit start
+ public int maximumRepairCost = 40;
2016-11-17 02:41:03 +01:00
+ private CraftInventoryView bukkitEntity;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
public ContainerAnvil(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a);
2020-06-25 02:00:00 +02:00
@@ -85,7 +93,7 @@
2016-02-29 22:32:46 +01:00
byte b1 = 0;
2016-11-17 02:41:03 +01:00
if (itemstack.isEmpty()) {
2020-06-25 02:00:00 +02:00
- this.resultInventory.setItem(0, ItemStack.b);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
2019-07-20 01:00:00 +02:00
this.levelCost.set(0);
2016-02-29 22:32:46 +01:00
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
2020-06-25 02:00:00 +02:00
@@ -103,7 +111,7 @@
2018-07-15 02:00:00 +02:00
if (itemstack1.e() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.getDamage(), itemstack1.h() / 4);
2016-02-29 22:32:46 +01:00
if (k <= 0) {
2020-06-25 02:00:00 +02:00
- this.resultInventory.setItem(0, ItemStack.b);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
2019-07-20 01:00:00 +02:00
this.levelCost.set(0);
2016-02-29 22:32:46 +01:00
return;
}
2020-06-25 02:00:00 +02:00
@@ -118,7 +126,7 @@
2019-04-23 04:00:00 +02:00
this.h = i1;
2016-02-29 22:32:46 +01:00
} else {
2018-07-15 02:00:00 +02:00
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.e())) {
2020-06-25 02:00:00 +02:00
- this.resultInventory.setItem(0, ItemStack.b);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
2019-07-20 01:00:00 +02:00
this.levelCost.set(0);
return;
}
2020-06-25 02:00:00 +02:00
@@ -208,7 +216,7 @@
}
if (flag2 && !flag1) {
2020-06-25 02:00:00 +02:00
- this.resultInventory.setItem(0, ItemStack.b);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
2019-07-20 01:00:00 +02:00
this.levelCost.set(0);
2016-02-29 22:32:46 +01:00
return;
}
2020-06-25 02:00:00 +02:00
@@ -232,11 +240,11 @@
itemstack1 = ItemStack.b;
}
2019-07-20 01:00:00 +02:00
- if (b1 == i && b1 > 0 && this.levelCost.get() >= 40) {
- this.levelCost.set(39);
+ if (b1 == i && b1 > 0 && this.levelCost.get() >= maximumRepairCost) { // CraftBukkit
+ this.levelCost.set(maximumRepairCost - 1); // CraftBukkit
}
2019-07-20 01:00:00 +02:00
- if (this.levelCost.get() >= 40 && !this.player.abilities.canInstantlyBuild) {
+ if (this.levelCost.get() >= maximumRepairCost && !this.player.abilities.canInstantlyBuild) { // CraftBukkit
2020-06-25 02:00:00 +02:00
itemstack1 = ItemStack.b;
}
2020-06-25 02:00:00 +02:00
@@ -255,7 +263,7 @@
2016-02-29 22:32:46 +01:00
EnchantmentManager.a(map, itemstack1);
}
2018-12-13 01:00:00 +01:00
- this.resultInventory.setItem(0, itemstack1);
2016-02-29 22:32:46 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.c();
2016-02-29 22:32:46 +01:00
}
}
2020-06-25 02:00:00 +02:00
@@ -278,4 +286,18 @@
2019-04-23 04:00:00 +02:00
this.e();
}
2016-11-17 02:41:03 +01:00
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
2016-02-29 22:32:46 +01:00
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(
2019-04-23 04:00:00 +02:00
+ containerAccess.getLocation(), this.repairInventory, this.resultInventory, this);
2018-12-13 01:00:00 +01:00
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
}