diff --git a/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java b/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java index ea6cdb5..2add847 100644 --- a/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java +++ b/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java @@ -1,27 +1,21 @@ package link.infra.indium.mixin.sodium; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - import link.infra.indium.Indium; import link.infra.indium.renderer.render.TerrainRenderContext; import me.jellysquid.mods.sodium.client.gl.compile.ChunkBuildContext; import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildResult; import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderBuildTask; import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderRebuildTask; import me.jellysquid.mods.sodium.client.util.task.CancellationSource; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.minecraft.block.BlockState; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockRenderView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; /** * The main injection point into Sodium - here we stop Sodium from rendering FRAPI block models, and do it ourselves @@ -46,8 +40,7 @@ public boolean onRenderBlock(BlockRenderer blockRenderer, BlockRenderContext ctx if (!Indium.ALWAYS_TESSELLATE_INDIUM && ((FabricBakedModel) ctx.model()).isVanillaAdapter()) { return blockRenderer.renderModel(ctx, buffers); } else { - Vec3d modelOffset = ctx.state().getModelOffset(ctx.world(), ctx.pos()); - return TerrainRenderContext.get(buildContext).tessellateBlock(ctx.state(), ctx.pos(), ctx.origin(), ctx.model(), modelOffset); + return TerrainRenderContext.get(buildContext).tessellateBlock(ctx); } } } diff --git a/src/main/java/link/infra/indium/renderer/render/BlockRenderInfo.java b/src/main/java/link/infra/indium/renderer/render/BlockRenderInfo.java index 52406da..4f86bee 100644 --- a/src/main/java/link/infra/indium/renderer/render/BlockRenderInfo.java +++ b/src/main/java/link/infra/indium/renderer/render/BlockRenderInfo.java @@ -16,8 +16,6 @@ package link.infra.indium.renderer.render; -import java.util.function.Supplier; - import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; @@ -31,6 +29,8 @@ import net.minecraft.util.math.random.RandomSeed; import net.minecraft.world.BlockRenderView; +import java.util.function.Supplier; + /** * Holds, manages and provides access to the block/world related state * needed by fallback and mesh consumers. @@ -49,27 +49,18 @@ public class BlockRenderInfo { RenderLayer defaultLayer; public final Supplier randomSupplier = () -> { - final Random result = random; - long seed = this.seed; - - if (seed == -1L) { - seed = blockState.getRenderingSeed(blockPos); - this.seed = seed; - } - - result.setSeed(seed); - return result; + random.setSeed(this.seed); + return random; }; public void setBlockView(BlockRenderView blockView) { this.blockView = blockView; } - public void prepareForBlock(BlockState blockState, BlockPos blockPos, boolean modelAO) { + public void prepareForBlock(BlockState blockState, BlockPos blockPos, boolean modelAO, long seed) { this.blockPos = blockPos; this.blockState = blockState; - // in the unlikely case seed actually matches this, we'll simply retrieve it more than one - seed = -1L; + this.seed = seed; defaultAo = modelAO && MinecraftClient.isAmbientOcclusionEnabled() && blockState.getLuminance() == 0; defaultLayer = RenderLayers.getBlockLayer(blockState); diff --git a/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java b/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java index 434e094..f99fe69 100644 --- a/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java @@ -77,7 +77,7 @@ public boolean render(BlockRenderView blockView, BakedModel model, BlockState st this.didOutput = false; aoCalc.clear(); blockInfo.setBlockView(blockView); - blockInfo.prepareForBlock(state, pos, model.useAmbientOcclusion()); + blockInfo.prepareForBlock(state, pos, model.useAmbientOcclusion(), seed); lightCache.reset(pos, blockView); ((FabricBakedModel) model).emitBlockQuads(blockView, state, pos, randomSupplier, this); diff --git a/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java b/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java index fc05ba6..3581863 100644 --- a/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java +++ b/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java @@ -32,8 +32,8 @@ public TerrainBlockRenderInfo(BlockOcclusionCache blockOcclusionCache) { } @Override - public void prepareForBlock(BlockState blockState, BlockPos blockPos, boolean modelAO) { - super.prepareForBlock(blockState, blockPos, modelAO); + public void prepareForBlock(BlockState blockState, BlockPos blockPos, boolean modelAO, long seed) { + super.prepareForBlock(blockState, blockPos, modelAO, seed); cullCompletionFlags = 0; cullResultFlags = 0; } diff --git a/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java b/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java index 879e3c4..62e1f53 100644 --- a/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java @@ -1,8 +1,5 @@ package link.infra.indium.renderer.render; -import java.util.function.Consumer; -import java.util.function.Function; - import link.infra.indium.mixin.sodium.AccessBlockRenderer; import link.infra.indium.renderer.accessor.AccessBlockRenderCache; import link.infra.indium.renderer.aocalc.AoCalculator; @@ -10,23 +7,22 @@ import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache; import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder; import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderCache; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache; import me.jellysquid.mods.sodium.client.world.WorldSlice; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.minecraft.block.BlockState; import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.model.BakedModel; import net.minecraft.util.crash.CrashException; import net.minecraft.util.crash.CrashReport; import net.minecraft.util.crash.CrashReportSection; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.Vec3i; -import org.joml.Vector3f; import org.joml.Vector3fc; +import java.util.function.Consumer; +import java.util.function.Function; + public class TerrainRenderContext extends AbstractRenderContext { private final TerrainBlockRenderInfo blockInfo; private final ChunkRenderInfo chunkInfo; @@ -66,19 +62,19 @@ public void release() { } /** Called from chunk renderer hook. */ - public boolean tessellateBlock(BlockState blockState, BlockPos blockPos, Vector3fc origin, final BakedModel model, Vec3d modelOffset) { - this.origin = origin; - this.modelOffset = modelOffset; + public boolean tessellateBlock(BlockRenderContext ctx) { + this.origin = ctx.origin(); + this.modelOffset = ctx.state().getModelOffset(ctx.world(), ctx.pos()); try { chunkInfo.didOutput = false; aoCalc.clear(); - blockInfo.prepareForBlock(blockState, blockPos, model.useAmbientOcclusion()); - ((FabricBakedModel) model).emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this); + blockInfo.prepareForBlock(ctx.state(), ctx.pos(), ctx.model().useAmbientOcclusion(), ctx.seed()); + ((FabricBakedModel) ctx.model()).emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this); } catch (Throwable throwable) { CrashReport crashReport = CrashReport.create(throwable, "Tessellating block in world - Indium Renderer"); CrashReportSection crashReportSection = crashReport.addElement("Block being tessellated"); - CrashReportSection.addBlockInfo(crashReportSection, chunkInfo.blockView, blockPos, blockState); + CrashReportSection.addBlockInfo(crashReportSection, chunkInfo.blockView, ctx.pos(), ctx.state()); throw new CrashException(crashReport); }