Skip to content

Commit

Permalink
fix: InfoOverlay getting confused with the ClientWorld
Browse files Browse the repository at this point in the history
feat/fix: add switchable AO Processor config,`renderAOModernEnabled` in order to disable / enable the 'new' AO Processor code; or continue using the older code from 2018 without the "Shadows" that it creates in between block layers.
  • Loading branch information
sakura-ryoko committed Dec 5, 2024
1 parent a984907 commit 526a354
Show file tree
Hide file tree
Showing 20 changed files with 1,232 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = litematica-fabric

# Current mod version
mod_version = 0.21.0-sakura.1
mod_version = 0.21.0-sakura.2

# Required malilib version
malilib_version = 1e13f4c8ce
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fi/dy/masa/litematica/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ public static class Visuals
public static final ConfigBoolean IGNORE_EXISTING_FLUIDS = new ConfigBoolean("ignoreExistingFluids", false).apply(VISUALS_KEY);
public static final ConfigBoolean OVERLAY_REDUCED_INNER_SIDES = new ConfigBoolean("overlayReducedInnerSides", false).apply(VISUALS_KEY);
public static final ConfigDouble PLACEMENT_BOX_SIDE_ALPHA = new ConfigDouble( "placementBoxSideAlpha", 0.2, 0, 1).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_AO_MODERN_ENABLE = new ConfigBoolean("renderAOModernEnable", false).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_AREA_SELECTION_BOX_SIDES = new ConfigBoolean("renderAreaSelectionBoxSides", true).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_BLOCKS_AS_TRANSLUCENT = new ConfigBoolean("renderBlocksAsTranslucent", false).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_COLLIDING_SCHEMATIC_BLOCKS = new ConfigBoolean("renderCollidingSchematicBlocks", false).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_ERROR_MARKER_CONNECTIONS = new ConfigBoolean("renderErrorMarkerConnections", false).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_ERROR_MARKER_SIDES = new ConfigBoolean("renderErrorMarkerSides", true).apply(VISUALS_KEY);
//public static final ConfigInteger RENDER_FAKE_LIGHTING_LEVEL = new ConfigInteger("renderFakeLightingLevel", 15, 0, 15).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_PLACEMENT_BOX_SIDES = new ConfigBoolean("renderPlacementBoxSides", false).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_PLACEMENT_ENCLOSING_BOX = new ConfigBoolean("renderPlacementEnclosingBox", true).apply(VISUALS_KEY);
public static final ConfigBoolean RENDER_PLACEMENT_ENCLOSING_BOX_SIDES= new ConfigBoolean("renderPlacementEnclosingBoxSides", false).apply(VISUALS_KEY);
Expand Down Expand Up @@ -230,11 +232,13 @@ public static class Visuals
ENABLE_SCHEMATIC_OVERLAY,
IGNORE_EXISTING_FLUIDS,
OVERLAY_REDUCED_INNER_SIDES,
RENDER_AO_MODERN_ENABLE,
RENDER_AREA_SELECTION_BOX_SIDES,
RENDER_BLOCKS_AS_TRANSLUCENT,
RENDER_COLLIDING_SCHEMATIC_BLOCKS,
RENDER_ERROR_MARKER_CONNECTIONS,
RENDER_ERROR_MARKER_SIDES,
//RENDER_FAKE_LIGHTING_LEVEL,
RENDER_PLACEMENT_BOX_SIDES,
RENDER_PLACEMENT_ENCLOSING_BOX,
RENDER_PLACEMENT_ENCLOSING_BOX_SIDES,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ protected void allocateCache()
this.layerCache.get(layer).close();
}

this.layerCache.put(layer, new BufferAllocator(layer.getExpectedBufferSize()));
synchronized (this.layerCache)
{
this.layerCache.put(layer, new BufferAllocator(layer.getExpectedBufferSize()));
}
}
for (OverlayRenderType type : TYPES)
{
Expand All @@ -37,7 +40,10 @@ protected void allocateCache()
this.overlayCache.get(type).close();
}

