use of net.minecraft.block.IWaterLoggable in project Create_Aeronautics by Eriksonnaren.
the class AirshipManager method removeBlocksFromWorld.
public void removeBlocksFromWorld(World world, BlockPos anchor, Map<BlockPos, Template.BlockInfo> blocks) {
for (boolean brittles : Iterate.trueAndFalse) {
for (Iterator<Template.BlockInfo> iterator = blocks.values().iterator(); iterator.hasNext(); ) {
Template.BlockInfo block = iterator.next();
if (brittles != BlockMovementChecks.isBrittle(block.state))
continue;
BlockPos add = block.pos.offset(anchor);
BlockState oldState = world.getBlockState(add);
Block blockIn = oldState.getBlock();
if (block.state.getBlock() != blockIn)
iterator.remove();
world.removeBlockEntity(add);
int flags = Constants.BlockFlags.IS_MOVING | Constants.BlockFlags.NO_NEIGHBOR_DROPS | Constants.BlockFlags.UPDATE_NEIGHBORS | Constants.BlockFlags.BLOCK_UPDATE | Constants.BlockFlags.RERENDER_MAIN_THREAD;
if (blockIn instanceof IWaterLoggable && oldState.hasProperty(BlockStateProperties.WATERLOGGED) && oldState.getValue(BlockStateProperties.WATERLOGGED)) {
world.setBlock(add, Blocks.WATER.defaultBlockState(), flags);
continue;
}
world.setBlock(add, Blocks.AIR.defaultBlockState(), flags);
}
}
for (Template.BlockInfo block : blocks.values()) {
BlockPos add = block.pos.offset(anchor);
// if (!shouldUpdateAfterMovement(block))
// continue;
int flags = Constants.BlockFlags.IS_MOVING | Constants.BlockFlags.DEFAULT;
world.sendBlockUpdated(add, block.state, Blocks.AIR.defaultBlockState(), flags);
// when the blockstate is set to air, the block's POI data is removed, but markAndNotifyBlock tries to
// remove it again, so to prevent an error from being logged by double-removal we add the POI data back now
// (code copied from ServerWorld.onBlockStateChange)
ServerWorld serverWorld = (ServerWorld) world;
PointOfInterestType.forState(block.state).ifPresent(poiType -> {
world.getServer().execute(() -> {
serverWorld.getPoiManager().add(add, poiType);
DebugPacketSender.sendPoiAddedPacket(serverWorld, add);
});
});
world.markAndNotifyBlock(add, world.getChunkAt(add), block.state, Blocks.AIR.defaultBlockState(), flags, 512);
block.state.updateIndirectNeighbourShapes(world, add, flags & -2);
}
}
Aggregations