diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java index 5e4f2be..d5eca39 100644 --- a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java +++ b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java @@ -6,6 +6,7 @@ import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing; import me.jellysquid.mods.sodium.client.model.vertex.type.ChunkVertexType; import me.jellysquid.mods.sodium.client.render.chunk.*; +import me.jellysquid.mods.sodium.client.render.chunk.data.ChunkRenderBounds; import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -18,11 +19,13 @@ import java.util.List; -@Mixin(value = RegionChunkRenderer.class, remap = false) +@Mixin(value = RegionChunkRenderer.class, remap = false, priority = 1100) public abstract class MixinRegionChunkRenderer extends ShaderChunkRenderer { @Shadow @Final private boolean isBlockFaceCullingEnabled; @Shadow protected abstract void addDrawCall(ElementRange part, long baseIndexPointer, int baseVertexIndex); @Unique private boolean doFix = false; + @Unique private ChunkCameraContext camera; + @Unique private ChunkRenderBounds bounds; public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) { super(device, vertexType); @@ -31,14 +34,37 @@ public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) @Inject(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;getBounds()Lme/jellysquid/mods/sodium/client/render/chunk/data/ChunkRenderBounds;", ordinal = 0)) public void cullleaves$shouldApplyTransparentBlockFaceCullingFix(List sections, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfoReturnable cir) { doFix = pass.getAlphaCutoff() != 0 && CullLeavesConfig.enabled && CullLeavesConfig.sodiumBlockFaceCullingFix && this.isBlockFaceCullingEnabled; + this.camera = camera; + } + @Redirect(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;getBounds()Lme/jellysquid/mods/sodium/client/render/chunk/data/ChunkRenderBounds;", ordinal = 0)) + public ChunkRenderBounds cullleaves$getChunkRenderBounds(RenderSection instance) { + bounds = instance.getBounds(); + return bounds; } @Redirect(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ChunkGraphicsState;getModelPart(Lme/jellysquid/mods/sodium/client/model/quad/properties/ModelQuadFacing;)Lme/jellysquid/mods/sodium/client/gl/util/ElementRange;", ordinal = 0)) public ElementRange cullleaves$fixTransparentBlockFaceCulling(ChunkGraphicsState state, ModelQuadFacing facing) { if (doFix) { long indexOffset = state.getIndexSegment().getOffset(); int baseVertex = state.getVertexSegment().getOffset() / this.vertexFormat.getStride(); - for (ModelQuadFacing direction : ModelQuadFacing.DIRECTIONS) { - this.addDrawCall(state.getModelPart(direction), indexOffset, baseVertex); + if (this.isBlockFaceCullingEnabled) { + if (camera.posY <= bounds.y1) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.UP), indexOffset, baseVertex); + } + if (camera.posY >= bounds.y2) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.DOWN), indexOffset, baseVertex); + } + if (camera.posX <= bounds.x1) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.EAST), indexOffset, baseVertex); + } + if (camera.posX >= bounds.x2) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.WEST), indexOffset, baseVertex); + } + if (camera.posZ <= bounds.z1) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.SOUTH), indexOffset, baseVertex); + } + if (camera.posZ >= bounds.z2) { + this.addDrawCall(state.getModelPart(ModelQuadFacing.NORTH), indexOffset, baseVertex); + } } } return state.getModelPart(ModelQuadFacing.UNASSIGNED); diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 34502cd..adbc11d 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -31,5 +31,5 @@ side = "CLIENT" modId = "midnightlib" mandatory = true versionRange = "[1.0.0,)" -ordering = "NONE" +ordering = "BEFORE" side = "CLIENT" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 68bd165..07ba7a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.19.2 enabled_platforms=quilt,fabric,forge archives_base_name=cullleaves -mod_version=3.0.0 +mod_version=3.0.1 maven_group=eu.midnightdust architectury_version=6.2.43