diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/item/BucketItem.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/item/BucketItem.java.patch | 275 |
1 files changed, 275 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/item/BucketItem.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/item/BucketItem.java.patch new file mode 100644 index 0000000000..59d28174e7 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/item/BucketItem.java.patch @@ -0,0 +1,275 @@ +--- a/net/minecraft/world/item/BucketItem.java ++++ b/net/minecraft/world/item/BucketItem.java +@@ -5,13 +5,15 @@ + import net.minecraft.core.BlockPos; + import net.minecraft.core.Direction; + import net.minecraft.core.particles.ParticleTypes; ++import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; ++import net.minecraft.server.level.ServerLevel; + import net.minecraft.server.level.ServerPlayer; + import net.minecraft.sounds.SoundEvent; + import net.minecraft.sounds.SoundEvents; + import net.minecraft.sounds.SoundSource; + import net.minecraft.stats.Stats; + import net.minecraft.tags.FluidTags; +-import net.minecraft.world.InteractionHand; ++import net.minecraft.world.EnumHand; + import net.minecraft.world.InteractionResultHolder; + import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.player.Player; +@@ -21,56 +23,72 @@ + import net.minecraft.world.level.block.Block; + import net.minecraft.world.level.block.BucketPickup; + import net.minecraft.world.level.block.LiquidBlockContainer; +-import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.level.material.FlowingFluid; + import net.minecraft.world.level.material.Fluid; + import net.minecraft.world.level.material.Fluids; + import net.minecraft.world.phys.BlockHitResult; + import net.minecraft.world.phys.HitResult; ++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 BucketItem extends Item implements DispensibleContainerItem { + +- private final Fluid content; ++ public final Fluid content; + +- public BucketItem(Fluid fluid, Item.Properties item_properties) { +- super(item_properties); +- this.content = fluid; ++ public BucketItem(Fluid content, Item.Properties properties) { ++ super(properties); ++ this.content = content; + } + + @Override +- @Override +- public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionhand) { +- ItemStack itemstack = player.getItemInHand(interactionhand); +- BlockHitResult blockhitresult = getPlayerPOVHitResult(level, player, this.content == Fluids.EMPTY ? ClipContext.Fluid.SOURCE_ONLY : ClipContext.Fluid.NONE); ++ public InteractionResultHolder<ItemStack> use(Level level, Player player, EnumHand hand) { ++ ItemStack itemstack = player.getItemInHand(hand); ++ BlockHitResult movingobjectpositionblock = getPlayerPOVHitResult(level, player, this.content == Fluids.EMPTY ? ClipContext.Fluid.SOURCE_ONLY : ClipContext.Fluid.NONE); + +- if (blockhitresult.getType() == HitResult.Type.MISS) { ++ if (movingobjectpositionblock.getType() == HitResult.EnumMovingObjectType.MISS) { + return InteractionResultHolder.pass(itemstack); +- } else if (blockhitresult.getType() != HitResult.Type.BLOCK) { ++ } else if (movingobjectpositionblock.getType() != HitResult.EnumMovingObjectType.BLOCK) { + return InteractionResultHolder.pass(itemstack); + } else { +- BlockPos blockpos = blockhitresult.getBlockPos(); +- Direction direction = blockhitresult.getDirection(); +- BlockPos blockpos1 = blockpos.relative(direction); ++ BlockPos blockposition = movingobjectpositionblock.getBlockPos(); ++ Direction enumdirection = movingobjectpositionblock.getDirection(); ++ BlockPos blockposition1 = blockposition.relative(enumdirection); + +- if (level.mayInteract(player, blockpos) && player.mayUseItemAt(blockpos1, direction, itemstack)) { +- BlockState blockstate; ++ if (level.mayInteract(player, blockposition) && player.mayUseItemAt(blockposition1, enumdirection, itemstack)) { ++ IBlockData iblockdata; + + if (this.content == Fluids.EMPTY) { +- blockstate = level.getBlockState(blockpos); +- Block block = blockstate.getBlock(); ++ iblockdata = level.getBlockState(blockposition); ++ Block block = iblockdata.getBlock(); + + if (block instanceof BucketPickup) { +- BucketPickup bucketpickup = (BucketPickup) block; +- ItemStack itemstack1 = bucketpickup.pickupBlock(player, level, blockpos, blockstate); ++ BucketPickup ifluidsource = (BucketPickup) block; ++ // CraftBukkit start ++ ItemStack dummyFluid = ifluidsource.pickupBlock(player, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); ++ if (dummyFluid.isEmpty()) return InteractionResultHolder.fail(itemstack); // Don't fire event if the bucket won't be filled. ++ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) level, player, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), hand); + ++ if (event.isCancelled()) { ++ ((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(level, blockposition)); // SPIGOT-5163 (see PlayerInteractManager) ++ ((ServerPlayer) player).getBukkitEntity().updateInventory(); // SPIGOT-4541 ++ return InteractionResultHolder.fail(itemstack); ++ } ++ // CraftBukkit end ++ ItemStack itemstack1 = ifluidsource.pickupBlock(player, level, blockposition, iblockdata); ++ + if (!itemstack1.isEmpty()) { + player.awardStat(Stats.ITEM_USED.get(this)); +- bucketpickup.getPickupSound().ifPresent((soundevent) -> { +- player.playSound(soundevent, 1.0F, 1.0F); ++ ifluidsource.getPickupSound().ifPresent((soundeffect) -> { ++ player.playSound(soundeffect, 1.0F, 1.0F); + }); +- level.gameEvent((Entity) player, GameEvent.FLUID_PICKUP, blockpos); +- ItemStack itemstack2 = ItemUtils.createFilledResult(itemstack, player, itemstack1); ++ level.gameEvent((Entity) player, GameEvent.FLUID_PICKUP, blockposition); ++ ItemStack itemstack2 = ItemUtils.createFilledResult(itemstack, player, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit + + if (!level.isClientSide) { + CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer) player, itemstack1); +@@ -82,13 +100,13 @@ + + return InteractionResultHolder.fail(itemstack); + } else { +- blockstate = level.getBlockState(blockpos); +- BlockPos blockpos2 = blockstate.getBlock() instanceof LiquidBlockContainer && this.content == Fluids.WATER ? blockpos : blockpos1; ++ iblockdata = level.getBlockState(blockposition); ++ BlockPos blockposition2 = iblockdata.getBlock() instanceof LiquidBlockContainer && this.content == Fluids.WATER ? blockposition : blockposition1; + +- if (this.emptyContents(player, level, blockpos2, blockhitresult)) { +- this.checkExtraContent(player, level, itemstack, blockpos2); ++ if (this.emptyContents(player, level, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, hand)) { // CraftBukkit ++ this.checkExtraContent(player, level, itemstack, blockposition2); + if (player instanceof ServerPlayer) { +- CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) player, blockpos2, itemstack); ++ CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) player, blockposition2, itemstack); + } + + player.awardStat(Stats.ITEM_USED.get(this)); +@@ -103,40 +121,44 @@ + } + } + +- public static ItemStack getEmptySuccessItem(ItemStack itemstack, Player player) { +- return !player.getAbilities().instabuild ? new ItemStack(Items.BUCKET) : itemstack; ++ public static ItemStack getEmptySuccessItem(ItemStack bucketStack, Player player) { ++ return !player.getAbilities().instabuild ? new ItemStack(Items.BUCKET) : bucketStack; + } + + @Override +- @Override +- public void checkExtraContent(@Nullable Player player, Level level, ItemStack itemstack, BlockPos blockpos) {} ++ public void checkExtraContent(@Nullable Player player, Level level, ItemStack containerStack, BlockPos pos) {} + + @Override +- @Override +- public boolean emptyContents(@Nullable Player player, Level level, BlockPos blockpos, @Nullable BlockHitResult blockhitresult) { +- Fluid fluid = this.content; ++ public boolean emptyContents(@Nullable Player player, Level level, BlockPos pos, @Nullable BlockHitResult result) { ++ // CraftBukkit start ++ return emptyContents(player, level, pos, result, null, null, null, EnumHand.MAIN_HAND); ++ } + +- if (!(fluid instanceof FlowingFluid)) { ++ public boolean emptyContents(Player entityhuman, Level world, BlockPos blockposition, @Nullable BlockHitResult movingobjectpositionblock, Direction enumdirection, BlockPos clicked, ItemStack itemstack, EnumHand enumhand) { ++ // CraftBukkit end ++ Fluid fluidtype = this.content; ++ ++ if (!(fluidtype instanceof FlowingFluid)) { + return false; + } else { +- FlowingFluid flowingfluid; +- BlockState blockstate; ++ FlowingFluid fluidtypeflowing; ++ IBlockData iblockdata; + Block block; + boolean flag; +- LiquidBlockContainer liquidblockcontainer; ++ LiquidBlockContainer ifluidcontainer; + boolean flag1; + label70: + { +- flowingfluid = (FlowingFluid) fluid; +- blockstate = level.getBlockState(blockpos); +- block = blockstate.getBlock(); +- flag = blockstate.canBeReplaced(this.content); +- if (!blockstate.isAir() && !flag) { ++ fluidtypeflowing = (FlowingFluid) fluidtype; ++ iblockdata = world.getBlockState(blockposition); ++ block = iblockdata.getBlock(); ++ flag = iblockdata.canBeReplaced(this.content); ++ if (!iblockdata.isAir() && !flag) { + label67: + { + if (block instanceof LiquidBlockContainer) { +- liquidblockcontainer = (LiquidBlockContainer) block; +- if (liquidblockcontainer.canPlaceLiquid(player, level, blockpos, blockstate, this.content)) { ++ ifluidcontainer = (LiquidBlockContainer) block; ++ if (ifluidcontainer.canPlaceLiquid(entityhuman, world, blockposition, iblockdata, this.content)) { + break label67; + } + } +@@ -151,48 +173,58 @@ + + boolean flag2 = flag1; + ++ // CraftBukkit start ++ if (flag2 && entityhuman != null) { ++ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand); ++ if (event.isCancelled()) { ++ ((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-4238: needed when looking through entity ++ ((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 ++ return false; ++ } ++ } ++ // CraftBukkit end + if (!flag2) { +- return blockhitresult != null && this.emptyContents(player, level, blockhitresult.getBlockPos().relative(blockhitresult.getDirection()), (BlockHitResult) null); +- } else if (level.dimensionType().ultraWarm() && this.content.is(FluidTags.WATER)) { +- int i = blockpos.getX(); +- int j = blockpos.getY(); +- int k = blockpos.getZ(); ++ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (BlockHitResult) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit ++ } else if (world.dimensionType().ultraWarm() && this.content.is(FluidTags.WATER)) { ++ int i = blockposition.getX(); ++ int j = blockposition.getY(); ++ int k = blockposition.getZ(); + +- level.playSound(player, blockpos, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (level.random.nextFloat() - level.random.nextFloat()) * 0.8F); ++ world.playSound(entityhuman, blockposition, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F); + + for (int l = 0; l < 8; ++l) { +- level.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D); ++ world.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D); + } + + return true; + } else { + if (block instanceof LiquidBlockContainer) { +- liquidblockcontainer = (LiquidBlockContainer) block; ++ ifluidcontainer = (LiquidBlockContainer) block; + if (this.content == Fluids.WATER) { +- liquidblockcontainer.placeLiquid(level, blockpos, blockstate, flowingfluid.getSource(false)); +- this.playEmptySound(player, level, blockpos); ++ ifluidcontainer.placeLiquid(world, blockposition, iblockdata, fluidtypeflowing.getSource(false)); ++ this.playEmptySound(entityhuman, world, blockposition); + return true; + } + } + +- if (!level.isClientSide && flag && !blockstate.liquid()) { +- level.destroyBlock(blockpos, true); ++ if (!world.isClientSide && flag && !iblockdata.liquid()) { ++ world.destroyBlock(blockposition, true); + } + +- if (!level.setBlock(blockpos, this.content.defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) { ++ if (!world.setBlock(blockposition, this.content.defaultFluidState().createLegacyBlock(), 11) && !iblockdata.getFluidState().isSource()) { + return false; + } else { +- this.playEmptySound(player, level, blockpos); ++ this.playEmptySound(entityhuman, world, blockposition); + return true; + } + } + } + } + +- protected void playEmptySound(@Nullable Player player, LevelAccessor levelaccessor, BlockPos blockpos) { +- SoundEvent soundevent = this.content.is(FluidTags.LAVA) ? SoundEvents.BUCKET_EMPTY_LAVA : SoundEvents.BUCKET_EMPTY; ++ protected void playEmptySound(@Nullable Player player, LevelAccessor level, BlockPos pos) { ++ SoundEvent soundeffect = this.content.is(FluidTags.LAVA) ? SoundEvents.BUCKET_EMPTY_LAVA : SoundEvents.BUCKET_EMPTY; + +- levelaccessor.playSound(player, blockpos, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); +- levelaccessor.gameEvent((Entity) player, GameEvent.FLUID_PLACE, blockpos); ++ level.playSound(player, pos, soundeffect, SoundSource.BLOCKS, 1.0F, 1.0F); ++ level.gameEvent((Entity) player, GameEvent.FLUID_PLACE, pos); + } + } |