From 0afddb6a5d7ca96c13f87855db1a748be2198d16 Mon Sep 17 00:00:00 2001 From: Bogdan <64613894+Asek3@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:08:55 +0300 Subject: [PATCH] Fixed Leaves option --- .../leaves/MixinRenderLayers.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/features/render_layer/leaves/MixinRenderLayers.java b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render_layer/leaves/MixinRenderLayers.java index 6a707e81..44042fff 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/features/render_layer/leaves/MixinRenderLayers.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/features/render_layer/leaves/MixinRenderLayers.java @@ -7,15 +7,15 @@ import net.minecraft.block.Blocks; import net.minecraft.block.LeavesBlock; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.GraphicsMode; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayers; import net.minecraft.fluid.Fluid; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.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.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Map; @@ -42,11 +42,19 @@ public class MixinRenderLayers { FLUIDS = new Reference2ReferenceOpenHashMap<>(FLUIDS); } - @Inject(method = "getBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;", at = @At(value = "RETURN"), cancellable = true) - private static void redirectLeavesGraphics(BlockState state, CallbackInfoReturnable cir) { - if (state.getBlock() instanceof LeavesBlock) { - boolean fancyLeaves = SodiumClientMod.options().quality.leavesQuality.isFancy(MinecraftClient.getInstance().options.getGraphicsMode().getValue()); - cir.setReturnValue(fancyLeaves ? RenderLayer.getCutoutMipped() : RenderLayer.getSolid()); - } + + @Unique + private static boolean leavesFancy; + + @Redirect( + method = { "getBlockLayer", "getMovingBlockLayer", "getRenderLayers" }, + at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/RenderLayers;fancyGraphicsOrBetter:Z")) + private static boolean redirectLeavesShouldBeFancy() { + return leavesFancy; + } + + @Inject(method = "setFancyGraphicsOrBetter", at = @At("RETURN")) + private static void onSetFancyGraphicsOrBetter(boolean fancyGraphicsOrBetter, CallbackInfo ci) { + leavesFancy = SodiumClientMod.options().quality.leavesQuality.isFancy(fancyGraphicsOrBetter ? GraphicsMode.FANCY : GraphicsMode.FAST); } }