Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-23 23:00:08 +01:00
82 Zeilen
5.7 KiB
Diff
82 Zeilen
5.7 KiB
Diff
--- 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 {
|
|
|
|
@@ -32,12 +39,22 @@
|
|
if (this.fluidType == FluidTypes.EMPTY) {
|
|
iblockdata = world.getType(blockposition);
|
|
if (iblockdata.getBlock() instanceof IFluidSource) {
|
|
+ // CraftBukkit start
|
|
+ FluidType dummyFluid = ((IFluidSource) iblockdata.getBlock()).removeFluid(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
|
|
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.a());
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
|
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
FluidType fluidtype = ((IFluidSource) iblockdata.getBlock()).removeFluid(world, blockposition, iblockdata);
|
|
|
|
if (fluidtype != FluidTypes.EMPTY) {
|
|
entityhuman.b(StatisticList.ITEM_USED.b(this));
|
|
entityhuman.playSound(fluidtype.a((Tag) TagsFluid.LAVA) ? SoundEffects.ITEM_BUCKET_FILL_LAVA : SoundEffects.ITEM_BUCKET_FILL, 1.0F, 1.0F);
|
|
- ItemStack itemstack1 = ItemLiquidUtil.a(itemstack, entityhuman, new ItemStack(fluidtype.a()));
|
|
+ ItemStack itemstack1 = ItemLiquidUtil.a(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
|
|
|
if (!world.isClientSide) {
|
|
CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.a()));
|
|
@@ -52,7 +69,7 @@
|
|
iblockdata = world.getType(blockposition);
|
|
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.fluidType == FluidTypes.WATER ? blockposition : blockposition1;
|
|
|
|
- if (this.a(entityhuman, world, blockposition2, movingobjectpositionblock1)) {
|
|
+ if (this.a(entityhuman, world, blockposition2, movingobjectpositionblock1, movingobjectpositionblock1.getDirection(), blockposition, itemstack)) { // CraftBukkit
|
|
this.a(world, itemstack, blockposition2);
|
|
if (entityhuman instanceof EntityPlayer) {
|
|
CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition2, itemstack);
|
|
@@ -77,6 +94,11 @@
|
|
public void a(World world, ItemStack itemstack, BlockPosition blockposition) {}
|
|
|
|
public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
|
|
+ return a(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null);
|
|
+ }
|
|
+
|
|
+ public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
|
|
+ // CraftBukkit end
|
|
if (!(this.fluidType instanceof FluidTypeFlowing)) {
|
|
return false;
|
|
} else {
|
|
@@ -86,8 +108,18 @@
|
|
boolean flag = iblockdata.a(this.fluidType);
|
|
boolean flag1 = iblockdata.isAir() || flag || block instanceof IFluidContainer && ((IFluidContainer) block).canPlace(world, blockposition, iblockdata, this.fluidType);
|
|
|
|
+ // CraftBukkit start
|
|
+ if (flag1 && entityhuman != null) {
|
|
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack);
|
|
+ if (event.isCancelled()) {
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (!flag1) {
|
|
- return movingobjectpositionblock != null && this.a(entityhuman, world, movingobjectpositionblock.getBlockPosition().shift(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
|
|
+ return movingobjectpositionblock != null && this.a(entityhuman, world, movingobjectpositionblock.getBlockPosition().shift(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack); // CraftBukkit
|
|
} else if (world.getDimensionManager().isNether() && this.fluidType.a((Tag) TagsFluid.WATER)) {
|
|
int i = blockposition.getX();
|
|
int j = blockposition.getY();
|