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());
}
Aggregations