Search in sources :

Example 1 with CompiledOverlay

use of com.github.lunatrius.schematica.client.renderer.chunk.CompiledOverlay in project Spark-Client by Spark-Client-Development.

the class RenderOverlay method rebuildChunk.

@Override
public void rebuildChunk(final float x, final float y, final float z, final ChunkCompileTaskGenerator generator) {
    final CompiledOverlay compiledOverlay = new CompiledOverlay();
    final BlockPos from = getPosition();
    final BlockPos to = from.add(15, 15, 15);
    final BlockPos fromEx = from.add(-1, -1, -1);
    final BlockPos toEx = to.add(1, 1, 1);
    generator.getLock().lock();
    ChunkCache chunkCache;
    final SchematicWorld schematic = (SchematicWorld) this.world;
    try {
        if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING) {
            return;
        }
        if (from.getX() < 0 || from.getZ() < 0 || from.getX() >= schematic.getWidth() || from.getZ() >= schematic.getLength()) {
            generator.setCompiledChunk(CompiledChunk.DUMMY);
            return;
        }
        chunkCache = new ChunkCache(this.world, fromEx, toEx, 1);
        generator.setCompiledChunk(compiledOverlay);
    } finally {
        generator.getLock().unlock();
    }
    final VisGraph visgraph = new VisGraph();
    if (!chunkCache.isEmpty()) {
        ++renderChunksUpdated;
        final World mcWorld = Minecraft.getMinecraft().world;
        final BlockRenderLayer layer = BlockRenderLayer.TRANSLUCENT;
        final BufferBuilder buffer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(layer);
        GeometryTessellator.setStaticDelta(0.005);
        // Elements in this array may be null, indicating that nothing should be rendered (or out of bounds)
        // 18 elements to provide padding on both sides (this padding is not rendered).
        final BlockType[][][] types = new BlockType[18][18][18];
        // Build the type array (including the padding)
        BlockPos.MutableBlockPos mcPos = new BlockPos.MutableBlockPos();
        for (final BlockPos.MutableBlockPos pos : BlockPos.getAllInBoxMutable(fromEx, toEx)) {
            if (!schematic.isInside(pos) || !schematic.layerMode.shouldUseLayer(schematic, pos.getY())) {
                continue;
            }
            // Indices in types
            int secX = pos.getX() - fromEx.getX();
            int secY = pos.getY() - fromEx.getY();
            int secZ = pos.getZ() - fromEx.getZ();
            final IBlockState schBlockState = schematic.getBlockState(pos);
            final Block schBlock = schBlockState.getBlock();
            if (schBlockState.isOpaqueCube()) {
                visgraph.setOpaqueCube(pos);
            }
            mcPos.setPos(pos.getX() + schematic.position.getX(), pos.getY() + schematic.position.getY(), pos.getZ() + schematic.position.getZ());
            final IBlockState mcBlockState = mcWorld.getBlockState(mcPos);
            final Block mcBlock = mcBlockState.getBlock();
            final boolean isSchAirBlock = schematic.isAirBlock(pos);
            final boolean isMcAirBlock = mcWorld.isAirBlock(mcPos) || SchematicaConfig.INSTANCE.extraAirBlocks.isValueSelected(mcBlock);
            if (SchematicaConfig.INSTANCE.highlightAir.getValue() && !isMcAirBlock && isSchAirBlock) {
                types[secX][secY][secZ] = BlockType.EXTRA_BLOCK;
            } else if (SchematicaConfig.INSTANCE.highlight.getValue()) {
                if (!isMcAirBlock && !isSchAirBlock) {
                    if (schBlock != mcBlock) {
                        types[secX][secY][secZ] = BlockType.WRONG_BLOCK;
                    } else if (schBlock.getMetaFromState(schBlockState) != mcBlock.getMetaFromState(mcBlockState)) {
                        types[secX][secY][secZ] = BlockType.WRONG_META;
                    }
                } else if (!isSchAirBlock) {
                    types[secX][secY][secZ] = BlockType.MISSING_BLOCK;
                }
            }
        }
        // Draw the type array (but not the padding)
        for (final BlockPos.MutableBlockPos pos : BlockPos.getAllInBoxMutable(from, to)) {
            int secX = pos.getX() - fromEx.getX();
            int secY = pos.getY() - fromEx.getY();
            int secZ = pos.getZ() - fromEx.getZ();
            BlockType type = types[secX][secY][secZ];
            if (type != null) {
                if (!compiledOverlay.isLayerStarted(layer)) {
                    compiledOverlay.setLayerStarted(layer);
                    preRenderBlocks(buffer, from);
                }
                int sides = getSides(types, secX, secY, secZ);
                GeometryTessellator.drawCuboid(buffer, pos, sides, 0x3F000000 | type.color);
                compiledOverlay.setLayerUsed(layer);
            }
        }
        if (compiledOverlay.isLayerStarted(layer)) {
            postRenderBlocks(layer, x, y, z, buffer, compiledOverlay);
        }
    }
    compiledOverlay.setVisibility(visgraph.computeVisibility());
}
Also used : VisGraph(net.minecraft.client.renderer.chunk.VisGraph) IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) World(net.minecraft.world.World) SchematicWorld(com.github.lunatrius.schematica.client.world.SchematicWorld) SchematicWorld(com.github.lunatrius.schematica.client.world.SchematicWorld) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) CompiledOverlay(com.github.lunatrius.schematica.client.renderer.chunk.CompiledOverlay)

Aggregations

CompiledOverlay (com.github.lunatrius.schematica.client.renderer.chunk.CompiledOverlay)1 SchematicWorld (com.github.lunatrius.schematica.client.world.SchematicWorld)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 VisGraph (net.minecraft.client.renderer.chunk.VisGraph)1 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkCache (net.minecraft.world.ChunkCache)1 World (net.minecraft.world.World)1