this.overlayCache.put(type, new BufferAllocator(type.getExpectedBufferSize()));
synchronized (this.overlayCache)
{
this.overlayCache.put(type, new BufferAllocator(type.getExpectedBufferSize()));
}
}
}

Expand All @@ -53,19 +59,28 @@ protected boolean hasBufferByOverlay(OverlayRenderType type)

protected BufferAllocator getBufferByLayer(RenderLayer layer)
{
return this.layerCache.computeIfAbsent(layer, l -> new BufferAllocator(l.getExpectedBufferSize()));
synchronized (this.layerCache)
{
return this.layerCache.computeIfAbsent(layer, l -> new BufferAllocator(l.getExpectedBufferSize()));
}
}

protected BufferAllocator getBufferByOverlay(OverlayRenderType type)
{
return this.overlayCache.computeIfAbsent(type, t -> new BufferAllocator(t.getExpectedBufferSize()));
synchronized (this.overlayCache)
{
return this.overlayCache.computeIfAbsent(type, t -> new BufferAllocator(t.getExpectedBufferSize()));
}
}

protected void closeByLayer(RenderLayer layer)
{
try
{
this.layerCache.remove(layer).close();
synchronized (this.layerCache)
{
this.layerCache.remove(layer).close();
}
}
catch (Exception ignored) { }
}
Expand All @@ -74,7 +89,10 @@ protected void closeByType(OverlayRenderType type)
{
try
{
this.overlayCache.remove(type).close();
synchronized (this.overlayCache)
{
this.overlayCache.remove(type).close();
}
}
catch (Exception ignored) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ protected BufferBuilderCache() { }

protected boolean hasBufferByLayer(RenderLayer layer)
{
return blockBufferBuilders.containsKey(layer);
return this.blockBufferBuilders.containsKey(layer);
}

protected boolean hasBufferByOverlay(OverlayRenderType type)
{
return overlayBufferBuilders.containsKey(type);
return this.overlayBufferBuilders.containsKey(type);
}

protected BufferBuilder getBufferByLayer(RenderLayer layer, @Nonnull BufferAllocatorCache allocators)
{
return blockBufferBuilders.computeIfAbsent(layer, (key) -> new BufferBuilder(allocators.getBufferByLayer(key), key.getDrawMode(), key.getVertexFormat()));
synchronized (this.blockBufferBuilders)
{
return this.blockBufferBuilders.computeIfAbsent(layer, (key) -> new BufferBuilder(allocators.getBufferByLayer(key), key.getDrawMode(), key.getVertexFormat()));
}
}

protected BufferBuilder getBufferByOverlay(OverlayRenderType type, @Nonnull BufferAllocatorCache allocators)
{
return overlayBufferBuilders.computeIfAbsent(type, (key) -> new BufferBuilder(allocators.getBufferByOverlay(key), key.getDrawMode(), key.getVertexFormat()));
synchronized (this.overlayBufferBuilders)
{
return this.overlayBufferBuilders.computeIfAbsent(type, (key) -> new BufferBuilder(allocators.getBufferByOverlay(key), key.getDrawMode(), key.getVertexFormat()));
}
}

protected void clearAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ protected void storeBuiltBufferByLayer(RenderLayer layer, @Nonnull BuiltBuffer n
{
this.layerBuffers.get(layer).close();
}
this.layerBuffers.put(layer, newBuffer);
synchronized (this.layerBuffers)
{
this.layerBuffers.put(layer, newBuffer);
}
}

protected void storeBuiltBufferByType(OverlayRenderType type, @Nonnull BuiltBuffer newBuffer)
Expand All @@ -39,7 +42,10 @@ protected void storeBuiltBufferByType(OverlayRenderType type, @Nonnull BuiltBuff
{
this.overlayBuffers.get(type).close();
}
this.overlayBuffers.put(type, newBuffer);
synchronized (this.overlayBuffers)
{
this.overlayBuffers.put(type, newBuffer);
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import net.minecraft.client.render.RenderLayer;

public record ChunkRenderLayers()
Expand All @@ -17,6 +18,25 @@ private static List<RenderLayer> getLayers()
// Water Rendering
list.add(RenderLayer.getWaterMask());

// Experimental
/*
list.add(RenderLayer.getSecondaryBlockOutline());
list.add(RenderLayer.getArmorEntityGlint());
list.add(RenderLayer.getEntityGlint());
list.add(TexturedRenderLayers.getArmorTrims(true));
list.add(TexturedRenderLayers.getArmorTrims(false));
list.add(TexturedRenderLayers.getBeds());
list.add(TexturedRenderLayers.getBannerPatterns());
list.add(TexturedRenderLayers.getChest());
list.add(TexturedRenderLayers.getEntitySolid());
list.add(TexturedRenderLayers.getEntityCutout());
list.add(TexturedRenderLayers.getHangingSign());
list.add(TexturedRenderLayers.getItemEntityTranslucentCull());
list.add(TexturedRenderLayers.getShieldPatterns());
list.add(TexturedRenderLayers.getShulkerBoxes());
list.add(TexturedRenderLayers.getSign());
*/

return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.*;
import javax.annotation.Nullable;

import net.minecraft.client.render.block.BlockModelRenderer;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.profiler.Profilers;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
Expand Down Expand Up @@ -82,11 +85,10 @@ public WorldRendererSchematic(MinecraftClient mc)
this.mc = mc;
this.entityRenderDispatcher = mc.getEntityRenderDispatcher();
this.bufferBuilders = mc.getBufferBuilders();

this.renderChunkFactory = (world1, worldRenderer) -> new ChunkRendererSchematicVbo(world1, worldRenderer);

this.renderChunkFactory = ChunkRendererSchematicVbo::new;
this.blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
this.blockModelRenderer = new BlockModelRendererSchematic(mc.getBlockColors());
this.blockModelRenderer.setBakedManager(mc.getBakedModelManager());
}

public void markNeedsUpdate()
Expand Down Expand Up @@ -668,6 +670,8 @@ public boolean renderBlock(BlockRenderView world, BlockState state, BlockPos pos
this.blockModelRenderer.renderModel(world, this.getModelForState(state), state, pos, matrixStack, bufferBuilderIn, state.getRenderingSeed(pos));
BlockModelRendererSchematic.disableCache();

//System.out.printf("renderBlock(): result [%s]\n", result);

// TODO --> For testing the Vanilla Block Model Renderer
/*
BlockModelRenderer.enableBrightnessCache();
Expand Down Expand Up @@ -708,7 +712,8 @@ public BakedModel getModelForState(BlockState state)
}
*/

return this.blockRenderManager.getModel(state);
//return this.blockRenderManager.getModel(state);
return this.blockRenderManager.getModels().getModel(state);
}

public void renderEntities(Camera camera, Frustum frustum, Matrix4f posMatrix, float partialTicks, Profiler profiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fi.dy.masa.litematica.render.schematic.ao;

import java.util.BitSet;

import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;

import fi.dy.masa.litematica.config.Configs;

public abstract class AOProcessor
{
public final float[] brightness = new float[4];
public final int[] light = new int[4];

public static AOProcessor get()
{
if (Configs.Visuals.RENDER_AO_MODERN_ENABLE.getBooleanValue())
{
return new AOProcessorModern();
}
else
{
return new AOProcessorLegacy();
}
}

public void apply(BlockRenderView world, BlockState state, BlockPos pos, Direction direction, float[] box, BitSet shapeState, boolean hasShade)
{
}
}
Loading

0 comments on commit 526a354

Please sign in to comment.