use of net.minecraft.world.chunk.ChunkSection in project ChocolateQuestRepoured by TeamChocoQuest.
the class BlockPosUtil method forEach.
public static void forEach(World world, int x1, int y1, int z1, int x2, int y2, int z2, boolean skipUnloadedChunks, boolean skipAirBlocks, BlockInfoConsumer action) {
if (world.isDebug()) {
return;
}
x1 = Math.max(x1, -30_000_000);
y1 = Math.max(y1, 0);
z1 = Math.max(z1, -30_000_000);
x2 = Math.min(x2, 30_000_000);
y2 = Math.min(y2, 255);
z2 = Math.min(z2, 30_000_000);
if (x1 > x2 || y1 > y2 || z1 > z2) {
return;
}
int chunkStartX = x1 >> 4;
int chunkStartY = y1 >> 4;
int chunkStartZ = z1 >> 4;
int chunkEndX = x2 >> 4;
int chunkEndY = y2 >> 4;
int chunkEndZ = z2 >> 4;
BlockPos.Mutable mutablePos = new BlockPos.Mutable();
for (int chunkX = chunkStartX; chunkX <= chunkEndX; chunkX++) {
for (int chunkZ = chunkStartZ; chunkZ <= chunkEndZ; chunkZ++) {
if (skipUnloadedChunks && !world.isLoaded(mutablePos.set(chunkX << 4, 0, chunkZ << 4))) {
continue;
}
Chunk chunk = world.getChunk(chunkX, chunkZ);
ChunkSection[] blockStorageArray = chunk.getSections();
for (int chunkY = chunkStartY; chunkY <= chunkEndY; chunkY++) {
ChunkSection extendedBlockStorage = blockStorageArray[chunkY];
if (skipAirBlocks && extendedBlockStorage == Chunk.EMPTY_SECTION) {
continue;
}
int blockStartX = Math.max(chunkX << 4, x1);
int blockStartY = Math.max(chunkY << 4, y1);
int blockStartZ = Math.max(chunkZ << 4, z1);
int blockEndX = Math.min((chunkX << 4) | 15, x2);
int blockEndY = Math.min((chunkY << 4) | 15, y2);
int blockEndZ = Math.min((chunkZ << 4) | 15, z2);
for (int z5 = blockStartZ; z5 <= blockEndZ; z5++) {
for (int y5 = blockStartY; y5 <= blockEndY; y5++) {
for (int x5 = blockStartX; x5 <= blockEndX; x5++) {
BlockState state = extendedBlockStorage.getBlockState(x5 & 15, y5 & 15, z5 & 15);
if (skipAirBlocks && state.getBlock() == Blocks.AIR) {
continue;
}
mutablePos.set(x5, y5, z5);
action.accept(mutablePos, state);
}
}
}
}
}
}
}
use of net.minecraft.world.chunk.ChunkSection in project ChocolateQuestRepoured by TeamChocoQuest.
the class BlockPlacingHelper method setBlockState.
public static boolean setBlockState(World world, BlockPos pos, BlockState state, @Nullable TileEntity tileEntity, int flags, boolean updateLight) {
if (CQRMain.isPhosphorInstalled || CQRConfig.advanced.instantLightUpdates || updateLight) {
if (!world.setBlock(pos, state, flags)) {
return false;
}
if (tileEntity != null) {
world.setBlockEntity(pos, tileEntity);
tileEntity.updateContainingBlockInfo();
}
return true;
}
if (world.isOutsideBuildHeight(pos)) {
return false;
}
if (!world.isRemote && world.getWorldInfo().getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
return false;
}
IChunk chunk = world.getChunk(pos);
ChunkSection blockStorage = chunk.getSections()[pos.getY() >> 4];
if (blockStorage == Chunk.EMPTY_SECTION) {
if (state == Blocks.AIR.defaultBlockState()) {
return false;
}
blockStorage = new ChunkSection(pos.getY() >> 4 << 4);
chunk.getSections()[pos.getY() >> 4] = blockStorage;
}
return setBlockState(world, chunk, blockStorage, pos, state, tileEntity, flags);
}
use of net.minecraft.world.chunk.ChunkSection in project ChocolateQuestRepoured by TeamChocoQuest.
the class BlockPlacingHelper method setBlockStates.
public static boolean setBlockStates(World world, int chunkX, int chunkY, int chunkZ, GeneratableDungeon dungeon, IBlockInfo blockInfo) {
if (world.isOutsideBuildHeight(MUTABLE.set(chunkX << 4, chunkY << 4, chunkZ << 4))) {
return false;
}
if (!world.isRemote && world.getWorldInfo().getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
return false;
}
Chunk chunk = world.getChunk(chunkX, chunkZ);
ChunkSection blockStorage = chunk.getSections()[chunkY];
if (blockStorage == Chunk.EMPTY_SECTION) {
blockStorage = new ChunkSection(chunkY << 4);
chunk.getSections()[chunkY] = blockStorage;
if (!blockInfo.place(world, chunk, blockStorage, dungeon)) {
chunk.getSections()[chunkY] = null;
return false;
}
return true;
}
return blockInfo.place(world, chunk, blockStorage, dungeon);
}
use of net.minecraft.world.chunk.ChunkSection in project ChocolateQuestRepoured by TeamChocoQuest.
the class GeneratablePosInfo method generate.
@Override
public void generate(World world, GeneratableDungeon dungeon) {
Chunk chunk = world.getChunk(this.x >> 4, this.z >> 4);
if (this.y < 0 || this.y > 256) {
return;
}
ChunkSection blockStorage = chunk.getSections()[this.y >> 4];
if (blockStorage == null) {
blockStorage = new ChunkSection(this.y >> 4 << 4);
if (this.place(world, chunk, blockStorage, dungeon)) {
chunk.getSections()[this.y >> 4] = blockStorage;
}
} else {
this.place(world, chunk, blockStorage, dungeon);
}
}
use of net.minecraft.world.chunk.ChunkSection in project canvas by vram-guild.
the class ChunkPaletteCopier method captureCopy.
public static PaletteCopy captureCopy(WorldChunk chunk, int sectionIndex) {
if (chunk == null || sectionIndex < 0) {
return AIR_COPY;
}
final ChunkSection[] sections = chunk.getSectionArray();
if (sections == null || sectionIndex >= sections.length) {
return AIR_COPY;
}
final ChunkSection sec = sections[sectionIndex];
if (sec == null) {
return AIR_COPY;
}
if (sec.isEmpty()) {
final BlockState filler = sec.getBlockState(0, 0, 0);
return filler == AIR ? AIR_COPY : i -> filler;
}
return ((PalettedContainerExt) sec.getContainer()).canvas_paletteCopy();
}
Aggregations