Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/nms-patches/ContainerAnvil.patch

116 Zeilen
4.3 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ContainerAnvil.java
+++ b/net/minecraft/server/ContainerAnvil.java
2016-11-17 02:41:03 +01:00
@@ -6,6 +6,10 @@
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
+
public class ContainerAnvil extends Container {
private static final Logger f = LogManager.getLogger();
@@ -22,8 +26,14 @@
private int k;
2017-05-14 04:00:00 +02:00
public String renameText;
private final EntityHuman m;
+ // CraftBukkit start
+ private int lastLevelCost;
2016-11-17 02:41:03 +01:00
+ private CraftInventoryView bukkitEntity;
+ private PlayerInventory player;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
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;
@@ -110,7 +120,7 @@
2016-02-29 22:32:46 +01:00
byte b1 = 0;
2016-11-17 02:41:03 +01:00
if (itemstack.isEmpty()) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2017-05-14 04:00:00 +02:00
this.levelCost = 0;
2016-02-29 22:32:46 +01:00
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
@@ -128,7 +138,7 @@
2016-11-17 02:41:03 +01:00
if (itemstack1.f() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.i(), itemstack1.k() / 4);
2016-02-29 22:32:46 +01:00
if (k <= 0) {
2016-11-17 02:41:03 +01:00
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2017-05-14 04:00:00 +02:00
this.levelCost = 0;
2016-02-29 22:32:46 +01:00
return;
}
@@ -143,7 +153,7 @@
2016-02-29 22:32:46 +01:00
this.k = l;
} else {
2016-11-17 02:41:03 +01:00
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.f())) {
- this.g.setItem(0, ItemStack.a);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2017-05-14 04:00:00 +02:00
this.levelCost = 0;
return;
}
@@ -236,7 +246,7 @@
}
if (flag2 && !flag1) {
- this.g.setItem(0, ItemStack.a);
2016-11-17 02:41:03 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
2017-05-14 04:00:00 +02:00
this.levelCost = 0;
2016-02-29 22:32:46 +01:00
return;
}
@@ -283,7 +293,7 @@
2016-02-29 22:32:46 +01:00
EnchantmentManager.a(map, itemstack1);
}
- this.g.setItem(0, itemstack1);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
this.b();
}
}
@@ -301,6 +311,7 @@
}
2017-09-18 12:00:00 +02:00
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
2016-11-17 02:41:03 +01:00
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;
}
@@ -356,4 +367,33 @@
2016-11-17 02:41:03 +01:00
2015-02-26 23:41:06 +01:00
this.e();
}
2016-11-17 02:41:03 +01:00
+
+ // 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;
+ }
+
2016-02-29 22:32:46 +01:00
+ 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
2016-11-17 02:41:03 +01:00
}