|
1 | 1 | package dev.spiritstudios.abysm.client.mixin.render; |
2 | 2 |
|
3 | | -import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
4 | 3 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
5 | | -import dev.spiritstudios.abysm.client.AbysmClient; |
6 | | -import dev.spiritstudios.abysm.worldgen.biome.AbysmBiomes; |
7 | | -import net.minecraft.block.enums.CameraSubmersionType; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import com.llamalad7.mixinextras.sugar.Local; |
| 6 | +import dev.spiritstudios.abysm.client.render.AbysmWaterFogModifier; |
8 | 7 | import net.minecraft.client.render.Camera; |
9 | 8 | import net.minecraft.client.render.fog.WaterFogModifier; |
10 | 9 | import net.minecraft.client.world.ClientWorld; |
11 | | -import net.minecraft.registry.entry.RegistryEntry; |
12 | | -import net.minecraft.util.math.BlockPos; |
13 | | -import net.minecraft.util.math.ColorHelper; |
14 | | -import net.minecraft.util.math.MathHelper; |
15 | 10 | import net.minecraft.world.biome.Biome; |
16 | 11 | import org.spongepowered.asm.mixin.Mixin; |
17 | | -import org.spongepowered.asm.mixin.Shadow; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 15 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
18 | 16 |
|
19 | 17 | @Mixin(WaterFogModifier.class) |
20 | 18 | public abstract class WaterFogModifierMixin { |
21 | | - @Shadow |
22 | | - private static long updateTime; |
23 | 19 |
|
24 | | - @WrapMethod(method = "getFogColor") |
25 | | - private int adjustWaterFogColor(ClientWorld world, Camera camera, int viewDistance, float skyDarkness, Operation<Integer> original) { |
26 | | - int value = original.call(world, camera, viewDistance, skyDarkness); |
27 | | - |
28 | | - CameraSubmersionType cameraSubmersionType = camera.getSubmersionType(); |
29 | | - if (cameraSubmersionType == CameraSubmersionType.WATER) { |
30 | | - float lightness = 0.5F + 2.0F * MathHelper.clamp(MathHelper.cos(world.getSkyAngle(1.0F) * MathHelper.TAU), -0.25F, 0.25F); |
31 | | - RegistryEntry<Biome> biome = world.getBiome(BlockPos.ofFloored(camera.getPos())); |
32 | | - |
33 | | - // update underwater visiblity |
34 | | - float visibilityMultiplier; |
35 | | - if (biome.matchesKey(AbysmBiomes.FLORAL_REEF)) { |
36 | | - visibilityMultiplier = 0.3F + 0.7F * lightness; |
37 | | - } else if (biome.matchesKey(AbysmBiomes.DEEP_SEA_RUINS)) { |
38 | | - visibilityMultiplier = 0.13F; |
39 | | - } else { |
40 | | - visibilityMultiplier = 1.0F; |
41 | | - } |
42 | | - |
43 | | - if (updateTime < 0L) { |
44 | | - AbysmClient.underwaterVisibilityMultiplier = visibilityMultiplier; |
45 | | - AbysmClient.nextUnderwaterVisibilityMultiplier = visibilityMultiplier; |
46 | | - } else { |
47 | | - AbysmClient.underwaterVisibilityMultiplier = AbysmClient.nextUnderwaterVisibilityMultiplier; |
48 | | - AbysmClient.nextUnderwaterVisibilityMultiplier = MathHelper.lerp(0.007F, AbysmClient.underwaterVisibilityMultiplier, visibilityMultiplier); |
49 | | - } |
50 | | - |
51 | | - // adjust fog color |
52 | | - if (lightness < 0.999F && biome.matchesKey(AbysmBiomes.FLORAL_REEF)) { |
53 | | - int nightWaterFogColor = 0x11082F; |
54 | | - return ColorHelper.lerp(lightness, nightWaterFogColor, value); |
55 | | - } else { |
56 | | - return value; |
57 | | - } |
58 | | - } else { |
59 | | - return value; |
60 | | - } |
| 20 | + @Inject(method = "getFogColor", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;getWaterFogColor()I")) |
| 21 | + private void updateUnderwaterVisibility(ClientWorld world, Camera camera, int viewDistance, float skyDarkness, CallbackInfoReturnable<Integer> cir, @Local(ordinal = 0) long measuringTime) { |
| 22 | + AbysmWaterFogModifier.updateUnderwaterVisibility(world, camera, measuringTime); |
61 | 23 | } |
62 | 24 |
|
| 25 | + @WrapOperation(method = "getFogColor", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;getWaterFogColor()I")) |
| 26 | + private int adjustFogColor(Biome instance, Operation<Integer> original, ClientWorld world, Camera camera, int viewDistance, float skyDarkness, @Local(ordinal = 0) long measuringTime) { |
| 27 | + int value = original.call(instance); |
| 28 | + return AbysmWaterFogModifier.adjustWaterFogColor(value, world, camera); |
| 29 | + } |
63 | 30 |
|
| 31 | + @Inject(method = "onSkipped", at = @At("RETURN")) |
| 32 | + private void onSkipped(CallbackInfo ci) { |
| 33 | + AbysmWaterFogModifier.onSkipped(); |
| 34 | + } |
64 | 35 | } |
0 commit comments