diff --git a/src/main/java/com/lambda/mixin/render/WeatherRenderingMixin.java b/src/main/java/com/lambda/mixin/render/WeatherRenderingMixin.java new file mode 100644 index 000000000..5956f8a3c --- /dev/null +++ b/src/main/java/com/lambda/mixin/render/WeatherRenderingMixin.java @@ -0,0 +1,45 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.mixin.render; + +import com.lambda.module.modules.render.Weather; +import net.minecraft.client.render.WeatherRendering; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +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.CallbackInfoReturnable; + +@Mixin(WeatherRendering.class) +public class WeatherRenderingMixin { + @Inject(method = "getPrecipitationAt", at = @At("HEAD"), cancellable = true) + private void injectGetPrecipitationAt(World world, BlockPos pos, CallbackInfoReturnable cir) { + if (Weather.INSTANCE.isEnabled()) { + Weather.WeatherMode mode = Weather.getWeatherMode(); + if (world.getRegistryKey() == World.OVERWORLD) { + if (mode == Weather.WeatherMode.Rain && Weather.getOverrideSnow()) cir.setReturnValue(Biome.Precipitation.RAIN); + else if (mode == Weather.WeatherMode.Snow) cir.setReturnValue(Biome.Precipitation.SNOW); + } else { + if (mode == Weather.WeatherMode.Snow) cir.setReturnValue(Biome.Precipitation.SNOW); + else cir.setReturnValue(Biome.Precipitation.RAIN); + } + } + } +} diff --git a/src/main/java/com/lambda/mixin/world/WorldMixin.java b/src/main/java/com/lambda/mixin/world/WorldMixin.java index 083cdbf56..7c23170c9 100644 --- a/src/main/java/com/lambda/mixin/world/WorldMixin.java +++ b/src/main/java/com/lambda/mixin/world/WorldMixin.java @@ -19,6 +19,7 @@ import com.lambda.event.EventFlow; import com.lambda.event.events.WorldEvent; +import com.lambda.module.modules.render.Weather; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -26,6 +27,7 @@ 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(World.class) public abstract class WorldMixin { @@ -33,4 +35,24 @@ public abstract class WorldMixin { void onBlockChanged(BlockPos pos, BlockState oldBlock, BlockState newBlock, CallbackInfo ci) { EventFlow.post(new WorldEvent.BlockUpdate.Client(pos, oldBlock, newBlock)); } + + @Inject(method = "getThunderGradient(F)F", at = @At("HEAD"), cancellable = true) + private void injectGetThunderGradient(float tickProgress, CallbackInfoReturnable cir) { + if (Weather.INSTANCE.isEnabled()) { + if (Weather.getWeatherMode() == Weather.WeatherMode.Thunder) cir.setReturnValue(1f); + else cir.setReturnValue(0f); + } + } + + @Inject(method = "getRainGradient", at = @At("HEAD"), cancellable = true) + private void injectGetRainGradient(float tickProgress, CallbackInfoReturnable cir) { + if (Weather.INSTANCE.isEnabled()) { + Weather.WeatherMode mode = Weather.getWeatherMode(); + if (mode == Weather.WeatherMode.Rain || + mode == Weather.WeatherMode.Snow || + mode == Weather.WeatherMode.Thunder + ) cir.setReturnValue(1f); + else cir.setReturnValue(0f); + } + } } diff --git a/src/main/kotlin/com/lambda/module/modules/render/Weather.kt b/src/main/kotlin/com/lambda/module/modules/render/Weather.kt new file mode 100644 index 000000000..0f05d3aeb --- /dev/null +++ b/src/main/kotlin/com/lambda/module/modules/render/Weather.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.module.modules.render + +import com.lambda.module.Module +import com.lambda.module.tag.ModuleTag +import com.lambda.threading.runSafe +import com.lambda.util.NamedEnum +import net.minecraft.world.World + +object Weather : Module( + name = "Weather", + description = "Modifies the client side weather", + tag = ModuleTag.RENDER +) { + private enum class Group(override val displayName: String) : NamedEnum { + Overworld("Overworld"), + Nether("Nether"), + End("End") + } + + @JvmStatic val overworldMode by setting("Overworld Mode", WeatherMode.Clear).group(Group.Overworld) + @JvmStatic val overrideSnow by setting("Override Snow", false) { overworldMode == WeatherMode.Rain }.group(Group.Overworld) + @JvmStatic val netherMode by setting("Nether Mode", WeatherMode.Clear).group(Group.Nether) + @JvmStatic val endMode by setting("End Mode", WeatherMode.Clear).group(Group.End) + + @JvmStatic fun getWeatherMode() = + runSafe { + val dimension = world.registryKey + when (dimension) { + World.OVERWORLD -> overworldMode + World.NETHER -> netherMode + else -> endMode + } + } ?: WeatherMode.Clear + + enum class WeatherMode { + Clear, + Rain, + Thunder, + Snow + } +} \ No newline at end of file diff --git a/src/main/resources/lambda.mixins.common.json b/src/main/resources/lambda.mixins.common.json index 6a274c926..f5fb4fff6 100644 --- a/src/main/resources/lambda.mixins.common.json +++ b/src/main/resources/lambda.mixins.common.json @@ -61,6 +61,7 @@ "render.SplashOverlayMixin", "render.SplashOverlayMixin$LogoTextureMixin", "render.TooltipComponentMixin", + "render.WeatherRenderingMixin", "render.WorldBorderRenderingMixin", "render.WorldRendererMixin", "world.BlockCollisionSpliteratorMixin",