From 3dd181467fb70094a354e4558d95050d78a558b9 Mon Sep 17 00:00:00 2001 From: comp500 Date: Wed, 2 Aug 2023 22:51:17 +0100 Subject: [PATCH] Port to Sodium 0.5.0 --- gradle.properties | 6 +-- .../mixin/sodium/AccessBlockRenderer.java | 2 +- .../mixin/sodium/MixinBlockRenderCache.java | 2 +- .../sodium/MixinChunkBuilderMeshingTask.java | 48 +++++++++++++++++++ .../sodium/MixinChunkRenderRebuildTask.java | 46 ------------------ .../accessor/AccessBlockRenderCache.java | 2 +- .../indium/renderer/aocalc/AoCalculator.java | 40 ++++++++-------- .../render/AbstractBlockRenderContext.java | 7 ++- .../render/NonTerrainBlockRenderContext.java | 4 +- .../render/SingleBlockLightDataCache.java | 12 ++--- .../render/TerrainBlockRenderInfo.java | 2 +- .../renderer/render/TerrainRenderContext.java | 36 ++++++-------- src/main/resources/fabric.mod.json | 2 +- src/main/resources/indium.mixins.json | 2 +- 14 files changed, 104 insertions(+), 107 deletions(-) create mode 100644 src/main/java/link/infra/indium/mixin/sodium/MixinChunkBuilderMeshingTask.java delete mode 100644 src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java diff --git a/gradle.properties b/gradle.properties index e839ed0..7b76cd5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,14 +6,14 @@ minecraft_version=1.20.1 yarn_mappings=1.20.1+build.8 loader_version=0.14.21 # Mod Properties -mod_version=1.0.21 +mod_version=1.0.22 maven_group=link.infra archives_base_name=indium # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.84.0+1.20.1 -sodium_version=0.4.10 -sodium_minecraft_version=1.20 +sodium_version=0.5.0 +sodium_minecraft_version=1.20.1 # Publishing metadata curseforge_id=459496 source_url=https://github.com/comp500/Indium/ diff --git a/src/main/java/link/infra/indium/mixin/sodium/AccessBlockRenderer.java b/src/main/java/link/infra/indium/mixin/sodium/AccessBlockRenderer.java index bc6a9f4..1a91633 100644 --- a/src/main/java/link/infra/indium/mixin/sodium/AccessBlockRenderer.java +++ b/src/main/java/link/infra/indium/mixin/sodium/AccessBlockRenderer.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache; @Mixin(BlockRenderer.class) public interface AccessBlockRenderer { diff --git a/src/main/java/link/infra/indium/mixin/sodium/MixinBlockRenderCache.java b/src/main/java/link/infra/indium/mixin/sodium/MixinBlockRenderCache.java index 92daba6..260228d 100644 --- a/src/main/java/link/infra/indium/mixin/sodium/MixinBlockRenderCache.java +++ b/src/main/java/link/infra/indium/mixin/sodium/MixinBlockRenderCache.java @@ -1,5 +1,6 @@ package link.infra.indium.mixin.sodium; +import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache; import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderCache; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -11,7 +12,6 @@ import link.infra.indium.renderer.accessor.AccessBlockRenderCache; import link.infra.indium.renderer.render.TerrainRenderContext; -import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache; @Mixin(BlockRenderCache.class) public class MixinBlockRenderCache implements AccessBlockRenderCache { diff --git a/src/main/java/link/infra/indium/mixin/sodium/MixinChunkBuilderMeshingTask.java b/src/main/java/link/infra/indium/mixin/sodium/MixinChunkBuilderMeshingTask.java new file mode 100644 index 0000000..e684ad4 --- /dev/null +++ b/src/main/java/link/infra/indium/mixin/sodium/MixinChunkBuilderMeshingTask.java @@ -0,0 +1,48 @@ +package link.infra.indium.mixin.sodium; + +import link.infra.indium.Indium; +import link.infra.indium.renderer.render.TerrainRenderContext; +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildContext; +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildOutput; +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.compile.tasks.ChunkBuilderMeshingTask; +import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderTask; +import me.jellysquid.mods.sodium.client.util.task.CancellationToken; +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 + */ +@Mixin(ChunkBuilderMeshingTask.class) +public abstract class MixinChunkBuilderMeshingTask extends ChunkBuilderTask { + @Inject(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", + at = @At("HEAD"), remap = false) + public void beforePerformBuild(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable cir) { + // Set up our rendering context + TerrainRenderContext.get(buildContext).prepare(buildContext); + } + + @Inject(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", + at = @At("RETURN"), remap = false) + public void afterPerformBuild(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable cir) { + // Tear down our rendering context + TerrainRenderContext.get(buildContext).release(); + } + + @Redirect(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", + at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;renderModel(Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderContext;Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildBuffers;)V", remap = false), remap = false) + public void onRenderBlock(BlockRenderer blockRenderer, BlockRenderContext ctx, ChunkBuildBuffers buffers, ChunkBuildContext buildContext, CancellationToken cancellationToken) { + // We need to get the model with a bit more context than BlockRenderer has, so we do it here + if (Indium.ALWAYS_TESSELLATE_INDIUM || !ctx.model().isVanillaAdapter()) { + TerrainRenderContext.get(buildContext).tessellateBlock(ctx); + } else { + blockRenderer.renderModel(ctx, buffers); + } + } +} diff --git a/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java b/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java deleted file mode 100644 index 214c09a..0000000 --- a/src/main/java/link/infra/indium/mixin/sodium/MixinChunkRenderRebuildTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package link.infra.indium.mixin.sodium; - -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; - -/** - * The main injection point into Sodium - here we stop Sodium from rendering FRAPI block models, and do it ourselves - */ -@Mixin(ChunkRenderRebuildTask.class) -public abstract class MixinChunkRenderRebuildTask extends ChunkRenderBuildTask { - @Inject(method = "performBuild", at = @At("HEAD"), remap = false) - public void beforePerformBuild(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable cir) { - // Set up our rendering context - TerrainRenderContext.get(buildContext).prepare(buildContext); - } - - @Inject(method = "performBuild", at = @At("RETURN"), remap = false) - public void afterPerformBuild(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable cir) { - // Tear down our rendering context - TerrainRenderContext.get(buildContext).release(); - } - - @Redirect(method = "performBuild", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;renderModel(Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderContext;Lme/jellysquid/mods/sodium/client/render/chunk/compile/buffers/ChunkModelBuilder;)Z", remap = false), remap = false) - public boolean onRenderBlock(BlockRenderer blockRenderer, BlockRenderContext ctx, ChunkModelBuilder buffers, ChunkBuildContext buildContext, CancellationSource cancellationSource) { - // We need to get the model with a bit more context than BlockRenderer has, so we do it here - if (Indium.ALWAYS_TESSELLATE_INDIUM || !ctx.model().isVanillaAdapter()) { - return TerrainRenderContext.get(buildContext).tessellateBlock(ctx); - } - - return blockRenderer.renderModel(ctx, buffers); - } -} diff --git a/src/main/java/link/infra/indium/renderer/accessor/AccessBlockRenderCache.java b/src/main/java/link/infra/indium/renderer/accessor/AccessBlockRenderCache.java index f6492de..9e77fd8 100644 --- a/src/main/java/link/infra/indium/renderer/accessor/AccessBlockRenderCache.java +++ b/src/main/java/link/infra/indium/renderer/accessor/AccessBlockRenderCache.java @@ -1,7 +1,7 @@ package link.infra.indium.renderer.accessor; import link.infra.indium.renderer.render.TerrainRenderContext; -import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache; +import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache; public interface AccessBlockRenderCache { ArrayLightDataCache indium$getLightDataCache(); diff --git a/src/main/java/link/infra/indium/renderer/aocalc/AoCalculator.java b/src/main/java/link/infra/indium/renderer/aocalc/AoCalculator.java index 896f6f2..aa6c12e 100644 --- a/src/main/java/link/infra/indium/renderer/aocalc/AoCalculator.java +++ b/src/main/java/link/infra/indium/renderer/aocalc/AoCalculator.java @@ -22,7 +22,7 @@ import static link.infra.indium.renderer.helper.GeometryHelper.LIGHT_FACE_FLAG; import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackAO; import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackFO; -import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackLM; +import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.getLightmap; import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackOP; import static net.minecraft.util.math.Direction.DOWN; import static net.minecraft.util.math.Direction.EAST; @@ -366,23 +366,23 @@ private void computeFace(AoFaceData result, Direction lightFace, boolean isOnBlo // direction of the light face, but it was actually mis-sampling and causing // visible artifacts in certain situations - final long word0 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0]); - final int light0 = unpackLM(word0); + final int word0 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0]); + final int light0 = getLightmap(word0); final float ao0 = unpackAO(word0); final boolean isClear0 = unpackOP(word0); - final long word1 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1]); - final int light1 = unpackLM(word1); + final int word1 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1]); + final int light1 = getLightmap(word1); final float ao1 = unpackAO(word1); final boolean isClear1 = unpackOP(word1); - final long word2 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[2]); - final int light2 = unpackLM(word2); + final int word2 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[2]); + final int light2 = getLightmap(word2); final float ao2 = unpackAO(word2); final boolean isClear2 = unpackOP(word2); - final long word3 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[3]); - final int light3 = unpackLM(word3); + final int word3 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[3]); + final int light3 = getLightmap(word3); final float ao3 = unpackAO(word3); final boolean isClear3 = unpackOP(word3); @@ -397,48 +397,48 @@ private void computeFace(AoFaceData result, Direction lightFace, boolean isOnBlo cAo0 = ao0; cLight0 = light0; } else { - final long word02 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[2]); + final int word02 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[2]); cAo0 = unpackAO(word02); - cLight0 = unpackLM(word02); + cLight0 = getLightmap(word02); } if (!isClear3 && !isClear0) { cAo1 = ao0; cLight1 = light0; } else { - final long word03 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[3]); + final int word03 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[3]); cAo1 = unpackAO(word03); - cLight1 = unpackLM(word03); + cLight1 = getLightmap(word03); } if (!isClear2 && !isClear1) { cAo2 = ao1; cLight2 = light1; } else { - final long word12 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[2]); + final int word12 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[2]); cAo2 = unpackAO(word12); - cLight2 = unpackLM(word12); + cLight2 = getLightmap(word12); } if (!isClear3 && !isClear1) { cAo3 = ao1; cLight3 = light1; } else { - final long word13 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[3]); + final int word13 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[3]); cAo3 = unpackAO(word13); - cLight3 = unpackLM(word13); + cLight3 = getLightmap(word13); } - long centerWord = cache.get(lightPosX, lightPosY, lightPosZ); + int centerWord = cache.get(lightPosX, lightPosY, lightPosZ); // If on block face or neighbor isn't occluding, "center" will be neighbor brightness // Doesn't use light pos because logic not based solely on this block's geometry int lightCenter; if (isOnBlockFace || !unpackFO(centerWord)) { - lightCenter = unpackLM(centerWord); + lightCenter = getLightmap(centerWord); } else { - lightCenter = unpackLM(cache.get(x, y, z)); + lightCenter = getLightmap(cache.get(x, y, z)); } float aoCenter = unpackAO(centerWord); diff --git a/src/main/java/link/infra/indium/renderer/render/AbstractBlockRenderContext.java b/src/main/java/link/infra/indium/renderer/render/AbstractBlockRenderContext.java index 16256b3..ae8178d 100644 --- a/src/main/java/link/infra/indium/renderer/render/AbstractBlockRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/AbstractBlockRenderContext.java @@ -21,6 +21,8 @@ import java.util.List; +import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials; +import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; import org.jetbrains.annotations.Nullable; import link.infra.indium.renderer.IndiumRenderer; @@ -64,7 +66,7 @@ public void emitDirectly() { private final BlockPos.Mutable lightPos = new BlockPos.Mutable(); - protected abstract void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer); + protected abstract void bufferQuad(MutableQuadViewImpl quad, Material material); @Override public QuadEmitter getEmitter() { @@ -92,10 +94,11 @@ private void renderQuad(MutableQuadViewImpl quad, boolean isVanilla) { final boolean ao = blockInfo.useAo && (aoMode == TriState.TRUE || (aoMode == TriState.DEFAULT && blockInfo.defaultAo)); final boolean emissive = mat.emissive(); final RenderLayer renderLayer = blockInfo.effectiveRenderLayer(mat.blendMode()); + final Material sodiumMaterial = DefaultMaterials.forRenderLayer(renderLayer); colorizeQuad(quad, colorIndex); shadeQuad(quad, isVanilla, ao, emissive); - bufferQuad(quad, renderLayer); + bufferQuad(quad, sodiumMaterial); } /** handles block color, common to all renders. */ 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 c263d86..871227d 100644 --- a/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java @@ -18,8 +18,8 @@ import link.infra.indium.renderer.aocalc.AoCalculator; import link.infra.indium.renderer.mesh.MutableQuadViewImpl; +import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; import net.minecraft.block.BlockState; -import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.util.math.MatrixStack; @@ -40,7 +40,7 @@ public NonTerrainBlockRenderContext() { } @Override - protected void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer) { + protected void bufferQuad(MutableQuadViewImpl quad, Material material) { bufferQuad(quad, vertexConsumer); } diff --git a/src/main/java/link/infra/indium/renderer/render/SingleBlockLightDataCache.java b/src/main/java/link/infra/indium/renderer/render/SingleBlockLightDataCache.java index bf186c6..d3f81fa 100644 --- a/src/main/java/link/infra/indium/renderer/render/SingleBlockLightDataCache.java +++ b/src/main/java/link/infra/indium/renderer/render/SingleBlockLightDataCache.java @@ -2,7 +2,7 @@ import java.util.Arrays; -import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache; +import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache; import me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockRenderView; @@ -17,12 +17,12 @@ public class SingleBlockLightDataCache extends LightDataAccess { private static final int NEIGHBOR_BLOCK_RADIUS = 2; private static final int BLOCK_LENGTH = 1 + (NEIGHBOR_BLOCK_RADIUS * 2); - private final long[] light; + private final int[] light; private int xOffset, yOffset, zOffset; public SingleBlockLightDataCache() { - this.light = new long[BLOCK_LENGTH * BLOCK_LENGTH * BLOCK_LENGTH]; + this.light = new int[BLOCK_LENGTH * BLOCK_LENGTH * BLOCK_LENGTH]; } public void reset(BlockPos origin, BlockRenderView blockView) { @@ -30,7 +30,7 @@ public void reset(BlockPos origin, BlockRenderView blockView) { this.yOffset = origin.getY() - NEIGHBOR_BLOCK_RADIUS; this.zOffset = origin.getZ() - NEIGHBOR_BLOCK_RADIUS; - Arrays.fill(this.light, 0L); + Arrays.fill(this.light, 0); this.world = blockView; } @@ -44,10 +44,10 @@ private int index(int x, int y, int z) { } @Override - public long get(int x, int y, int z) { + public int get(int x, int y, int z) { int l = this.index(x, y, z); - long word = this.light[l]; + int word = this.light[l]; if (word != 0) { return word; 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 8a8e97c..9b17138 100644 --- a/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java +++ b/src/main/java/link/infra/indium/renderer/render/TerrainBlockRenderInfo.java @@ -16,7 +16,7 @@ package link.infra.indium.renderer.render; -import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache; import net.minecraft.util.math.Direction; public class TerrainBlockRenderInfo extends BlockRenderInfo { 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 693f352..be27cdd 100644 --- a/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/TerrainRenderContext.java @@ -1,27 +1,23 @@ package link.infra.indium.renderer.render; -import org.joml.Vector3fc; - import link.infra.indium.mixin.sodium.AccessBlockRenderer; import link.infra.indium.other.SpriteFinderCache; import link.infra.indium.renderer.accessor.AccessBlockRenderCache; import link.infra.indium.renderer.aocalc.AoCalculator; import link.infra.indium.renderer.mesh.MutableQuadViewImpl; -import me.jellysquid.mods.sodium.client.gl.compile.ChunkBuildContext; -import me.jellysquid.mods.sodium.client.model.IndexBufferBuilder; -import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache; +import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache; import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing; import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadOrientation; -import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadWinding; import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; +import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildContext; import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache; 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.render.vertex.type.ChunkVertexEncoder; -import me.jellysquid.mods.sodium.client.util.color.ColorARGB; +import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; import me.jellysquid.mods.sodium.client.world.WorldSlice; -import net.minecraft.client.render.RenderLayer; +import net.caffeinemc.mods.sodium.api.util.ColorARGB; import net.minecraft.client.texture.Sprite; import net.minecraft.util.crash.CrashException; import net.minecraft.util.crash.CrashReport; @@ -29,12 +25,12 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.random.LocalRandom; +import org.joml.Vector3fc; public class TerrainRenderContext extends AbstractBlockRenderContext { private final ChunkVertexEncoder.Vertex[] vertices = ChunkVertexEncoder.Vertex.uninitializedQuad(); private ChunkBuildBuffers buffers; - private boolean didOutput = false; private Vector3fc origin; private Vec3d modelOffset; @@ -55,12 +51,11 @@ public static TerrainRenderContext get(ChunkBuildContext buildContext) { } @Override - protected void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer) { - didOutput = true; - ChunkModelBuilder builder = buffers.get(renderLayer); + protected void bufferQuad(MutableQuadViewImpl quad, Material material) { + ChunkModelBuilder builder = buffers.get(material); Direction cullFace = quad.cullFace(); - IndexBufferBuilder indexBuffer = builder.getIndexBuffer(cullFace != null ? ModelQuadFacing.fromDirection(cullFace) : ModelQuadFacing.UNASSIGNED); + var vertexBuffer = builder.getVertexBuffer(cullFace != null ? ModelQuadFacing.fromDirection(cullFace) : ModelQuadFacing.UNASSIGNED); Vector3fc origin = this.origin; Vec3d modelOffset = this.modelOffset; @@ -85,7 +80,7 @@ protected void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer) { out.light = quad.lightmap(srcIndex); } - indexBuffer.add(builder.getVertexBuffer().push(vertices), ModelQuadWinding.CLOCKWISE); + vertexBuffer.push(vertices, material); Sprite sprite = quad.cachedSprite(); @@ -101,8 +96,8 @@ protected void shadeQuad(MutableQuadViewImpl quad, boolean isVanilla, boolean ao super.shadeQuad(quad, isVanilla, ao, emissive); if (ao) { - // Assumes aoCalc.ao holds the correct values for the current quad. - quad.orientation(ModelQuadOrientation.orientByBrightness(aoCalc.ao)); + // Assumes aoCalc.ao / aoCalc.light holds the correct values for the current quad. + quad.orientation(ModelQuadOrientation.orientByBrightness(aoCalc.ao, aoCalc.light)); } else { // When using flat lighting, Sodium makes all quads use the flipped orientation. quad.orientation(ModelQuadOrientation.FLIP); @@ -120,12 +115,11 @@ public void release() { } /** Called from chunk renderer hook. */ - public boolean tessellateBlock(BlockRenderContext ctx) { + public void tessellateBlock(BlockRenderContext ctx) { try { this.origin = ctx.origin(); this.modelOffset = ctx.state().getModelOffset(ctx.world(), ctx.pos()); - didOutput = false; aoCalc.clear(); blockInfo.prepareForBlock(ctx.state(), ctx.pos(), ctx.seed(), ctx.model().useAmbientOcclusion()); ctx.model().emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this); @@ -135,7 +129,5 @@ public boolean tessellateBlock(BlockRenderContext ctx) { CrashReportSection.addBlockInfo(crashReportSection, ctx.world(), ctx.pos(), ctx.state()); throw new CrashException(crashReport); } - - return didOutput; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 595b743..9d9570e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "depends": { "fabricloader": ">=0.8.0", "minecraft": "~1.20.1", - "sodium": "0.4.10", + "sodium": "0.5.0", "fabric-renderer-api-v1": ">=3.1.0", "fabric-resource-loader-v0": ">=0.4.0" } diff --git a/src/main/resources/indium.mixins.json b/src/main/resources/indium.mixins.json index 5d94b2c..0cd08ec 100644 --- a/src/main/resources/indium.mixins.json +++ b/src/main/resources/indium.mixins.json @@ -8,7 +8,7 @@ "renderer.MixinItemRenderer", "sodium.AccessBlockRenderer", "sodium.MixinBlockRenderCache", - "sodium.MixinChunkRenderRebuildTask" + "sodium.MixinChunkBuilderMeshingTask" ], "injectors": { "defaultRequire": 1