From 41efe55ea68f858db0618b2683e301f34fea9a8b Mon Sep 17 00:00:00 2001 From: Motschen Date: Thu, 24 Aug 2023 15:40:01 +0200 Subject: [PATCH] CullLeaves 3.2.0 - Mangrove Root Culling & Sodium fix - Added an option to cull Mangrove Roots (closes #47) - Fixed incompatibility with Sodium by removing a now obsolete feature - Add German translation by myself --- .../cullleaves/config/CullLeavesConfig.java | 4 +- .../mixin/MixinMangroveRootsBlock.java | 26 +++++++++ .../mixin/MixinRegionChunkRenderer.java | 54 ------------------- .../mixin/MixinSodiumGameOptionPages.java | 11 ++++ .../assets/cullleaves/lang/de_de.json | 9 ++++ .../assets/cullleaves/lang/en_us.json | 5 +- .../src/main/resources/cullleaves.mixins.json | 2 +- fabric/build.gradle | 1 + gradle.properties | 4 +- 9 files changed, 55 insertions(+), 61 deletions(-) create mode 100755 common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinMangroveRootsBlock.java delete mode 100644 common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java create mode 100755 common/src/main/resources/assets/cullleaves/lang/de_de.json diff --git a/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java b/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java index 3d8a59a..605069f 100755 --- a/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java +++ b/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java @@ -5,6 +5,6 @@ import eu.midnightdust.lib.config.MidnightConfig; public class CullLeavesConfig extends MidnightConfig { @Entry // Enable/Disable the mod. Requires Chunk Reload (F3 + A). public static boolean enabled = true; - @Entry // Fixes resourcepacks utilizing leaf culling flickering when using Sodium - public static boolean sodiumBlockFaceCullingFix = true; + @Entry // Enable/Disable culling on Mangrove Roots. + public static boolean cullRoots = true; } diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinMangroveRootsBlock.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinMangroveRootsBlock.java new file mode 100755 index 0000000..adecbc9 --- /dev/null +++ b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinMangroveRootsBlock.java @@ -0,0 +1,26 @@ +package eu.midnightdust.cullleaves.mixin; + +import eu.midnightdust.cullleaves.config.CullLeavesConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.*; +import net.minecraft.util.math.Direction; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(value = MangroveRootsBlock.class, priority = 1900) +@Environment(EnvType.CLIENT) +public abstract class MixinMangroveRootsBlock extends Block { + + public MixinMangroveRootsBlock(Settings settings) { + super(settings); + } + + @Override + @SuppressWarnings("deprecation") + public boolean isSideInvisible(BlockState state, BlockState neighborState, Direction offset) { + if (CullLeavesConfig.cullRoots) { + return neighborState.getBlock() instanceof MangroveRootsBlock; + } + else return false; + } +} \ No newline at end of file diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java deleted file mode 100644 index 3aa8571..0000000 --- a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java +++ /dev/null @@ -1,54 +0,0 @@ -package eu.midnightdust.cullleaves.mixin; - -import eu.midnightdust.cullleaves.config.CullLeavesConfig; -import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; -import me.jellysquid.mods.sodium.client.gl.util.ElementRange; -import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing; -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 me.jellysquid.mods.sodium.client.render.vertex.type.ChunkVertexType; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.Iterator; -import java.util.List; - -@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); - - public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) { - super(device, vertexType); - } - - @Inject(method = "buildDrawBatches", locals = LocalCapture.CAPTURE_FAILSOFT, 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 void cullleaves$fixTransparentBlockFaceCulling(List sections, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfoReturnable cir, Iterator var4, RenderSection render, ChunkGraphicsState state, ChunkRenderBounds bounds, long indexOffset, int baseVertex) { - if (pass.getAlphaCutoff() != 0 && CullLeavesConfig.enabled && CullLeavesConfig.sodiumBlockFaceCullingFix && 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); - } - } - } -} diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java index 1997903..3b184fa 100644 --- a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java +++ b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java @@ -36,6 +36,17 @@ public class MixinSodiumGameOptionPages { .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) .setImpact(OptionImpact.MEDIUM) .build() + ).add(OptionImpl.createBuilder(boolean.class, sodiumOpts) + .setName(Text.translatable("cullleaves.midnightconfig.cullRoots")) + .setTooltip(Text.translatable("cullleaves.midnightconfig.cullRoots.tooltip.sodium")) + .setControl(TickBoxControl::new) + .setBinding((opts, value) -> { + CullLeavesConfig.cullRoots = value; + CullLeavesConfig.write("cullleaves"); + }, opts -> CullLeavesConfig.cullRoots) + .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) + .setImpact(OptionImpact.MEDIUM) + .build() ) .build() ); diff --git a/common/src/main/resources/assets/cullleaves/lang/de_de.json b/common/src/main/resources/assets/cullleaves/lang/de_de.json new file mode 100755 index 0000000..45582cb --- /dev/null +++ b/common/src/main/resources/assets/cullleaves/lang/de_de.json @@ -0,0 +1,9 @@ +{ + "cullleaves.midnightconfig.title":"Cull Leaves Konfiguration", + "cullleaves.midnightconfig.enabled.tooltip":"Aktiviert Culling bei Blättern, was zu besserer Performance führt.\n§cNach dem Ändern dieser Option müssen alle Chunks neugeladen werden (F3 + A)", + "cullleaves.midnightconfig.enabled.tooltip.sodium":"Aktiviert Culling bei Blättern, was zu besserer Performance führt.", + "cullleaves.midnightconfig.enabled":"Aktiviere Culling von Blättern", + "cullleaves.midnightconfig.cullRoots.tooltip":"Aktiviert Culling von Mangrovenwurzeln.\n§cNach dem Ändern dieser Option müssen alle Chunks neugeladen werden (F3 + A)", + "cullleaves.midnightconfig.cullRoots.tooltip.sodium":"Aktiviert Culling von Mangrovenwurzeln.", + "cullleaves.midnightconfig.cullRoots":"Culling von Mangrovenwurzeln" +} \ No newline at end of file diff --git a/common/src/main/resources/assets/cullleaves/lang/en_us.json b/common/src/main/resources/assets/cullleaves/lang/en_us.json index f113df1..63eb19e 100755 --- a/common/src/main/resources/assets/cullleaves/lang/en_us.json +++ b/common/src/main/resources/assets/cullleaves/lang/en_us.json @@ -3,6 +3,7 @@ "cullleaves.midnightconfig.enabled.tooltip":"Enables culling for leaves, providing a nice performance boost.\n§cAfter changing this setting you have to reload all chunks (F3 + A)", "cullleaves.midnightconfig.enabled.tooltip.sodium":"Enables culling for leaves, providing a nice performance boost", "cullleaves.midnightconfig.enabled":"Enable Leaf Culling", - "cullleaves.midnightconfig.sodiumBlockFaceCullingFix.tooltip": "Fixes resourcepacks utilizing leaf culling flickering when using Sodium.\nYou probably want this to be enabled.", - "cullleaves.midnightconfig.sodiumBlockFaceCullingFix": "Fix Sodium Block Face Culling on Leaves" + "cullleaves.midnightconfig.cullRoots.tooltip":"Enables culling for mangrove roots.\n§cAfter changing this setting you have to reload all chunks (F3 + A)", + "cullleaves.midnightconfig.cullRoots.tooltip.sodium":"Enables culling for mangrove roots.", + "cullleaves.midnightconfig.cullRoots":"Enable Mangrove Root Culling" } \ No newline at end of file diff --git a/common/src/main/resources/cullleaves.mixins.json b/common/src/main/resources/cullleaves.mixins.json index 2224a3f..0d01c5a 100644 --- a/common/src/main/resources/cullleaves.mixins.json +++ b/common/src/main/resources/cullleaves.mixins.json @@ -5,7 +5,7 @@ "minVersion": "0.8", "client": [ "MixinLeavesBlock", - "MixinRegionChunkRenderer", + "MixinMangroveRootsBlock", "MixinSodiumGameOptionPages" ], "injectors": { diff --git a/fabric/build.gradle b/fabric/build.gradle index 2a59bb9..c28f9ed 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -30,6 +30,7 @@ dependencies { //modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" modImplementation "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric" include "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric" + modRuntimeOnly "maven.modrinth:sodium:${rootProject.sodium_version}" common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } diff --git a/gradle.properties b/gradle.properties index 0d79c20..79f0034 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ yarn_mappings=1.20.1+build.9 enabled_platforms=quilt,fabric,forge archives_base_name=cullleaves -mod_version=3.1.0 +mod_version=3.2.0 maven_group=eu.midnightdust architectury_version=6.2.43 midnightlib_version=1.4.1 -sodium_version=mc1.20-0.4.10 +sodium_version=mc1.20.1-0.5.2 fabric_loader_version=0.14.21 fabric_api_version=0.85.0+1.20.1