Skip to content

Commit

Permalink
Fixed Leaves option
Browse files Browse the repository at this point in the history
  • Loading branch information
Asek3 committed Sep 20, 2023
1 parent 698ebd6 commit 0afddb6
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<RenderLayer> 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);
}
}

0 comments on commit 0afddb6

Please sign in to comment.