mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-25 03:26:14 +00:00
89 lines
5.9 KiB
Diff
89 lines
5.9 KiB
Diff
--- a/net/minecraft/world/item/ItemBucket.java
|
|
+++ b/net/minecraft/world/item/ItemBucket.java
|
|
@@ -30,6 +30,16 @@
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
|
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
|
|
+import net.minecraft.server.level.WorldServer;
|
|
+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 implements DispensibleContainerItem {
|
|
|
|
public final FluidType content;
|
|
@@ -63,6 +73,17 @@
|
|
|
|
if (block instanceof IFluidSource) {
|
|
IFluidSource ifluidsource = (IFluidSource) block;
|
|
+ // CraftBukkit start
|
|
+ ItemStack dummyFluid = ifluidsource.pickupBlock(entityhuman, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
|
|
+ if (dummyFluid.isEmpty()) return EnumInteractionResult.FAIL; // Don't fire event if the bucket won't be filled.
|
|
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), enumhand);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
|
+ return EnumInteractionResult.FAIL;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
itemstack1 = ifluidsource.pickupBlock(entityhuman, world, blockposition, iblockdata);
|
|
if (!itemstack1.isEmpty()) {
|
|
@@ -71,7 +92,7 @@
|
|
entityhuman.playSound(soundeffect, 1.0F, 1.0F);
|
|
});
|
|
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.FLUID_PICKUP, blockposition);
|
|
- ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1);
|
|
+ ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
|
|
|
if (!world.isClientSide) {
|
|
CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1);
|
|
@@ -86,7 +107,7 @@
|
|
iblockdata = world.getBlockState(blockposition);
|
|
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1;
|
|
|
|
- if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock)) {
|
|
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, enumhand)) { // CraftBukkit
|
|
this.checkExtraContent(entityhuman, world, itemstack, blockposition2);
|
|
if (entityhuman instanceof EntityPlayer) {
|
|
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack);
|
|
@@ -114,6 +135,12 @@
|
|
|
|
@Override
|
|
public boolean emptyContents(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
|
|
+ // CraftBukkit start
|
|
+ return emptyContents(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null, EnumHand.MAIN_HAND);
|
|
+ }
|
|
+
|
|
+ public boolean emptyContents(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack, EnumHand enumhand) {
|
|
+ // CraftBukkit end
|
|
FluidType fluidtype = this.content;
|
|
|
|
if (!(fluidtype instanceof FluidTypeFlowing fluidtypeflowing)) {
|
|
@@ -149,8 +176,18 @@
|
|
|
|
boolean flag2 = flag1;
|
|
|
|
+ // CraftBukkit start
|
|
+ if (flag2 && entityhuman != null) {
|
|
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand);
|
|
+ if (event.isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (!flag2) {
|
|
- return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
|
|
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
|
|
} else if (world.dimensionType().ultraWarm() && this.content.is(TagsFluid.WATER)) {
|
|
int i = blockposition.getX();
|
|
int j = blockposition.getY();
|