2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/item/ItemBucket.java
|
|
|
|
+++ b/net/minecraft/world/item/ItemBucket.java
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -30,6 +30,16 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
2021-03-08 22:47:33 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+// CraftBukkit start
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
|
|
|
|
+import net.minecraft.server.level.WorldServer;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2018-07-15 02:00:00 +02:00
|
|
|
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
|
|
|
+import org.bukkit.event.player.PlayerBucketFillEvent;
|
|
|
|
+// CraftBukkit end
|
2021-03-08 22:47:33 +01:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
public class ItemBucket extends Item implements DispensibleContainerItem {
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
public final FluidType content;
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -62,6 +72,17 @@
|
2023-09-21 18:40:00 +02:00
|
|
|
|
|
|
|
if (block instanceof IFluidSource) {
|
|
|
|
IFluidSource ifluidsource = (IFluidSource) block;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2023-09-21 18:40:00 +02:00
|
|
|
+ ItemStack dummyFluid = ifluidsource.pickupBlock(entityhuman, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
|
2021-08-18 09:06:40 +02:00
|
|
|
+ if (dummyFluid.isEmpty()) return InteractionResultWrapper.fail(itemstack); // Don't fire event if the bucket won't be filled.
|
2022-10-02 00:07:14 +02:00
|
|
|
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), enumhand);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (event.isCancelled()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
|
2018-12-22 00:12:16 +01:00
|
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
2021-03-15 23:00:00 +01:00
|
|
|
+ return InteractionResultWrapper.fail(itemstack);
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2023-09-21 18:40:00 +02:00
|
|
|
ItemStack itemstack1 = ifluidsource.pickupBlock(entityhuman, world, blockposition, iblockdata);
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!itemstack1.isEmpty()) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -70,7 +91,7 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
entityhuman.playSound(soundeffect, 1.0F, 1.0F);
|
|
|
|
});
|
2024-04-23 17:15:00 +02:00
|
|
|
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.FLUID_PICKUP, blockposition);
|
2021-11-21 23:00:00 +01:00
|
|
|
- ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1);
|
|
|
|
+ ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
2018-07-15 02:00:00 +02:00
|
|
|
|
|
|
|
if (!world.isClientSide) {
|
2021-11-21 23:00:00 +01:00
|
|
|
CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -85,7 +106,7 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
iblockdata = world.getBlockState(blockposition);
|
2021-06-11 07:00:00 +02:00
|
|
|
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1;
|
2018-07-15 02:00:00 +02:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock)) {
|
2022-10-02 00:07:14 +02:00
|
|
|
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, enumhand)) { // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
this.checkExtraContent(entityhuman, world, itemstack, blockposition2);
|
2018-07-15 02:00:00 +02:00
|
|
|
if (entityhuman instanceof EntityPlayer) {
|
2021-11-21 23:00:00 +01:00
|
|
|
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -112,6 +133,12 @@
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
@Override
|
2021-11-21 23:00:00 +01:00
|
|
|
public boolean emptyContents(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
|
2022-10-02 00:07:14 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ return emptyContents(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null, EnumHand.MAIN_HAND);
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
|
|
|
+
|
2022-10-02 00:07:14 +02:00
|
|
|
+ public boolean emptyContents(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack, EnumHand enumhand) {
|
2016-02-29 22:32:46 +01:00
|
|
|
+ // CraftBukkit end
|
2023-09-21 18:40:00 +02:00
|
|
|
FluidType fluidtype = this.content;
|
|
|
|
|
2024-04-23 17:15:00 +02:00
|
|
|
if (!(fluidtype instanceof FluidTypeFlowing fluidtypeflowing)) {
|
|
|
|
@@ -147,8 +174,18 @@
|
2023-09-21 18:40:00 +02:00
|
|
|
|
|
|
|
boolean flag2 = flag1;
|
2018-07-18 09:48:17 +02:00
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
+ // CraftBukkit start
|
2023-09-21 18:40:00 +02:00
|
|
|
+ if (flag2 && entityhuman != null) {
|
2022-10-02 00:07:14 +02:00
|
|
|
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand);
|
2020-06-25 02:00:00 +02:00
|
|
|
+ if (event.isCancelled()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
|
2020-06-25 02:00:00 +02:00
|
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
|
|
|
+ return false;
|
2016-02-29 22:32:46 +01:00
|
|
|
+ }
|
2020-06-25 02:00:00 +02:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2023-09-21 18:40:00 +02:00
|
|
|
if (!flag2) {
|
2021-11-21 23:00:00 +01:00
|
|
|
- return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
|
2022-10-02 00:07:14 +02:00
|
|
|
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
} else if (world.dimensionType().ultraWarm() && this.content.is(TagsFluid.WATER)) {
|
2020-06-29 03:09:50 +02:00
|
|
|
int i = blockposition.getX();
|
|
|
|
int j = blockposition.getY();
|