From 3cfff04211daca610c79ed286dacf59c2181532f Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 1 Apr 2023 11:51:43 +0200 Subject: [PATCH] Fix sky rendering with render distance greater than 32 (fixes #152) --- CHANGELOG.md | 1 + .../bobby/mixin/BackgroundRendererMixin.java | 14 ++++++++++++++ .../minecraft/bobby/mixin/WorldRendererMixin.java | 14 ++++++++++++++ src/main/resources/bobby.mixins.json | 2 ++ 4 files changed, 31 insertions(+) create mode 100644 src/main/java/de/johni0702/minecraft/bobby/mixin/BackgroundRendererMixin.java create mode 100644 src/main/java/de/johni0702/minecraft/bobby/mixin/WorldRendererMixin.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a2a94..29a13fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### 4.0.6-SNAPSHOT +- Fix sky fog rendering incorrectly as render distance goes beyond 32 (#152) ### 4.0.5 - Fix unloading of block entities without "Disable Block Entities" (#142) diff --git a/src/main/java/de/johni0702/minecraft/bobby/mixin/BackgroundRendererMixin.java b/src/main/java/de/johni0702/minecraft/bobby/mixin/BackgroundRendererMixin.java new file mode 100644 index 0000000..6b66329 --- /dev/null +++ b/src/main/java/de/johni0702/minecraft/bobby/mixin/BackgroundRendererMixin.java @@ -0,0 +1,14 @@ +package de.johni0702.minecraft.bobby.mixin; + +import net.minecraft.client.render.BackgroundRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(BackgroundRenderer.class) +public abstract class BackgroundRendererMixin { + @ModifyVariable(method = "render", at = @At("HEAD"), argsOnly = true) + private static int clampMaxValue(int viewDistance) { + return Math.min(viewDistance, 32); + } +} diff --git a/src/main/java/de/johni0702/minecraft/bobby/mixin/WorldRendererMixin.java b/src/main/java/de/johni0702/minecraft/bobby/mixin/WorldRendererMixin.java new file mode 100644 index 0000000..4ef414f --- /dev/null +++ b/src/main/java/de/johni0702/minecraft/bobby/mixin/WorldRendererMixin.java @@ -0,0 +1,14 @@ +package de.johni0702.minecraft.bobby.mixin; + +import net.minecraft.client.render.WorldRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +@Mixin(WorldRenderer.class) +public abstract class WorldRendererMixin { + @ModifyArg(method = "method_37365", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BackgroundRenderer;applyFog(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/BackgroundRenderer$FogType;FZF)V"), index = 2) + private static float clampMaxValue(float viewDistance) { + return Math.min(viewDistance, 32 * 16); + } +} diff --git a/src/main/resources/bobby.mixins.json b/src/main/resources/bobby.mixins.json index 8e0fd1a..1bdf51b 100644 --- a/src/main/resources/bobby.mixins.json +++ b/src/main/resources/bobby.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_17", "plugin": "de.johni0702.minecraft.bobby.MixinConfigPlugin", "client": [ + "BackgroundRendererMixin", "BiomeAccessAccessor", "ChunkLightProviderMixin", "ClientChunkManagerMixin", @@ -16,6 +17,7 @@ "MinecraftClientMixin", "SimpleOptionAccessor", "ValidatingIntSliderCallbacksAccessor", + "WorldRendererMixin", "sodium.SodiumChunkManagerMixin", "sodium.SodiumClientPlayNetworkHandlerMixin", "sodium.SodiumGameOptionPagesMixin"