Skip to content

Commit 87e0095

Browse files
Camii2407emyfopsAvanatiker
authored
[1.20.x] [All] [Feature]: Skybox and fog colors (#60)
Co-authored-by: Edouard127 <46357922+Edouard127@users.noreply.github.com> Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent 75ccc5f commit 87e0095

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.render.WorldColors;
4+
import net.minecraft.client.render.BackgroundRenderer;
5+
import net.minecraft.util.math.Vec3d;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Redirect;
9+
10+
@Mixin(BackgroundRenderer.class)
11+
public class BackgroundRendererMixin {
12+
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getX()D"))
13+
private static double redirectRed(Vec3d baseColor) {
14+
return WorldColors.backgroundColor(baseColor).getX();
15+
}
16+
17+
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getY()D"))
18+
private static double redirectGreen(Vec3d baseColor) {
19+
return WorldColors.backgroundColor(baseColor).getY();
20+
}
21+
22+
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getZ()D"))
23+
private static double redirectBlue(Vec3d baseColor) {
24+
return WorldColors.backgroundColor(baseColor).getZ();
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.render.WorldColors;
4+
import com.mojang.blaze3d.systems.RenderSystem;
5+
import org.spongepowered.asm.mixin.Final;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(RenderSystem.class)
13+
public class RenderSystemMixin {
14+
@Shadow @Final private static float[] shaderFogColor;
15+
16+
@Inject(method = "_setShaderFogColor", at = @At(value ="HEAD"), cancellable = true)
17+
private static void onSetShaderFogColor(float red, float green, float blue, float alpha, CallbackInfo ci){
18+
if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomFog()){
19+
ci.cancel();
20+
shaderFogColor[0] = WorldColors.getFogColor().getRed() / 255f;
21+
shaderFogColor[1] = WorldColors.getFogColor().getGreen() / 255f;
22+
shaderFogColor[2] = WorldColors.getFogColor().getBlue() / 255f;
23+
shaderFogColor[3] = WorldColors.getFogColor().getAlpha() / 255f;
24+
}
25+
}
26+
}

common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import com.lambda.event.EventFlow;
44
import com.lambda.event.events.WorldEvent;
5+
import com.lambda.module.modules.render.WorldColors;
6+
import com.lambda.util.math.ColorUtils;
57
import net.minecraft.block.BlockState;
68
import net.minecraft.client.world.ClientWorld;
79
import net.minecraft.entity.Entity;
810
import net.minecraft.util.math.BlockPos;
11+
import net.minecraft.util.math.Vec3d;
912
import org.spongepowered.asm.mixin.Mixin;
1013
import org.spongepowered.asm.mixin.injection.At;
1114
import org.spongepowered.asm.mixin.injection.Inject;
1215
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1317

1418
@Mixin(ClientWorld.class)
1519
public class ClientWorldMixin {
@@ -24,4 +28,18 @@ private void handleBlockUpdateInject(BlockPos pos, BlockState state, int flags,
2428
private void addEntity(Entity entity, CallbackInfo ci) {
2529
if (EventFlow.post(new WorldEvent.EntitySpawn(entity)).isCanceled()) ci.cancel();
2630
}
31+
32+
@Inject(method = "getCloudsColor", at = @At("HEAD"), cancellable = true)
33+
private void getCloudsColorInject(float tickDelta, CallbackInfoReturnable<Vec3d> cir) {
34+
if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomClouds()) {
35+
cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getCloudColor()));
36+
}
37+
}
38+
39+
@Inject(method = "getSkyColor", at = @At("HEAD"), cancellable = true)
40+
private void getSkyColorInject(Vec3d cameraPos, float tickDelta, CallbackInfoReturnable<Vec3d> cir) {
41+
if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()) {
42+
cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getSkyColor()));
43+
}
44+
}
2745
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.lambda.module.modules.render
2+
3+
import com.lambda.module.Module
4+
import com.lambda.module.tag.ModuleTag
5+
import com.lambda.util.math.ColorUtils.vec3d
6+
import net.minecraft.util.math.Vec3d
7+
import java.awt.Color
8+
9+
object WorldColors : Module(
10+
name = "World Colors",
11+
description = "Changes the color of the sky",
12+
defaultTags = setOf(ModuleTag.RENDER)
13+
){
14+
@JvmStatic
15+
val customSky by setting("Custom Sky", true)
16+
@JvmStatic
17+
val skyColor by setting("Sky Color", Color(255, 24, 75), "The color of your sky") { customSky }
18+
@JvmStatic
19+
val customFog by setting("Custom Fog",false)
20+
@JvmStatic
21+
val fogColor by setting("Fog Color", Color(255, 24, 75, 255), "The color of your fog") { customFog }
22+
@JvmStatic
23+
val customClouds by setting("Custom Clouds", false)
24+
@JvmStatic
25+
val cloudColor by setting("Cloud Color", Color(255, 24, 75)) { customClouds }
26+
27+
@JvmStatic
28+
fun backgroundColor(base: Vec3d) =
29+
if (customFog && isEnabled) fogColor.vec3d else base
30+
}

common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.util.math
22

3+
import net.minecraft.util.math.Vec3d
34
import java.awt.Color
45

56
object ColorUtils {
@@ -13,4 +14,7 @@ object ColorUtils {
1314
val Color.g get() = green.toDouble() / 255.0
1415
val Color.b get() = blue.toDouble() / 255.0
1516
val Color.a get() = alpha.toDouble() / 255.0
17+
18+
@JvmStatic
19+
val Color.vec3d get() = Vec3d(r, g, b)
1620
}

common/src/main/resources/lambda.mixins.common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"network.HandshakeC2SPacketMixin",
2323
"network.LoginHelloC2SPacketMixin",
2424
"network.LoginKeyC2SPacketMixin",
25+
"render.BackgroundRendererMixin",
2526
"render.BlockRenderManagerMixin",
2627
"render.CameraMixin",
2728
"render.ChatInputSuggestorMixin",
@@ -34,6 +35,7 @@
3435
"render.LightmapTextureManagerMixin",
3536
"render.LivingEntityRendererMixin",
3637
"render.RenderLayersMixin",
38+
"render.RenderSystemMixin",
3739
"render.RenderTickCounterMixin",
3840
"render.ScreenHandlerMixin",
3941
"render.VertexBufferMixin",

0 commit comments

Comments
 (0)