Search in sources :

Example 21 with ChunkSection

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 22 with ChunkSection

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);
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 23 with ChunkSection

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);
}
Also used : IChunk(net.minecraft.world.chunk.IChunk) Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 24 with ChunkSection

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);
    }
}
Also used : Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 25 with ChunkSection

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();
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Aggregations

ChunkSection (net.minecraft.world.chunk.ChunkSection)36 Chunk (net.minecraft.world.chunk.Chunk)11 BlockState (net.minecraft.block.BlockState)10 BlockPos (net.minecraft.util.math.BlockPos)8 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 WorldChunk (net.minecraft.world.chunk.WorldChunk)5 Inject (org.spongepowered.asm.mixin.injection.Inject)5 TileEntity (net.minecraft.tileentity.TileEntity)3 BiomeContainer (net.minecraft.world.biome.BiomeContainer)3 ArrayList (java.util.ArrayList)2 Block (net.minecraft.block.Block)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2 PathNodeType (net.minecraft.entity.ai.pathing.PathNodeType)2 FluidState (net.minecraft.fluid.FluidState)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 PalettedContainer (net.minecraft.util.palette.PalettedContainer)2 CollisionView (net.minecraft.world.CollisionView)2