summaryrefslogtreecommitdiffstats
path: root/nms-patches/ContainerAnvil.patch
blob: f42c2945b37a6117c2b75f39e53ad872a446a72c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--- 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,13 @@
     private int k;
     private String l;
     private final EntityHuman m;
+    // CraftBukkit start
+    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;
@@ -110,7 +119,7 @@
         byte b1 = 0;
 
         if (itemstack.isEmpty()) {
-            this.g.setItem(0, ItemStack.a);
+            org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
             this.a = 0;
         } else {
             ItemStack itemstack1 = itemstack.cloneItemStack();
@@ -128,7 +137,7 @@
                 if (itemstack1.f() && itemstack1.getItem().a(itemstack, itemstack2)) {
                     k = Math.min(itemstack1.i(), itemstack1.k() / 4);
                     if (k <= 0) {
-                        this.g.setItem(0, ItemStack.a);
+                        org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
                         this.a = 0;
                         return;
                     }
@@ -143,7 +152,7 @@
                     this.k = l;
                 } else {
                     if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.f())) {
-                        this.g.setItem(0, ItemStack.a);
+                        org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a); // CraftBukkit
                         this.a = 0;
                         return;
                     }
@@ -270,7 +279,7 @@
                 EnchantmentManager.a(map, itemstack1);
             }
 
-            this.g.setItem(0, itemstack1);
+            org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
             this.b();
         }
     }
@@ -295,6 +304,7 @@
     }
 
     public boolean a(EntityHuman entityhuman) {
+        if (!this.checkReachable) return true; // CraftBukkit
         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;
     }
 
@@ -350,4 +360,18 @@
 
         this.e();
     }
+
+    // CraftBukkit start
+    @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);
+        bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+        return bukkitEntity;
+    }
+    // CraftBukkit end
 }