PaperMC/paper-server/nms-patches/net/minecraft/world/level/block/BlockSponge.patch
CraftBukkit/Spigot 8a3c8cfcd4 Update to Minecraft 1.20.2
By: md_5 <git@md-5.net>
2023-09-22 02:40:00 +10:00

110 lines
5.3 KiB
Diff

--- a/net/minecraft/world/level/block/BlockSponge.java
+++ b/net/minecraft/world/level/block/BlockSponge.java
@@ -12,6 +12,13 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.material.Fluid;
+// 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;
@@ -44,7 +51,8 @@
}
private boolean removeWaterBreadthFirstSearch(World world, BlockPosition blockposition) {
- return BlockPosition.breadthFirstTraversal(blockposition, 6, 65, (blockposition1, consumer) -> {
+ BlockStateListPopulator blockList = new BlockStateListPopulator(world); // CraftBukkit - Use BlockStateListPopulator
+ BlockPosition.breadthFirstTraversal(blockposition, 6, 65, (blockposition1, consumer) -> {
EnumDirection[] aenumdirection = BlockSponge.ALL_DIRECTIONS;
int i = aenumdirection.length;
@@ -58,8 +66,10 @@
if (blockposition1.equals(blockposition)) {
return true;
} else {
- IBlockData iblockdata = world.getBlockState(blockposition1);
- Fluid fluid = world.getFluidState(blockposition1);
+ // CraftBukkit start
+ IBlockData iblockdata = blockList.getBlockState(blockposition1);
+ Fluid fluid = blockList.getFluidState(blockposition1);
+ // CraftBukkit end
if (!fluid.is(TagsFluid.WATER)) {
return false;
@@ -69,27 +79,64 @@
if (block instanceof IFluidSource) {
IFluidSource ifluidsource = (IFluidSource) block;
- if (!ifluidsource.pickupBlock((EntityHuman) null, world, blockposition1, iblockdata).isEmpty()) {
+ if (!ifluidsource.pickupBlock((EntityHuman) null, blockList, blockposition1, iblockdata).isEmpty()) { // CraftBukkit
return true;
}
}
if (iblockdata.getBlock() instanceof BlockFluids) {
- world.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3); // CraftBukkit
} else {
if (!iblockdata.is(Blocks.KELP) && !iblockdata.is(Blocks.KELP_PLANT) && !iblockdata.is(Blocks.SEAGRASS) && !iblockdata.is(Blocks.TALL_SEAGRASS)) {
return false;
}
- TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
+ // CraftBukkit start
+ // TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
- dropResources(iblockdata, world, blockposition1, tileentity);
- world.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ // dropResources(iblockdata, world, blockposition1, tileentity);
+ blockList.setBlock(blockposition1, Blocks.AIR.defaultBlockState(), 3);
+ // CraftBukkit end
}
return true;
}
}
- }) > 1;
+ });
+ // CraftBukkit start
+ List<CraftBlockState> 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<org.bukkit.block.BlockState>) (List) blocks);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false;
+ }
+
+ for (CraftBlockState block : blocks) {
+ BlockPosition blockposition1 = block.getPosition();
+ IBlockData iblockdata = world.getBlockState(blockposition1);
+ Fluid fluid = world.getFluidState(blockposition1);
+
+ if (fluid.is(TagsFluid.WATER)) {
+ if (iblockdata.getBlock() instanceof IFluidSource && !((IFluidSource) iblockdata.getBlock()).pickupBlock((EntityHuman) null, blockList, blockposition1, iblockdata).isEmpty()) {
+ // NOP
+ } else if (iblockdata.getBlock() instanceof BlockFluids) {
+ // NOP
+ } else if (iblockdata.is(Blocks.KELP) || iblockdata.is(Blocks.KELP_PLANT) || iblockdata.is(Blocks.SEAGRASS) || iblockdata.is(Blocks.TALL_SEAGRASS)) {
+ TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition1) : null;
+
+ dropResources(iblockdata, world, blockposition1, tileentity);
+ }
+ }
+ world.setBlock(blockposition1, block.getHandle(), block.getFlag());
+ }
+
+ return true;
+ }
+ return false;
+ // CraftBukkit end
}
}