--- a/net/minecraft/world/level/block/BlockSponge.java +++ b/net/minecraft/world/level/block/BlockSponge.java @@ -13,6 +13,13 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Material; +// CraftBukkit start +import java.util.List; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.util.BlockStateListPopulator; +import org.bukkit.event.block.SpongeAbsorbEvent; +// CraftBukkit end + public class BlockSponge extends Block { public static final int MAX_DEPTH = 6; @@ -48,6 +55,7 @@ queue.add(new Tuple<>(blockposition, 0)); int i = 0; + BlockStateListPopulator blockList = new BlockStateListPopulator(world); // CraftBukkit - Use BlockStateListPopulator while (!queue.isEmpty()) { Tuple tuple = (Tuple) queue.poll(); @@ -59,27 +67,31 @@ for (int l = 0; l < k; ++l) { EnumDirection enumdirection = aenumdirection[l]; BlockPosition blockposition2 = blockposition1.relative(enumdirection); - IBlockData iblockdata = world.getBlockState(blockposition2); - Fluid fluid = world.getFluidState(blockposition2); + // CraftBukkit start + IBlockData iblockdata = blockList.getBlockState(blockposition2); + Fluid fluid = blockList.getFluidState(blockposition2); + // CraftBukkit end Material material = iblockdata.getMaterial(); if (fluid.is(TagsFluid.WATER)) { - if (iblockdata.getBlock() instanceof IFluidSource && !((IFluidSource) iblockdata.getBlock()).pickupBlock(world, blockposition2, iblockdata).isEmpty()) { + if (iblockdata.getBlock() instanceof IFluidSource && !((IFluidSource) iblockdata.getBlock()).pickupBlock(blockList, blockposition2, iblockdata).isEmpty()) { // CraftBukkit ++i; if (j < 6) { queue.add(new Tuple<>(blockposition2, j + 1)); } } else if (iblockdata.getBlock() instanceof BlockFluids) { - world.setBlock(blockposition2, Blocks.AIR.defaultBlockState(), 3); + blockList.setBlock(blockposition2, Blocks.AIR.defaultBlockState(), 3); // CraftBukkit ++i; if (j < 6) { queue.add(new Tuple<>(blockposition2, j + 1)); } } else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) { - TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition2) : null; + // CraftBukkit start + // TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition2) : null; - dropResources(iblockdata, world, blockposition2, tileentity); - world.setBlock(blockposition2, Blocks.AIR.defaultBlockState(), 3); + // dropResources(iblockdata, world, blockposition2, tileentity); + blockList.setBlock(blockposition2, Blocks.AIR.defaultBlockState(), 3); + // CraftBukkit end ++i; if (j < 6) { queue.add(new Tuple<>(blockposition2, j + 1)); @@ -92,6 +104,39 @@ break; } } + // CraftBukkit start + List blocks = blockList.getList(); // Is a clone + if (!blocks.isEmpty()) { + final org.bukkit.block.Block bblock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); + + SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List) (List) blocks); + world.getCraftServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return false; + } + + for (CraftBlockState block : blocks) { + BlockPosition blockposition2 = block.getPosition(); + IBlockData iblockdata = world.getBlockState(blockposition2); + Fluid fluid = world.getFluidState(blockposition2); + Material material = iblockdata.getMaterial(); + + if (fluid.is(TagsFluid.WATER)) { + if (iblockdata.getBlock() instanceof IFluidSource && !((IFluidSource) iblockdata.getBlock()).pickupBlock(blockList, blockposition2, iblockdata).isEmpty()) { + // NOP + } else if (iblockdata.getBlock() instanceof BlockFluids) { + // NOP + } else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) { + TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition2) : null; + + dropResources(iblockdata, world, blockposition2, tileentity); + } + } + world.setBlock(blockposition2, block.getHandle(), block.getFlag()); + } + } + // CraftBukkit end return i > 0; }