use of org.bukkit.event.block.SpongeAbsorbEvent in project Arclight by IzzelAliz.
the class SpongeBlockMixin method absorb.
/**
* @author IzzelAliz
* @reason
*/
@SuppressWarnings("unchecked")
@Overwrite
private boolean absorb(World worldIn, BlockPos pos) {
Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
queue.add(new Tuple<>(pos, 0));
int i = 0;
BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn);
while (!queue.isEmpty()) {
Tuple<BlockPos, Integer> tuple = queue.poll();
BlockPos blockpos = tuple.getA();
int j = tuple.getB();
for (Direction direction : Direction.values()) {
BlockPos blockpos1 = blockpos.offset(direction);
BlockState blockstate = blockList.getBlockState(blockpos1);
IFluidState ifluidstate = blockList.getFluidState(blockpos1);
Material material = blockstate.getMaterial();
if (ifluidstate.isTagged(FluidTags.WATER)) {
if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
++i;
if (j < 6) {
queue.add(new Tuple<>(blockpos1, j + 1));
}
} else if (blockstate.getBlock() instanceof FlowingFluidBlock) {
worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
++i;
if (j < 6) {
queue.add(new Tuple<>(blockpos1, j + 1));
}
} else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
// TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
// Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity);
blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
++i;
if (j < 6) {
queue.add(new Tuple<>(blockpos1, j + 1));
}
}
}
}
if (i > 64) {
break;
}
}
// Is a clone
List<CraftBlockState> blocks = blockList.getList();
if (!blocks.isEmpty()) {
final org.bukkit.block.Block bblock = CraftBlock.at(worldIn, pos);
SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
for (CraftBlockState block : blocks) {
BlockPos blockposition2 = block.getPosition();
BlockState iblockdata = worldIn.getBlockState(blockposition2);
IFluidState fluid = worldIn.getFluidState(blockposition2);
Material material = iblockdata.getMaterial();
if (fluid.isTagged(FluidTags.WATER)) {
if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) {
// NOP
} else if (iblockdata.getBlock() instanceof FlowingFluidBlock) {
// NOP
} else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null;
Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity);
}
}
worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag());
}
}
return i > 0;
}
Aggregations