craftbukkit/nms-patches/net/minecraft/world/item/ItemBucket.patch

95 lines
6.1 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/item/ItemBucket.java
+++ b/net/minecraft/world/item/ItemBucket.java
2024-04-24 01:15:00 +10:00
@@ -30,6 +30,16 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.MovingObjectPosition;
import net.minecraft.world.phys.MovingObjectPositionBlock;
2021-03-09 08:47:33 +11:00
+// CraftBukkit start
2021-03-16 09:00:00 +11:00
+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;
2018-07-15 10:00:00 +10:00
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
2021-03-09 08:47:33 +11:00
+
2021-06-11 15:00:00 +10:00
public class ItemBucket extends Item implements DispensibleContainerItem {
2021-06-11 15:00:00 +10:00
public final FluidType content;
2025-03-26 03:05:00 +11:00
@@ -60,6 +70,17 @@
2023-09-22 02:40:00 +10:00
if (block instanceof IFluidSource) {
IFluidSource ifluidsource = (IFluidSource) block;
+ // CraftBukkit start
2023-09-22 02:40:00 +10:00
+ ItemStack dummyFluid = ifluidsource.pickupBlock(entityhuman, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
2024-10-23 02:15:00 +11:00
+ 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()) {
2021-11-22 09:00:00 +11:00
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
2024-10-23 02:15:00 +11:00
+ return EnumInteractionResult.FAIL;
+ }
+ // CraftBukkit end
2025-03-26 03:05:00 +11:00
ItemStack itemstack1 = ifluidsource.pickupBlock(entityhuman, world, blockposition, iblockdata);
2021-06-11 15:00:00 +10:00
if (!itemstack1.isEmpty()) {
2025-03-26 03:05:00 +11:00
@@ -68,7 +89,7 @@
2021-06-11 15:00:00 +10:00
entityhuman.playSound(soundeffect, 1.0F, 1.0F);
});
2025-03-26 03:05:00 +11:00
world.gameEvent(entityhuman, (Holder) GameEvent.FLUID_PICKUP, blockposition);
2021-11-22 09:00:00 +11:00
- ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1);
+ ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
2018-07-15 10:00:00 +10:00
if (!world.isClientSide) {
2021-11-22 09:00:00 +11:00
CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1);
2025-03-26 03:05:00 +11:00
@@ -83,7 +104,7 @@
IBlockData iblockdata1 = world.getBlockState(blockposition);
BlockPosition blockposition2 = iblockdata1.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1;
2018-07-15 10:00:00 +10:00
2021-11-22 09:00:00 +11:00
- if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock)) {
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, enumhand)) { // CraftBukkit
2021-11-22 09:00:00 +11:00
this.checkExtraContent(entityhuman, world, itemstack, blockposition2);
2018-07-15 10:00:00 +10:00
if (entityhuman instanceof EntityPlayer) {
2021-11-22 09:00:00 +11:00
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack);
2025-03-26 03:05:00 +11:00
@@ -112,11 +133,18 @@
2015-02-26 22:41:06 +00:00
2021-06-11 15:00:00 +10:00
@Override
2025-03-26 03:05:00 +11:00
public boolean emptyContents(@Nullable EntityLiving entityliving, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
+ // CraftBukkit start
2025-03-26 03:05:00 +11:00
+ return emptyContents(entityliving, world, blockposition, movingobjectpositionblock, null, null, null, EnumHand.MAIN_HAND);
2016-03-01 08:32:46 +11:00
+ }
+
2025-03-26 03:05:00 +11:00
+ public boolean emptyContents(@Nullable EntityLiving entityliving, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack, EnumHand enumhand) {
2016-03-01 08:32:46 +11:00
+ // CraftBukkit end
2023-09-22 02:40:00 +10:00
FluidType fluidtype = this.content;
2024-04-24 01:15:00 +10:00
if (!(fluidtype instanceof FluidTypeFlowing fluidtypeflowing)) {
2025-03-26 03:05:00 +11:00
return false;
} else {
+ IBlockData iblockdata; // CraftBukkit - decompile error
Block block;
boolean flag;
boolean flag1;
@@ -146,8 +174,18 @@
2023-09-22 02:40:00 +10:00
boolean flag2 = flag1;
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start
2025-03-26 03:05:00 +11:00
+ if (flag2 && entityliving instanceof EntityPlayer entityplayer) {
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityplayer, blockposition, clicked, enumdirection, itemstack, enumhand);
2020-06-25 10:00:00 +10:00
+ if (event.isCancelled()) {
2025-03-26 03:05:00 +11:00
+ entityplayer.connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
+ entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-4541
2020-06-25 10:00:00 +10:00
+ return false;
2016-03-01 08:32:46 +11:00
+ }
2020-06-25 10:00:00 +10:00
+ }
+ // CraftBukkit end
2023-09-22 02:40:00 +10:00
if (!flag2) {
2025-03-26 03:05:00 +11:00
- return movingobjectpositionblock != null && this.emptyContents(entityliving, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
+ return movingobjectpositionblock != null && this.emptyContents(entityliving, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
2021-11-22 09:00:00 +11:00
} else if (world.dimensionType().ultraWarm() && this.content.is(TagsFluid.WATER)) {
int i = blockposition.getX();
int j = blockposition.getY();