diff --git a/.gitignore b/.gitignore index ccb0c56..4f340a1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ out/ output/ bin/ libs/ +.architectury-transformer/ .classpath .project diff --git a/common/build.gradle b/common/build.gradle index 8795389..e249a2f 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -14,9 +14,10 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" modCompileOnlyApi "maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric" + modCompileOnlyApi "maven.modrinth:sodium:${rootProject.sodium_version}" // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury:${rootProject.architectury_version}" + //modApi "dev.architectury:architectury:${rootProject.architectury_version}" } publishing { 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 14786e9..3d8a59a 100755 --- a/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java +++ b/common/src/main/java/eu/midnightdust/cullleaves/config/CullLeavesConfig.java @@ -5,4 +5,6 @@ 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; } diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java new file mode 100644 index 0000000..5e4f2be --- /dev/null +++ b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinRegionChunkRenderer.java @@ -0,0 +1,46 @@ +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.model.vertex.type.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.*; +import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +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 java.util.List; + +@Mixin(value = RegionChunkRenderer.class, remap = false) +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; + + public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) { + super(device, 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; + } + @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); + } + } + return state.getModelPart(ModelQuadFacing.UNASSIGNED); + } +} diff --git a/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java new file mode 100644 index 0000000..1997903 --- /dev/null +++ b/common/src/main/java/eu/midnightdust/cullleaves/mixin/MixinSodiumGameOptionPages.java @@ -0,0 +1,45 @@ +package eu.midnightdust.cullleaves.mixin; + +import eu.midnightdust.cullleaves.config.CullLeavesConfig; +import me.jellysquid.mods.sodium.client.gui.SodiumGameOptionPages; +import me.jellysquid.mods.sodium.client.gui.options.OptionFlag; +import me.jellysquid.mods.sodium.client.gui.options.OptionGroup; +import me.jellysquid.mods.sodium.client.gui.options.OptionImpact; +import me.jellysquid.mods.sodium.client.gui.options.OptionImpl; +import me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl; +import me.jellysquid.mods.sodium.client.gui.options.storage.SodiumOptionsStorage; +import net.minecraft.text.Text; +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.ModifyVariable; + +import java.util.List; + +@Mixin(value = SodiumGameOptionPages.class, remap = false) +public class MixinSodiumGameOptionPages { + + @Shadow @Final private static SodiumOptionsStorage sodiumOpts; + + @ModifyVariable(method = "performance", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;")) + private static List cullleaves$addCullLeavesOption(List groups) { + groups.add(OptionGroup.createBuilder() + .add(OptionImpl.createBuilder(boolean.class, sodiumOpts) + .setName(Text.translatable("cullleaves.midnightconfig.enabled")) + .setTooltip(Text.translatable("cullleaves.midnightconfig.enabled.tooltip.sodium")) + .setControl(TickBoxControl::new) + .setBinding((opts, value) -> { + CullLeavesConfig.enabled = value; + CullLeavesConfig.write("cullleaves"); + }, opts -> CullLeavesConfig.enabled) + .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) + .setImpact(OptionImpact.MEDIUM) + .build() + ) + .build() + ); + + return groups; + } +} 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 2f284ab..f113df1 100755 --- a/common/src/main/resources/assets/cullleaves/lang/en_us.json +++ b/common/src/main/resources/assets/cullleaves/lang/en_us.json @@ -1,5 +1,8 @@ { "cullleaves.midnightconfig.title":"Cull Leaves Config", - "cullleaves.midnightconfig.enabled.tooltip":"After changing this setting you have to reload all chunks (F3 + A)", - "cullleaves.midnightconfig.enabled":"Enabled" + "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" } \ No newline at end of file diff --git a/common/src/main/resources/assets/cullleaves/lang/pt_br.json b/common/src/main/resources/assets/cullleaves/lang/pt_br.json index 05419a2..3ade672 100644 --- a/common/src/main/resources/assets/cullleaves/lang/pt_br.json +++ b/common/src/main/resources/assets/cullleaves/lang/pt_br.json @@ -1,5 +1,5 @@ { "cullleaves.midnightconfig.title":"Definições do Cull Leaves", "cullleaves.midnightconfig.enabled.tooltip":"Recarregue os chunks (F3 + A) ao alterar essa opção", - "cullleaves.midnightconfig.enabled":"Ativado" + "cullleaves.midnightconfig.enabled":"Ativado Cull Leaves" } diff --git a/common/src/main/resources/assets/cullleaves/lang/ru_ru.json b/common/src/main/resources/assets/cullleaves/lang/ru_ru.json index 2ffa5ec..25e3826 100644 --- a/common/src/main/resources/assets/cullleaves/lang/ru_ru.json +++ b/common/src/main/resources/assets/cullleaves/lang/ru_ru.json @@ -1,5 +1,5 @@ { "cullleaves.midnightconfig.title":"Настройки Cull Leaves", "cullleaves.midnightconfig.enabled.tooltip":"После изменения этого параметра необходимо перезагрузить чанки (F3 + A)", - "cullleaves.midnightconfig.enabled":"Включён" + "cullleaves.midnightconfig.enabled":"Включён Cull Leaves" } diff --git a/common/src/main/resources/cullleaves.mixins.json b/common/src/main/resources/cullleaves.mixins.json index 19cd774..2224a3f 100644 --- a/common/src/main/resources/cullleaves.mixins.json +++ b/common/src/main/resources/cullleaves.mixins.json @@ -2,10 +2,11 @@ "required": true, "package": "eu.midnightdust.cullleaves.mixin", "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", "client": [ - "MixinLeavesBlock" - ], - "mixins": [ + "MixinLeavesBlock", + "MixinRegionChunkRenderer", + "MixinSodiumGameOptionPages" ], "injectors": { "defaultRequire": 1 diff --git a/fabric-like/src/main/resources/resourcepacks/smartleaves/assets/minecraft/models/block/leaves.json b/common/src/main/resources/resourcepacks/smartleaves/assets/minecraft/models/block/leaves.json similarity index 100% rename from fabric-like/src/main/resources/resourcepacks/smartleaves/assets/minecraft/models/block/leaves.json rename to common/src/main/resources/resourcepacks/smartleaves/assets/minecraft/models/block/leaves.json diff --git a/fabric-like/src/main/resources/resourcepacks/smartleaves/license.txt b/common/src/main/resources/resourcepacks/smartleaves/license.txt similarity index 96% rename from fabric-like/src/main/resources/resourcepacks/smartleaves/license.txt rename to common/src/main/resources/resourcepacks/smartleaves/license.txt index 375aefc..ca22179 100755 --- a/fabric-like/src/main/resources/resourcepacks/smartleaves/license.txt +++ b/common/src/main/resources/resourcepacks/smartleaves/license.txt @@ -1,5 +1,5 @@ The MIT License -Copyright © 2020 Motschen +Copyright © 2022 Motschen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, diff --git a/common/src/main/resources/resourcepacks/smartleaves/pack.mcmeta b/common/src/main/resources/resourcepacks/smartleaves/pack.mcmeta new file mode 100755 index 0000000..1d9f719 --- /dev/null +++ b/common/src/main/resources/resourcepacks/smartleaves/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 9, + "description": "§2Makes leaves look identical to OptiFine's smart leaves" + } +} diff --git a/fabric-like/src/main/resources/resourcepacks/smartleaves/pack.png b/common/src/main/resources/resourcepacks/smartleaves/pack.png similarity index 100% rename from fabric-like/src/main/resources/resourcepacks/smartleaves/pack.png rename to common/src/main/resources/resourcepacks/smartleaves/pack.png diff --git a/fabric-like/build.gradle b/fabric-like/build.gradle index e73e3f4..5f1e660 100644 --- a/fabric-like/build.gradle +++ b/fabric-like/build.gradle @@ -10,7 +10,7 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" + //modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" compileClasspath(project(path: ":common", configuration: "namedElements")) { transitive false } } diff --git a/fabric-like/src/main/resources/resourcepacks/smartleaves/pack.mcmeta b/fabric-like/src/main/resources/resourcepacks/smartleaves/pack.mcmeta deleted file mode 100755 index f4bad40..0000000 --- a/fabric-like/src/main/resources/resourcepacks/smartleaves/pack.mcmeta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "pack": { - "pack_format": 9, - "description": "§2Makes leaves look identical to optifine's smart leaves" - } -} diff --git a/fabric/build.gradle b/fabric/build.gradle index 1b86738..2a59bb9 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -20,6 +20,7 @@ configurations { compileClasspath.extendsFrom common runtimeClasspath.extendsFrom common developmentFabric.extendsFrom common + archivesBaseName = rootProject.archives_base_name + "-fabric" } dependencies { diff --git a/forge/build.gradle b/forge/build.gradle index 941f077..e029a09 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -23,6 +23,7 @@ configurations { compileClasspath.extendsFrom common runtimeClasspath.extendsFrom common developmentForge.extendsFrom common + archivesBaseName = rootProject.archives_base_name + "-forge" } dependencies { diff --git a/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientEvents.java b/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientEvents.java new file mode 100644 index 0000000..acb60c8 --- /dev/null +++ b/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientEvents.java @@ -0,0 +1,33 @@ +package eu.midnightdust.cullleaves.forge; + +import net.minecraft.resource.*; +import net.minecraft.resource.metadata.PackResourceMetadata; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.event.AddPackFindersEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.forgespi.locating.IModFile; +import net.minecraftforge.resource.PathPackResources; + +import java.io.IOException; + +@Mod.EventBusSubscriber(modid = "cullleaves", bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) +public class CullLeavesClientEvents { + @SubscribeEvent + public static void addPackFinders(AddPackFindersEvent event) { + if (event.getPackType() == ResourceType.CLIENT_RESOURCES) { + registerResourcePack(event, new Identifier("cullleaves", "smartleaves"), false); + } + } + private static void registerResourcePack(AddPackFindersEvent event, Identifier id, boolean alwaysEnabled) { + event.addRepositorySource(((profileAdder, factory) -> { + IModFile file = ModList.get().getModFileById(id.getNamespace()).getFile(); + try (PathPackResources pack = new PathPackResources(id.toString(), file.findResource("resourcepacks/"+id.getPath()))) { + profileAdder.accept(new ResourcePackProfile(id.toString(), alwaysEnabled, () -> pack, Text.of(id.getNamespace()+"/"+id.getPath()), pack.parseMetadata(PackResourceMetadata.READER).getDescription().copy().append(" §7(built-in)"), ResourcePackCompatibility.COMPATIBLE, ResourcePackProfile.InsertionPosition.TOP, false, ResourcePackSource.PACK_SOURCE_BUILTIN, false)); + } catch (IOException | NullPointerException e) {e.printStackTrace();} + })); + } +} diff --git a/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientForge.java b/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientForge.java index 27da0c3..a982f39 100644 --- a/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientForge.java +++ b/forge/src/main/java/eu/midnightdust/cullleaves/forge/CullLeavesClientForge.java @@ -3,14 +3,19 @@ import eu.midnightdust.cullleaves.config.CullLeavesConfig; import eu.midnightdust.lib.config.MidnightConfig; import net.minecraftforge.client.ConfigScreenHandler; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.IExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.network.NetworkConstants; @Mod("cullleaves") public class CullLeavesClientForge { public CullLeavesClientForge() { MidnightConfig.init("cullleaves", CullLeavesConfig.class); + ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (remote, server) -> true)); ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, "cullleaves"))); + MinecraftForge.EVENT_BUS.register(new CullLeavesClientEvents()); } } \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 7638c79..34502cd 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,7 +1,7 @@ modLoader = "javafml" loaderVersion = "[43,)" #issueTrackerURL = "" -license = "MIT" +license = "MIT License" [[mods]] modId = "cullleaves" diff --git a/gradle.properties b/gradle.properties index 9f9b861..68bd165 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,7 @@ maven_group=eu.midnightdust architectury_version=6.2.43 midnightlib_version=1.0.0 +sodium_version=mc1.19.2-0.4.4 fabric_loader_version=0.14.9 fabric_api_version=0.59.0+1.19.2 diff --git a/quilt/build.gradle b/quilt/build.gradle index d8f28aa..474e69b 100644 --- a/quilt/build.gradle +++ b/quilt/build.gradle @@ -22,6 +22,7 @@ configurations { compileClasspath.extendsFrom common runtimeClasspath.extendsFrom common developmentQuilt.extendsFrom common + archivesBaseName = rootProject.archives_base_name + "-quilt" } dependencies { diff --git a/quilt/src/main/resources/quilt.mod.json b/quilt/src/main/resources/quilt.mod.json index ad6d33b..545cf04 100644 --- a/quilt/src/main/resources/quilt.mod.json +++ b/quilt/src/main/resources/quilt.mod.json @@ -18,7 +18,7 @@ "license": "MIT", "icon": "assets/cullleaves/icon.png", "intermediate_mappings": "net.fabricmc:intermediary", - "environment": "*", + "environment": "client", "entrypoints": { "client_init": [ "eu.midnightdust.cullleaves.quilt.CullLeavesClientQuilt" @@ -40,6 +40,7 @@ ], "metadata": { "name": "Cull Leaves (Quilt)", + "description": "Adds culling to leaf blocks, providing a huge performance boost over vanilla.", "contributors": { "Motschen": "Author", "TeamMidnightDust": "Mascot"