Commits
md_5 authored 6ff5a64c25f
7 7 | +// CraftBukkit start |
8 8 | +import org.bukkit.craftbukkit.event.CraftEventFactory; |
9 9 | +import org.bukkit.craftbukkit.inventory.CraftItemStack; |
10 10 | +import org.bukkit.craftbukkit.util.DummyGeneratorAccess; |
11 11 | +import org.bukkit.event.player.PlayerBucketEmptyEvent; |
12 12 | +import org.bukkit.event.player.PlayerBucketFillEvent; |
13 13 | +// CraftBukkit end |
14 14 | |
15 15 | public class ItemBucket extends Item { |
16 16 | |
17 - | |
17 + | |
18 18 | if (this.fluidType == FluidTypes.a) { |
19 19 | iblockdata = world.getType(blockposition); |
20 20 | if (iblockdata.getBlock() instanceof IFluidSource) { |
21 21 | + // CraftBukkit start |
22 22 | + FluidType dummyFluid = ((IFluidSource) iblockdata.getBlock()).a(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); |
23 23 | + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, dummyFluid.b()); |
24 24 | + |
25 25 | + if (event.isCancelled()) { |
26 + | + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 |
26 27 | + return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); |
27 28 | + } |
28 29 | + // CraftBukkit end |
29 30 | FluidType fluidtype = ((IFluidSource) iblockdata.getBlock()).a(world, blockposition, iblockdata); |
30 31 | |
31 32 | if (fluidtype != FluidTypes.a) { |
32 33 | entityhuman.b(StatisticList.ITEM_USED.b(this)); |
33 34 | entityhuman.a(fluidtype.a(TagsFluid.LAVA) ? SoundEffects.ITEM_BUCKET_FILL_LAVA : SoundEffects.ITEM_BUCKET_FILL, 1.0F, 1.0F); |
34 35 | - ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b()); |
35 36 | + ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b(), event.getItemStack()); // CraftBukkit |
36 37 | |
37 38 | if (!world.isClientSide) { |
38 39 | CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.b())); |
39 - | |
40 + | |
40 41 | iblockdata = world.getType(blockposition); |
41 42 | BlockPosition blockposition1 = this.a(iblockdata, blockposition, movingobjectposition); |
42 43 | |
43 44 | - if (this.a(entityhuman, world, blockposition1, movingobjectposition)) { |
44 45 | + if (this.a(entityhuman, world, blockposition1, movingobjectposition, movingobjectposition.direction, blockposition, itemstack)) { // CraftBukkit |
45 46 | this.a(world, itemstack, blockposition1); |
46 47 | if (entityhuman instanceof EntityPlayer) { |
47 48 | CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition1, itemstack); |
48 - | |
49 + | |
49 50 | |
50 51 | public void a(World world, ItemStack itemstack, BlockPosition blockposition) {} |
51 52 | |
52 53 | - private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item) { |
53 54 | + // CraftBukkit - added ob.ItemStack result - TODO: Is this... the right way to handle this? |
54 55 | + private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item, org.bukkit.inventory.ItemStack result) { |
55 56 | if (entityhuman.abilities.canInstantlyBuild) { |
56 57 | return itemstack; |
57 58 | } else { |
58 59 | itemstack.subtract(1); |
62 63 | + return CraftItemStack.asNMSCopy(result); |
63 64 | } else { |
64 65 | - if (!entityhuman.inventory.pickup(new ItemStack(item))) { |
65 66 | - entityhuman.drop(new ItemStack(item), false); |
66 67 | + if (!entityhuman.inventory.pickup(CraftItemStack.asNMSCopy(result))) { |
67 68 | + entityhuman.drop(CraftItemStack.asNMSCopy(result), false); |
68 69 | + // CraftBukkit end |
69 70 | } |
70 71 | |
71 72 | return itemstack; |
72 - | |
73 + | |
73 74 | } |
74 75 | } |
75 76 | |
76 77 | + // CraftBukkit start |
77 78 | public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition) { |
78 79 | + return a(entityhuman, world, blockposition, movingobjectposition, null, null, null); |
79 80 | + } |
80 81 | + |
81 82 | + public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) { |
82 83 | + // CraftBukkit end |
83 84 | if (!(this.fluidType instanceof FluidTypeFlowing)) { |
84 85 | return false; |
85 86 | } else { |
86 - | |
87 + | |
87 88 | boolean flag1 = material.isReplaceable(); |
88 89 | |
89 90 | if (!world.isEmpty(blockposition) && !flag && !flag1 && (!(iblockdata.getBlock() instanceof IFluidContainer) || !((IFluidContainer) iblockdata.getBlock()).canPlace(world, blockposition, iblockdata, this.fluidType))) { |
90 91 | - return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.getBlockPosition().shift(movingobjectposition.direction), (MovingObjectPosition) null); |
91 92 | + return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.getBlockPosition().shift(movingobjectposition.direction), (MovingObjectPosition) null, enumdirection, clicked, itemstack); // CraftBukkit |
92 93 | } else { |
93 94 | + // CraftBukkit start |
94 95 | + if (entityhuman != null) { |
95 96 | + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clicked.getX(), clicked.getY(), clicked.getZ(), enumdirection, itemstack); |
96 97 | + if (event.isCancelled()) { |
97 98 | + ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity |
98 - | + // TODO: inventory not updated |
99 + | + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 |
99 100 | + return false; |
100 101 | + } |
101 102 | + } |
102 103 | + // CraftBukkit end |
103 104 | if (world.worldProvider.isNether() && this.fluidType.a(TagsFluid.WATER)) { |
104 105 | int i = blockposition.getX(); |
105 106 | int j = blockposition.getY(); |