summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemBucket.patch
blob: 5e131a07a92cb17d1108edffcd889c9fcdf88e50 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--- a/net/minecraft/server/ItemBucket.java
+++ b/net/minecraft/server/ItemBucket.java
@@ -1,6 +1,13 @@
 package net.minecraft.server;
 
 import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
 
 public class ItemBucket extends Item {
 
@@ -28,12 +35,20 @@
                 if (this.a == FluidTypes.a) {
                     iblockdata = world.getType(blockposition);
                     if (iblockdata.getBlock() instanceof IFluidSource) {
+                        // CraftBukkit start
+                        FluidType dummyFluid = ((IFluidSource) iblockdata.getBlock()).b(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
+                        PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, dummyFluid.b());
+
+                        if (event.isCancelled()) {
+                            return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+                        }
+                        // CraftBukkit end
                         FluidType fluidtype = ((IFluidSource) iblockdata.getBlock()).b(world, blockposition, iblockdata);
 
                         if (fluidtype != FluidTypes.a) {
                             entityhuman.b(StatisticList.ITEM_USED.b(this));
                             entityhuman.a(fluidtype.a(TagsFluid.b) ? SoundEffects.ITEM_BUCKET_FILL_LAVA : SoundEffects.ITEM_BUCKET_FILL, 1.0F, 1.0F);
-                            ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b());
+                            ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b(), event.getItemStack()); // CraftBukkit
 
                             if (!world.isClientSide) {
                                 CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.b()));
@@ -48,7 +63,7 @@
                     iblockdata = world.getType(blockposition);
                     BlockPosition blockposition1 = this.a(iblockdata, blockposition, movingobjectposition);
 
-                    if (this.a(entityhuman, world, blockposition1, movingobjectposition)) {
+                    if (this.a(entityhuman, world, blockposition1, movingobjectposition, movingobjectposition.direction, blockposition, itemstack)) { // CraftBukkit
                         this.a(world, itemstack, blockposition1);
                         if (entityhuman instanceof EntityPlayer) {
                             CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition1, itemstack);
@@ -76,16 +91,19 @@
 
     public void a(World world, ItemStack itemstack, BlockPosition blockposition) {}
 
-    private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item) {
+    // CraftBukkit - added ob.ItemStack result - TODO: Is this... the right way to handle this?
+    private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item, org.bukkit.inventory.ItemStack result) {
         if (entityhuman.abilities.canInstantlyBuild) {
             return itemstack;
         } else {
             itemstack.subtract(1);
             if (itemstack.isEmpty()) {
-                return new ItemStack(item);
+                // CraftBukkit start
+                return CraftItemStack.asNMSCopy(result);
             } else {
-                if (!entityhuman.inventory.pickup(new ItemStack(item))) {
-                    entityhuman.drop(new ItemStack(item), false);
+                if (!entityhuman.inventory.pickup(CraftItemStack.asNMSCopy(result))) {
+                    entityhuman.drop(CraftItemStack.asNMSCopy(result), false);
+                    // CraftBukkit end
                 }
 
                 return itemstack;
@@ -93,7 +111,13 @@
         }
     }
 
+    // CraftBukkit start
     public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition) {
+        return a(entityhuman, world, blockposition, movingobjectposition, null, null, null);
+    }
+
+    public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
+        // CraftBukkit end
         if (!(this.a instanceof FluidTypeFlowing)) {
             return false;
         } else {
@@ -103,8 +127,17 @@
             boolean flag1 = material.isReplaceable();
 
             if (!world.isEmpty(blockposition) && !flag && !flag1 && (!(iblockdata.getBlock() instanceof IFluidContainer) || !((IFluidContainer) iblockdata.getBlock()).a((IBlockAccess) world, blockposition, iblockdata, this.a))) {
-                return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.a().shift(movingobjectposition.direction), (MovingObjectPosition) null);
+                return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.a().shift(movingobjectposition.direction), (MovingObjectPosition) null, enumdirection, clicked, itemstack); // CraftBukkit
             } else {
+                // CraftBukkit start
+                if (entityhuman != null) {
+                    PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clicked.getX(), clicked.getY(), clicked.getZ(), enumdirection, itemstack);
+                    if (event.isCancelled()) {
+                        // TODO: inventory not updated
+                        return false;
+                    }
+                }
+                // CraftBukkit end
                 if (world.worldProvider.isNether() && this.a.a(TagsFluid.a)) {
                     int i = blockposition.getX();
                     int j = blockposition.getY();