Skip to content

Commit 20c94bf

Browse files
authored
Weather module (#156)
1 parent 19cd002 commit 20c94bf

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin.render;
19+
20+
import com.lambda.module.modules.render.Weather;
21+
import net.minecraft.client.render.WeatherRendering;
22+
import net.minecraft.util.math.BlockPos;
23+
import net.minecraft.world.World;
24+
import net.minecraft.world.biome.Biome;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
30+
@Mixin(WeatherRendering.class)
31+
public class WeatherRenderingMixin {
32+
@Inject(method = "getPrecipitationAt", at = @At("HEAD"), cancellable = true)
33+
private void injectGetPrecipitationAt(World world, BlockPos pos, CallbackInfoReturnable<Biome.Precipitation> cir) {
34+
if (Weather.INSTANCE.isEnabled()) {
35+
Weather.WeatherMode mode = Weather.getWeatherMode();
36+
if (world.getRegistryKey() == World.OVERWORLD) {
37+
if (mode == Weather.WeatherMode.Rain && Weather.getOverrideSnow()) cir.setReturnValue(Biome.Precipitation.RAIN);
38+
else if (mode == Weather.WeatherMode.Snow) cir.setReturnValue(Biome.Precipitation.SNOW);
39+
} else {
40+
if (mode == Weather.WeatherMode.Snow) cir.setReturnValue(Biome.Precipitation.SNOW);
41+
else cir.setReturnValue(Biome.Precipitation.RAIN);
42+
}
43+
}
44+
}
45+
}

src/main/java/com/lambda/mixin/world/WorldMixin.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,40 @@
1919

2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.WorldEvent;
22+
import com.lambda.module.modules.render.Weather;
2223
import net.minecraft.block.BlockState;
2324
import net.minecraft.util.math.BlockPos;
2425
import net.minecraft.world.World;
2526
import org.spongepowered.asm.mixin.Mixin;
2627
import org.spongepowered.asm.mixin.injection.At;
2728
import org.spongepowered.asm.mixin.injection.Inject;
2829
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
30+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2931

3032
@Mixin(World.class)
3133
public abstract class WorldMixin {
3234
@Inject(method = "onBlockStateChanged", at = @At("TAIL"))
3335
void onBlockChanged(BlockPos pos, BlockState oldBlock, BlockState newBlock, CallbackInfo ci) {
3436
EventFlow.post(new WorldEvent.BlockUpdate.Client(pos, oldBlock, newBlock));
3537
}
38+
39+
@Inject(method = "getThunderGradient(F)F", at = @At("HEAD"), cancellable = true)
40+
private void injectGetThunderGradient(float tickProgress, CallbackInfoReturnable<Float> cir) {
41+
if (Weather.INSTANCE.isEnabled()) {
42+
if (Weather.getWeatherMode() == Weather.WeatherMode.Thunder) cir.setReturnValue(1f);
43+
else cir.setReturnValue(0f);
44+
}
45+
}
46+
47+
@Inject(method = "getRainGradient", at = @At("HEAD"), cancellable = true)
48+
private void injectGetRainGradient(float tickProgress, CallbackInfoReturnable<Float> cir) {
49+
if (Weather.INSTANCE.isEnabled()) {
50+
Weather.WeatherMode mode = Weather.getWeatherMode();
51+
if (mode == Weather.WeatherMode.Rain ||
52+
mode == Weather.WeatherMode.Snow ||
53+
mode == Weather.WeatherMode.Thunder
54+
) cir.setReturnValue(1f);
55+
else cir.setReturnValue(0f);
56+
}
57+
}
3658
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.render
19+
20+
import com.lambda.module.Module
21+
import com.lambda.module.tag.ModuleTag
22+
import com.lambda.threading.runSafe
23+
import com.lambda.util.NamedEnum
24+
import net.minecraft.world.World
25+
26+
object Weather : Module(
27+
name = "Weather",
28+
description = "Modifies the client side weather",
29+
tag = ModuleTag.RENDER
30+
) {
31+
private enum class Group(override val displayName: String) : NamedEnum {
32+
Overworld("Overworld"),
33+
Nether("Nether"),
34+
End("End")
35+
}
36+
37+
@JvmStatic val overworldMode by setting("Overworld Mode", WeatherMode.Clear).group(Group.Overworld)
38+
@JvmStatic val overrideSnow by setting("Override Snow", false) { overworldMode == WeatherMode.Rain }.group(Group.Overworld)
39+
@JvmStatic val netherMode by setting("Nether Mode", WeatherMode.Clear).group(Group.Nether)
40+
@JvmStatic val endMode by setting("End Mode", WeatherMode.Clear).group(Group.End)
41+
42+
@JvmStatic fun getWeatherMode() =
43+
runSafe {
44+
val dimension = world.registryKey
45+
when (dimension) {
46+
World.OVERWORLD -> overworldMode
47+
World.NETHER -> netherMode
48+
else -> endMode
49+
}
50+
} ?: WeatherMode.Clear
51+
52+
enum class WeatherMode {
53+
Clear,
54+
Rain,
55+
Thunder,
56+
Snow
57+
}
58+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"render.SplashOverlayMixin",
6262
"render.SplashOverlayMixin$LogoTextureMixin",
6363
"render.TooltipComponentMixin",
64+
"render.WeatherRenderingMixin",
6465
"render.WorldBorderRenderingMixin",
6566
"render.WorldRendererMixin",
6667
"world.BlockCollisionSpliteratorMixin",

0 commit comments

Comments
 (0)