13
0
geforkt von Mirrors/Paper
Paper/nms-patches/ItemBucket.patch

79 Zeilen
5.3 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ItemBucket.java
+++ b/net/minecraft/server/ItemBucket.java
2018-08-26 04:00:00 +02:00
@@ -1,6 +1,13 @@
package net.minecraft.server;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+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;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
2016-05-10 13:47:39 +02:00
public class ItemBucket extends Item {
2019-12-10 23:00:00 +01:00
@@ -32,12 +39,22 @@
2018-12-25 22:00:00 +01:00
if (this.fluidType == FluidTypes.EMPTY) {
2018-07-15 02:00:00 +02:00
iblockdata = world.getType(blockposition);
if (iblockdata.getBlock() instanceof IFluidSource) {
+ // CraftBukkit start
2018-12-25 22:00:00 +01:00
+ FluidType dummyFluid = ((IFluidSource) iblockdata.getBlock()).removeFluid(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
2020-06-25 02:00:00 +02:00
+ 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
2016-02-29 22:32:46 +01:00
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ }
+ // CraftBukkit end
2018-12-25 22:00:00 +01:00
FluidType fluidtype = ((IFluidSource) iblockdata.getBlock()).removeFluid(world, blockposition, iblockdata);
2018-12-25 22:00:00 +01:00
if (fluidtype != FluidTypes.EMPTY) {
2018-07-15 02:00:00 +02:00
entityhuman.b(StatisticList.ITEM_USED.b(this));
2020-06-25 02:00:00 +02:00
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
2018-07-15 02:00:00 +02:00
if (!world.isClientSide) {
2019-12-10 23:00:00 +01:00
CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.a()));
@@ -52,7 +69,7 @@
2018-07-15 02:00:00 +02:00
iblockdata = world.getType(blockposition);
2019-12-10 23:00:00 +01:00
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.fluidType == FluidTypes.WATER ? blockposition : blockposition1;
2018-07-15 02:00:00 +02:00
2020-06-25 02:00:00 +02:00
- if (this.a(entityhuman, world, blockposition2, movingobjectpositionblock1)) {
+ if (this.a(entityhuman, world, blockposition2, movingobjectpositionblock1, movingobjectpositionblock1.getDirection(), blockposition, itemstack)) { // CraftBukkit
2019-12-10 23:00:00 +01:00
this.a(world, itemstack, blockposition2);
2018-07-15 02:00:00 +02:00
if (entityhuman instanceof EntityPlayer) {
2019-12-10 23:00:00 +01:00
CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition2, itemstack);
2020-06-25 02:00:00 +02:00
@@ -77,6 +94,11 @@
2018-07-15 02:00:00 +02:00
public void a(World world, ItemStack itemstack, BlockPosition blockposition) {}
2015-02-26 23:41:06 +01:00
2019-04-23 04:00:00 +02:00
public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
+ return a(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null);
2016-02-29 22:32:46 +01:00
+ }
+
2019-04-23 04:00:00 +02:00
+ public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
if (!(this.fluidType instanceof FluidTypeFlowing)) {
2016-02-29 22:32:46 +01:00
return false;
} else {
2020-06-25 02:00:00 +02:00
@@ -86,6 +108,16 @@
2019-12-10 23:00:00 +01:00
boolean flag = iblockdata.a(this.fluidType);
2020-06-25 02:00:00 +02:00
boolean flag1 = iblockdata.isAir() || flag || block instanceof IFluidContainer && ((IFluidContainer) block).canPlace(world, blockposition, iblockdata, this.fluidType);
2020-06-25 02:00:00 +02:00
+ // 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;
2016-02-29 22:32:46 +01:00
+ }
2020-06-25 02:00:00 +02:00
+ }
+ // CraftBukkit end
if (!flag1) {
return movingobjectpositionblock != null && this.a(entityhuman, world, movingobjectpositionblock.getBlockPosition().shift(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
} else if (world.getDimensionManager().isNether() && this.fluidType.a((Tag) TagsFluid.WATER)) {