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

95 Zeilen
3.7 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ContainerAnvil.java
+++ b/net/minecraft/server/ContainerAnvil.java
2016-05-10 13:47:39 +02:00
@@ -7,6 +7,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.PrepareAnvilEvent;
+// CraftBukkit end
+
public class ContainerAnvil extends Container {
private static final Logger f = LogManager.getLogger();
2016-05-10 13:47:39 +02:00
@@ -23,8 +29,13 @@
private int k;
private String l;
private final EntityHuman m;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ 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;
2016-05-10 13:47:39 +02:00
@@ -110,7 +121,7 @@
2016-02-29 22:32:46 +01:00
byte b1 = 0;
if (itemstack == null) {
- this.g.setItem(0, (ItemStack) null);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), null); // CraftBukkit
this.a = 0;
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
2016-05-10 13:47:39 +02:00
@@ -128,7 +139,7 @@
2016-02-29 22:32:46 +01:00
if (itemstack1.e() && itemstack1.getItem().a(itemstack, itemstack2)) {
k = Math.min(itemstack1.h(), itemstack1.j() / 4);
if (k <= 0) {
- this.g.setItem(0, (ItemStack) null);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), null); // CraftBukkit
this.a = 0;
return;
}
2016-05-10 13:47:39 +02:00
@@ -143,7 +154,7 @@
2016-02-29 22:32:46 +01:00
this.k = l;
} else {
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.e())) {
- this.g.setItem(0, (ItemStack) null);
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), null); // CraftBukkit
this.a = 0;
return;
}
2016-05-10 13:47:39 +02:00
@@ -270,7 +281,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();
}
}
2016-05-10 13:47:39 +02:00
@@ -295,6 +306,7 @@
}
public boolean a(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.i.getType(this.j).getBlock() != Blocks.ANVIL ? false : entityhuman.e((double) this.j.getX() + 0.5D, (double) this.j.getY() + 0.5D, (double) this.j.getZ() + 0.5D) <= 64.0D;
}
2016-05-10 13:47:39 +02:00
@@ -352,6 +364,20 @@
2015-02-26 23:41:06 +01:00
this.e();
}
2016-02-29 22:32:46 +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(
+ new org.bukkit.Location(i.getWorld(), j.getX(), j.getY(), j.getZ()), this.h, this.g);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
+
static class SyntheticClass_1 {
static final int[] a = new int[Enchantment.Rarity.values().length];