13
0
geforkt von Mirrors/Paper
Paper/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch
CraftBukkit/Spigot 9da047989c Repackage NMS
By: md_5 <git@md-5.net>
2021-03-16 09:00:00 +11:00

85 Zeilen
5.8 KiB
Diff

--- a/net/minecraft/world/item/ItemBucket.java
+++ b/net/minecraft/world/item/ItemBucket.java
@@ -29,6 +29,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 {
public final FluidType fluidType;
@@ -59,12 +69,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 InteractionResultWrapper.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()));
@@ -79,7 +99,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);
@@ -104,6 +124,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 {
@@ -113,8 +138,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();