|
| 1 | +package dev.isxander.debugify.client.mixins.basic.mc298558; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.expression.Definition; |
| 4 | +import com.llamalad7.mixinextras.expression.Expression; |
| 5 | +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; |
| 6 | +import com.llamalad7.mixinextras.sugar.Local; |
| 7 | +import dev.isxander.debugify.fixes.BugFix; |
| 8 | +import dev.isxander.debugify.fixes.FixCategory; |
| 9 | +import net.minecraft.client.renderer.fog.environment.AtmosphericFogEnvironment; |
| 10 | +import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.injection.At; |
| 12 | + |
| 13 | +@BugFix(id = "MC-298558", category = FixCategory.BASIC, env = BugFix.Env.CLIENT, description = "Rain fog calculation can overshoot while game is unresponsive") |
| 14 | +@Mixin(AtmosphericFogEnvironment.class) |
| 15 | +public class AtmosphericFogEnvironmentMixin { |
| 16 | + |
| 17 | + /** |
| 18 | + * The issue stems from the gtDeltaTicks * 0.2, which needs a maximum value of 1. |
| 19 | + */ |
| 20 | + @Definition(id = "rainFogMultiplier", field = "Lnet/minecraft/client/renderer/fog/environment/AtmosphericFogEnvironment;rainFogMultiplier:F") |
| 21 | + @Definition(id = "rainLevel", local = @Local(type = float.class, ordinal = 3)) |
| 22 | + @Definition(id = "gtDeltaTicks", local = @Local(type = float.class, ordinal = 1)) |
| 23 | + // `?.` instead of `this.` since the `this` is DUPed making it impossible to target |
| 24 | + @Expression("?.rainFogMultiplier = ?.rainFogMultiplier + (rainLevel - ?.rainFogMultiplier) * @(gtDeltaTicks) * 0.2") |
| 25 | + @ModifyExpressionValue(method = "setupFog", at = @At("MIXINEXTRAS:EXPRESSION")) |
| 26 | + private float clampFog(float original) { |
| 27 | + // it's impossible to target `gtDeltaTicks * 0.2` since in bytecode |
| 28 | + // it's `...) * gtDeltaTicks) * 0.2`. so instead just modify `gtDeltaTicks` with min 5, since 5 * 0.2 is 1 |
| 29 | + return Math.min(5f, original); |
| 30 | + } |
| 31 | +} |
0 commit comments