From a7bc5630879f93bef16ece00e0a27cf8a26f1b7b Mon Sep 17 00:00:00 2001 From: Camii2407 Date: Tue, 20 Aug 2024 01:52:29 +0100 Subject: [PATCH 1/4] Added feature WorldColors that changes sky color and fog color --- .../mixin/render/RenderSystemMixin.java | 26 +++++++++++++++++++ .../mixin/render/WorldRendererMixin.java | 11 ++++++++ .../module/modules/render/WorldColors.kt | 20 ++++++++++++++ .../main/resources/lambda.mixins.common.json | 1 + 4 files changed, 58 insertions(+) create mode 100644 common/src/main/java/com/lambda/mixin/render/RenderSystemMixin.java create mode 100644 common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt diff --git a/common/src/main/java/com/lambda/mixin/render/RenderSystemMixin.java b/common/src/main/java/com/lambda/mixin/render/RenderSystemMixin.java new file mode 100644 index 000000000..e33d1d3c5 --- /dev/null +++ b/common/src/main/java/com/lambda/mixin/render/RenderSystemMixin.java @@ -0,0 +1,26 @@ +package com.lambda.mixin.render; + +import com.lambda.module.modules.render.WorldColors; +import com.mojang.blaze3d.systems.RenderSystem; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderSystem.class) +public class RenderSystemMixin { + @Shadow @Final private static float[] shaderFogColor; + + @Inject(method = "_setShaderFogColor", at = @At(value ="HEAD"), cancellable = true) + private static void onSetShaderFogColor(float red, float green, float blue, float alpha, CallbackInfo ci){ + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomFog()){ + ci.cancel(); + shaderFogColor[0] = WorldColors.getFogColor().getRed() / 255f; + shaderFogColor[1] = WorldColors.getFogColor().getGreen() / 255f; + shaderFogColor[2] = WorldColors.getFogColor().getBlue() / 255f; + shaderFogColor[3] = WorldColors.getFogColor().getAlpha() / 255f; + } + } +} diff --git a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java index e95ee1303..bd7e4d414 100644 --- a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java @@ -1,8 +1,11 @@ package com.lambda.mixin.render; import com.lambda.module.modules.player.Freecam; +import com.lambda.module.modules.render.WorldColors; import net.minecraft.client.render.Camera; import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -19,4 +22,12 @@ private boolean renderIsThirdPerson(Camera camera) { private boolean renderSetupTerrainModifyArg(boolean spectator) { return Freecam.INSTANCE.isEnabled() || spectator; } + + @Redirect(method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getSkyColor(Lnet/minecraft/util/math/Vec3d;F)Lnet/minecraft/util/math/Vec3d;")) + private Vec3d redirectSkyColor(ClientWorld world, Vec3d cameraPos, float tickDelta){ + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()){ + return new Vec3d(WorldColors.getSkyColor().getRed() / 255f, WorldColors.getSkyColor().getGreen() / 255f, WorldColors.getSkyColor().getBlue() / 255f); + } + return world.getSkyColor(cameraPos, tickDelta); + } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt new file mode 100644 index 000000000..ab5f1f3ee --- /dev/null +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -0,0 +1,20 @@ +package com.lambda.module.modules.render + +import com.lambda.module.Module +import com.lambda.module.tag.ModuleTag +import java.awt.Color + +object WorldColors : Module( + name = "World Colors", + description = "Changes the color of the sky", + defaultTags = setOf(ModuleTag.RENDER) +){ + @JvmStatic + val customSky by setting("Sky Color", true) + @JvmStatic + val skyColor by setting("Color", Color(255, 24, 75), "The color of your sky") { customSky } + @JvmStatic + val customFog by setting("Fog",false) + @JvmStatic + val fogColor by setting("Color", Color(255, 24, 75, 255), "The color of your horizon") { customFog } +} \ No newline at end of file diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index d9c7a6fb4..60a058d34 100644 --- a/common/src/main/resources/lambda.mixins.common.json +++ b/common/src/main/resources/lambda.mixins.common.json @@ -30,6 +30,7 @@ "render.LightmapTextureManagerMixin", "render.LivingEntityRendererMixin", "render.RenderLayersMixin", + "render.RenderSystemMixin", "render.RenderTickCounterMixin", "render.ScreenHandlerMixin", "render.VertexBufferMixin", From 7e29ce773566aa2e3060a1363a318a0b6e8a0799 Mon Sep 17 00:00:00 2001 From: Camii2407 Date: Tue, 20 Aug 2024 10:50:32 +0100 Subject: [PATCH 2/4] Added cloud color changer in WorldColors and Vec3d in ColorUtils --- .../com/lambda/mixin/render/WorldRendererMixin.java | 13 +++++++++++-- .../com/lambda/module/modules/render/WorldColors.kt | 12 ++++++++---- .../main/kotlin/com/lambda/util/math/ColorUtils.kt | 4 ++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java index bd7e4d414..85afa78bb 100644 --- a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java @@ -2,6 +2,7 @@ import com.lambda.module.modules.player.Freecam; import com.lambda.module.modules.render.WorldColors; +import com.lambda.util.math.ColorUtils; import net.minecraft.client.render.Camera; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.world.ClientWorld; @@ -25,9 +26,17 @@ private boolean renderSetupTerrainModifyArg(boolean spectator) { @Redirect(method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getSkyColor(Lnet/minecraft/util/math/Vec3d;F)Lnet/minecraft/util/math/Vec3d;")) private Vec3d redirectSkyColor(ClientWorld world, Vec3d cameraPos, float tickDelta){ - if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()){ - return new Vec3d(WorldColors.getSkyColor().getRed() / 255f, WorldColors.getSkyColor().getGreen() / 255f, WorldColors.getSkyColor().getBlue() / 255f); + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()) { + return ColorUtils.getVec3d(WorldColors.getSkyColor()); } return world.getSkyColor(cameraPos, tickDelta); } + + @Redirect(method = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FDDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getCloudsColor(F)Lnet/minecraft/util/math/Vec3d;")) + private Vec3d redirectCloudColor(ClientWorld world, float tickDelta){ + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomClouds()) { + return ColorUtils.getVec3d(WorldColors.getCloudsColor()); + } + return world.getCloudsColor(tickDelta); + } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt index ab5f1f3ee..10fc0cbff 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -10,11 +10,15 @@ object WorldColors : Module( defaultTags = setOf(ModuleTag.RENDER) ){ @JvmStatic - val customSky by setting("Sky Color", true) + val customSky by setting("Custom Sky", true) @JvmStatic - val skyColor by setting("Color", Color(255, 24, 75), "The color of your sky") { customSky } + val skyColor by setting("Sky Color", Color(255, 24, 75), "The color of your sky") { customSky } @JvmStatic - val customFog by setting("Fog",false) + val customFog by setting("Custom Fog",false) @JvmStatic - val fogColor by setting("Color", Color(255, 24, 75, 255), "The color of your horizon") { customFog } + val fogColor by setting("Fog Color", Color(255, 24, 75, 255), "The color of your fog") { customFog } + @JvmStatic + val customClouds by setting("Custom Clouds", false) + @JvmStatic + val cloudsColor by setting("Clouds Color", Color(255, 24, 75)) { customClouds } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt b/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt index 4e8b10f1e..6adec5efd 100644 --- a/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt +++ b/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt @@ -1,5 +1,6 @@ package com.lambda.util.math +import net.minecraft.util.math.Vec3d import java.awt.Color object ColorUtils { @@ -13,4 +14,7 @@ object ColorUtils { val Color.g get() = green.toDouble() / 255.0 val Color.b get() = blue.toDouble() / 255.0 val Color.a get() = alpha.toDouble() / 255.0 + + @JvmStatic + val Color.vec3d get() = Vec3d(r, g, b) } \ No newline at end of file From e3328aea6b1ac0320db5d5df85f0bb4f0df21b2a Mon Sep 17 00:00:00 2001 From: Camii2407 Date: Wed, 21 Aug 2024 23:28:36 +0100 Subject: [PATCH 3/4] Added avens improvements to WorldColors --- .../mixin/render/WorldRendererMixin.java | 20 ------------------- .../lambda/mixin/world/ClientWorldMixin.java | 18 +++++++++++++++++ .../module/modules/render/WorldColors.kt | 3 ++- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java index 85afa78bb..e95ee1303 100644 --- a/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/WorldRendererMixin.java @@ -1,12 +1,8 @@ package com.lambda.mixin.render; import com.lambda.module.modules.player.Freecam; -import com.lambda.module.modules.render.WorldColors; -import com.lambda.util.math.ColorUtils; import net.minecraft.client.render.Camera; import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -23,20 +19,4 @@ private boolean renderIsThirdPerson(Camera camera) { private boolean renderSetupTerrainModifyArg(boolean spectator) { return Freecam.INSTANCE.isEnabled() || spectator; } - - @Redirect(method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getSkyColor(Lnet/minecraft/util/math/Vec3d;F)Lnet/minecraft/util/math/Vec3d;")) - private Vec3d redirectSkyColor(ClientWorld world, Vec3d cameraPos, float tickDelta){ - if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()) { - return ColorUtils.getVec3d(WorldColors.getSkyColor()); - } - return world.getSkyColor(cameraPos, tickDelta); - } - - @Redirect(method = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FDDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getCloudsColor(F)Lnet/minecraft/util/math/Vec3d;")) - private Vec3d redirectCloudColor(ClientWorld world, float tickDelta){ - if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomClouds()) { - return ColorUtils.getVec3d(WorldColors.getCloudsColor()); - } - return world.getCloudsColor(tickDelta); - } } diff --git a/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java b/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java index af12440bc..bc0c91157 100644 --- a/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java +++ b/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java @@ -2,14 +2,18 @@ import com.lambda.event.EventFlow; import com.lambda.event.events.WorldEvent; +import com.lambda.module.modules.render.WorldColors; +import com.lambda.util.math.ColorUtils; import net.minecraft.block.BlockState; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientWorld.class) public class ClientWorldMixin { @@ -24,4 +28,18 @@ private void handleBlockUpdateInject(BlockPos pos, BlockState state, int flags, private void addEntity(Entity entity, CallbackInfo ci) { if (EventFlow.post(new WorldEvent.EntitySpawn(entity)).isCanceled()) ci.cancel(); } + + @Inject(method = "getCloudsColor", at = @At("HEAD"), cancellable = true) + private void getCloudsColorInject(float tickDelta, CallbackInfoReturnable cir) { + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomClouds()) { + cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getCloudColor())); + } + } + + @Inject(method = "getSkyColor", at = @At("HEAD"), cancellable = true) + private void getSkyColorInject(Vec3d cameraPos, float tickDelta, CallbackInfoReturnable cir) { + if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()) { + cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getSkyColor())); + } + } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt index 10fc0cbff..f3c35e775 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -20,5 +20,6 @@ object WorldColors : Module( @JvmStatic val customClouds by setting("Custom Clouds", false) @JvmStatic - val cloudsColor by setting("Clouds Color", Color(255, 24, 75)) { customClouds } + val cloudColor by setting("Cloud Color", Color(255, 24, 75)) { customClouds } + } \ No newline at end of file From d8b509f39a6279bff5427a96bf906a0f3db95e12 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 22 Aug 2024 01:31:24 +0200 Subject: [PATCH 4/4] Match background to fog color --- .../mixin/render/BackgroundRendererMixin.java | 26 +++++++++++++++++++ .../module/modules/render/WorldColors.kt | 5 ++++ .../main/resources/lambda.mixins.common.json | 1 + 3 files changed, 32 insertions(+) create mode 100644 common/src/main/java/com/lambda/mixin/render/BackgroundRendererMixin.java diff --git a/common/src/main/java/com/lambda/mixin/render/BackgroundRendererMixin.java b/common/src/main/java/com/lambda/mixin/render/BackgroundRendererMixin.java new file mode 100644 index 000000000..d72788b80 --- /dev/null +++ b/common/src/main/java/com/lambda/mixin/render/BackgroundRendererMixin.java @@ -0,0 +1,26 @@ +package com.lambda.mixin.render; + +import com.lambda.module.modules.render.WorldColors; +import net.minecraft.client.render.BackgroundRenderer; +import net.minecraft.util.math.Vec3d; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BackgroundRenderer.class) +public class BackgroundRendererMixin { + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getX()D")) + private static double redirectRed(Vec3d baseColor) { + return WorldColors.backgroundColor(baseColor).getX(); + } + + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getY()D")) + private static double redirectGreen(Vec3d baseColor) { + return WorldColors.backgroundColor(baseColor).getY(); + } + + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;getZ()D")) + private static double redirectBlue(Vec3d baseColor) { + return WorldColors.backgroundColor(baseColor).getZ(); + } +} diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt index f3c35e775..56604c22d 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -2,6 +2,8 @@ package com.lambda.module.modules.render import com.lambda.module.Module import com.lambda.module.tag.ModuleTag +import com.lambda.util.math.ColorUtils.vec3d +import net.minecraft.util.math.Vec3d import java.awt.Color object WorldColors : Module( @@ -22,4 +24,7 @@ object WorldColors : Module( @JvmStatic val cloudColor by setting("Cloud Color", Color(255, 24, 75)) { customClouds } + @JvmStatic + fun backgroundColor(base: Vec3d) = + if (customFog && isEnabled) fogColor.vec3d else base } \ No newline at end of file diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index 0cac0ec06..71f9d0ea9 100644 --- a/common/src/main/resources/lambda.mixins.common.json +++ b/common/src/main/resources/lambda.mixins.common.json @@ -22,6 +22,7 @@ "network.HandshakeC2SPacketMixin", "network.LoginHelloC2SPacketMixin", "network.LoginKeyC2SPacketMixin", + "render.BackgroundRendererMixin", "render.BlockRenderManagerMixin", "render.CameraMixin", "render.ChatInputSuggestorMixin",