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/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/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 new file mode 100644 index 000000000..56604c22d --- /dev/null +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -0,0 +1,30 @@ +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( + name = "World Colors", + description = "Changes the color of the sky", + defaultTags = setOf(ModuleTag.RENDER) +){ + @JvmStatic + val customSky by setting("Custom Sky", true) + @JvmStatic + val skyColor by setting("Sky Color", Color(255, 24, 75), "The color of your sky") { customSky } + @JvmStatic + val customFog by setting("Custom Fog",false) + @JvmStatic + 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 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/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 diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index d39928708..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", @@ -34,6 +35,7 @@ "render.LightmapTextureManagerMixin", "render.LivingEntityRendererMixin", "render.RenderLayersMixin", + "render.RenderSystemMixin", "render.RenderTickCounterMixin", "render.ScreenHandlerMixin", "render.VertexBufferMixin",