Skip to content

Commit 8ca6a4d

Browse files
committed
real and true
1 parent b577169 commit 8ca6a4d

23 files changed

Lines changed: 361 additions & 123 deletions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ toolkitMultiversion {
2020

2121
toolkitLoomHelper {
2222
useOneConfig {
23-
version = "1.0.0-alpha.151"
23+
version = "1.0.0-alpha.153"
2424
loaderVersion = "1.1.0-alpha.49"
2525

2626
usePolyMixin = true

src/main/java/org/polyfrost/polyweather/mixin/Mixin_FixLowTempsWhenSnowing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.polyfrost.polyweather.mixin;
22

33
import net.minecraft.world.biome.WorldChunkManager;
4-
import org.polyfrost.polyweather.client.PolyWeatherClient;
4+
import org.polyfrost.polyweather.client.ClientWeatherManager;
55
import org.polyfrost.polyweather.client.PolyWeatherConfig;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.*;
@@ -11,7 +11,7 @@
1111
public class Mixin_FixLowTempsWhenSnowing {
1212
@Inject(method = "getTemperatureAtHeight", at = @At("HEAD"), cancellable = true)
1313
private void polyweather$updateTemperatures(float p_76939_1_, int p_76939_2_, CallbackInfoReturnable<Float> cir) {
14-
if (PolyWeatherConfig.INSTANCE.enabled && PolyWeatherClient.isSnowing()) {
14+
if (PolyWeatherConfig.isEnabled() && ClientWeatherManager.isSnowy()) {
1515
cir.setReturnValue(0f);
1616
}
1717
}
Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,72 @@
11
package org.polyfrost.polyweather.mixin;
22

3+
import net.minecraft.client.multiplayer.WorldClient;
4+
import net.minecraft.profiler.Profiler;
5+
import net.minecraft.util.BlockPos;
36
import net.minecraft.world.World;
7+
import net.minecraft.world.WorldProvider;
8+
import net.minecraft.world.biome.BiomeGenBase;
9+
import net.minecraft.world.storage.ISaveHandler;
10+
import net.minecraft.world.storage.WorldInfo;
11+
import org.polyfrost.polyweather.client.ClientWeatherManager;
412
import org.polyfrost.polyweather.client.PolyWeatherClient;
513
import org.polyfrost.polyweather.client.PolyWeatherConfig;
14+
import org.polyfrost.polyweather.client.WeatherStorage;
615
import org.spongepowered.asm.mixin.Mixin;
16+
import org.spongepowered.asm.mixin.Unique;
717
import org.spongepowered.asm.mixin.injection.At;
818
import org.spongepowered.asm.mixin.injection.Inject;
919
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1020

11-
@Mixin(World.class)
12-
public class Mixin_FixRainAndThunderStrength {
13-
@Inject(method = "getRainStrength", at = @At("HEAD"), cancellable = true)
14-
private void getRainStrength(float delta, CallbackInfoReturnable<Float> cir) {
15-
if (PolyWeatherConfig.INSTANCE.enabled) {
16-
cir.setReturnValue(PolyWeatherClient.isSnowing() ? PolyWeatherClient.getSnowStrength() : PolyWeatherClient.isRaining() ? PolyWeatherClient.getRainStrength() : 0f);
21+
@Mixin(WorldClient.class)
22+
public abstract class Mixin_FixRainAndThunderStrength extends World implements WeatherStorage {
23+
protected Mixin_FixRainAndThunderStrength(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client) {
24+
super(saveHandlerIn, info, providerIn, profilerIn, client);
25+
}
26+
27+
public float getRainStrength(float delta) {
28+
if (PolyWeatherConfig.isEnabled()) {
29+
return ClientWeatherManager.getPrecipitationStrength(delta);
1730
}
31+
32+
return super.getRainStrength(delta);
1833
}
1934

20-
@Inject(method = "getThunderStrength", at = @At("HEAD"), cancellable = true)
21-
private void getThunderStrength(float delta, CallbackInfoReturnable<Float> cir) {
22-
if (PolyWeatherConfig.INSTANCE.enabled) {
23-
cir.setReturnValue(PolyWeatherClient.isThundering() ? PolyWeatherClient.getThunderStrength() : 0f);
35+
public float getThunderStrength(float delta) {
36+
if (PolyWeatherConfig.isEnabled()) {
37+
return ClientWeatherManager.getStormStrength(delta);
2438
}
39+
40+
return super.getThunderStrength(delta);
41+
}
42+
43+
public boolean isRainingAt(BlockPos strikePosition) {
44+
if (PolyWeatherConfig.isEnabled()) {
45+
// Stops the player from being able to use the trident when they have rainy weather enabled
46+
// We do this by just checking if it's actually raining, otherwise just say nope
47+
if (!ClientWeatherManager.isActuallyRaining()) {
48+
return false;
49+
}
50+
51+
if (!this.canSeeSky(strikePosition)) {
52+
return false;
53+
}
54+
55+
int topY = this.getPrecipitationHeight(strikePosition).getY();
56+
if (topY > strikePosition.getY()) {
57+
return false;
58+
}
59+
60+
BiomeGenBase biome = this.getBiomeGenForCoords(strikePosition);
61+
return biome.getEnableSnow() ? false : (this.canSnowAt(strikePosition, false) ? false : biome.canRain());
62+
}
63+
64+
return super.isRainingAt(strikePosition);
65+
}
66+
67+
@Unique
68+
@Override
69+
public boolean polyweather$isRaining() {
70+
return super.getRainStrength(1f) > 0.2f;
2571
}
2672
}

src/main/java/org/polyfrost/polyweather/mixin/Mixin_ForceRainAndSnowParticles.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.polyfrost.polyweather.mixin;
22

33
import net.minecraft.client.renderer.EntityRenderer;
4+
import org.polyfrost.polyweather.client.ClientWeatherManager;
45
import org.polyfrost.polyweather.client.PolyWeatherClient;
56
import org.polyfrost.polyweather.client.PolyWeatherConfig;
67
import org.spongepowered.asm.mixin.Mixin;
@@ -12,7 +13,7 @@
1213
public class Mixin_ForceRainAndSnowParticles {
1314
@Inject(method = "addRainParticles", at = @At("HEAD"), cancellable = true)
1415
private void addRainParticles(CallbackInfo ci) {
15-
if (PolyWeatherConfig.INSTANCE.enabled && (!PolyWeatherClient.isRaining() || PolyWeatherClient.isSnowing())) {
16+
if (PolyWeatherConfig.isEnabled() && (!ClientWeatherManager.isRainy() || ClientWeatherManager.isSnowy())) {
1617
ci.cancel();
1718
}
1819
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.polyfrost.polyweather.mixin;
22

33
import net.minecraft.world.storage.WorldInfo;
4-
import org.polyfrost.polyweather.client.PolyWeatherClient;
4+
import org.polyfrost.polyweather.client.ClientWeatherManager;
55
import org.polyfrost.polyweather.client.PolyWeatherConfig;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.At;
@@ -12,15 +12,15 @@
1212
public class Mixin_ForceRainAndThunderChecks {
1313
@Inject(method = "isRaining", at = @At("HEAD"), cancellable = true)
1414
private void isRaining(CallbackInfoReturnable<Boolean> cir) {
15-
if (PolyWeatherConfig.INSTANCE.enabled) {
16-
cir.setReturnValue(PolyWeatherClient.isRaining());
15+
if (PolyWeatherConfig.isEnabled()) {
16+
cir.setReturnValue(ClientWeatherManager.isRainy());
1717
}
1818
}
1919

2020
@Inject(method = "isThundering", at = @At("HEAD"), cancellable = true)
2121
private void isThundering(CallbackInfoReturnable<Boolean> cir) {
22-
if (PolyWeatherConfig.INSTANCE.enabled) {
23-
cir.setReturnValue(PolyWeatherClient.isThundering());
22+
if (PolyWeatherConfig.isEnabled()) {
23+
cir.setReturnValue(ClientWeatherManager.isStormy());
2424
}
2525
}
2626
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.polyfrost.polyweather.client
2+
3+
import dev.deftu.omnicore.api.client.world
4+
import dev.deftu.omnicore.api.math.OmniMath
5+
import org.polyfrost.polyweather.client.realtime.RealWeatherHandler
6+
import org.polyfrost.polyweather.util.WeatherType
7+
8+
object ClientWeatherManager {
9+
private val weatherStorage: WeatherStorage?
10+
get() {
11+
val world = world ?: return null
12+
return world as? WeatherStorage
13+
?: throw IllegalStateException("World does not implement WeatherStorage")
14+
}
15+
16+
@JvmStatic val isRainy: Boolean get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.isRainy else PolyWeatherConfig.weatherType != WeatherType.CLEAR
17+
@JvmStatic val isStormy: Boolean get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.isStormy else PolyWeatherConfig.weatherType == WeatherType.STORM
18+
@JvmStatic val isSnowy: Boolean get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.isSnowy else PolyWeatherConfig.weatherType == WeatherType.SNOW
19+
20+
@JvmStatic val isActuallyRaining: Boolean get() = weatherStorage?.`polyweather$isRaining`() == true
21+
22+
private val rainStrength: Float get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.rainStrength else PolyWeatherConfig.rainStrength
23+
private val snowStrength: Float get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.rainStrength else PolyWeatherConfig.snowStrength
24+
private val stormStrength: Float get() = if (PolyWeatherConfig.isIrlWeather) RealWeatherHandler.thunderStrength else PolyWeatherConfig.thunderStrength
25+
26+
private var prevRainStrength = 0f
27+
private var prevSnowStrength = 0f
28+
private var prevStormStrength = 0f
29+
30+
@JvmStatic
31+
fun getRainStrength(delta: Float): Float {
32+
if (!isRainy) {
33+
prevRainStrength = 0f
34+
return 0f
35+
}
36+
37+
prevRainStrength = OmniMath.lerp(prevRainStrength, rainStrength, delta)
38+
return prevRainStrength
39+
}
40+
41+
@JvmStatic
42+
fun getSnowStrength(delta: Float): Float {
43+
if (!isSnowy) {
44+
prevSnowStrength = 0f
45+
return 0f
46+
}
47+
48+
prevSnowStrength = OmniMath.lerp(prevSnowStrength, snowStrength, delta)
49+
return prevSnowStrength
50+
}
51+
52+
@JvmStatic
53+
fun getPrecipitationStrength(delta: Float): Float {
54+
return when {
55+
isSnowy -> getSnowStrength(delta)
56+
isRainy -> getRainStrength(delta)
57+
else -> 0f
58+
}
59+
}
60+
61+
@JvmStatic
62+
fun getStormStrength(delta: Float): Float {
63+
if (!isStormy) {
64+
prevStormStrength = 0f
65+
return 0f
66+
}
67+
68+
prevStormStrength = OmniMath.lerp(prevStormStrength, stormStrength, delta)
69+
return prevStormStrength
70+
}
71+
}
Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
11
package org.polyfrost.polyweather.client
22

3-
import org.polyfrost.oneconfig.api.commands.v1.CommandManager
3+
import com.mojang.brigadier.Command
4+
import dev.deftu.omnicore.api.client.commands.OmniClientCommands
5+
import dev.deftu.omnicore.api.client.commands.command
46
import org.polyfrost.oneconfig.utils.v1.dsl.openUI
57
import org.polyfrost.polyweather.PolyWeatherConstants
68
import org.polyfrost.polyweather.client.realtime.RealWeatherHandler
7-
import org.polyfrost.polyweather.util.WeatherType
89

910
object PolyWeatherClient {
10-
@JvmStatic
11-
val isRaining: Boolean
12-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.isRaining else PolyWeatherConfig.weatherType != WeatherType.CLEAR
13-
14-
@JvmStatic
15-
val isThundering: Boolean
16-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.isThundering else PolyWeatherConfig.weatherType == WeatherType.STORM
17-
18-
@JvmStatic
19-
val isSnowing: Boolean
20-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.isSnowing else PolyWeatherConfig.weatherType == WeatherType.SNOW
21-
22-
@JvmStatic
23-
val rainStrength: Float
24-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.rainStrength else PolyWeatherConfig.rainStrength
25-
26-
@JvmStatic
27-
val snowStrength: Float
28-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.rainStrength else PolyWeatherConfig.snowStrength
29-
30-
@JvmStatic
31-
val thunderStrength: Float
32-
get() = if (PolyWeatherConfig.irlWeather) RealWeatherHandler.thunderStrength else PolyWeatherConfig.thunderStrength
33-
3411
fun initialize() {
3512
PolyWeatherConfig.preload()
3613
RealWeatherHandler.initialize()
3714

38-
CommandManager.register(with(CommandManager.literal(PolyWeatherConstants.ID)) {
39-
executes { ctx ->
15+
OmniClientCommands.command(PolyWeatherConstants.ID) {
16+
runs { _ ->
4017
PolyWeatherConfig.openUI()
41-
0
18+
Command.SINGLE_SUCCESS
4219
}
43-
})
20+
}.register()
4421
}
4522
}

src/main/kotlin/org/polyfrost/polyweather/client/PolyWeatherConfig.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,53 @@ import org.polyfrost.oneconfig.api.config.v1.Property
55
import org.polyfrost.oneconfig.api.config.v1.annotations.Checkbox
66
import org.polyfrost.oneconfig.api.config.v1.annotations.Dropdown
77
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider
8+
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
89
import org.polyfrost.polyweather.PolyWeatherConstants
910
import org.polyfrost.polyweather.util.WeatherType
1011

1112
object PolyWeatherConfig : Config("${PolyWeatherConstants.ID}.json", "/assets/polyweather/polyweather_dark.svg", PolyWeatherConstants.NAME, Category.QOL) {
13+
@Switch(
14+
title = "Enable PolyWeather",
15+
description = "Master switch to enable/disable the mod",
16+
category = "Weather"
17+
) @JvmStatic var isEnabled = true
1218

1319
@Dropdown(
1420
title = "Weather",
1521
options = ["Clear", "Rain", "Storm", "Snow"],
1622
category = "Weather"
17-
)
18-
var weather = 0
23+
) var weather = 0
1924

2025
val weatherType: WeatherType
2126
get() = WeatherType.from(weather)
2227

2328
@Checkbox(
2429
title = "Use IRL weather",
2530
category = "Weather"
26-
)
27-
var irlWeather = false
31+
) var isIrlWeather = false
2832

2933
@Slider(
3034
title = "Rain intensity",
3135
min = 0f, max = 1f,
3236
category = "Weather"
33-
)
34-
var rainStrength = 1f
37+
) var rainStrength = 1f
3538

3639
@Slider(
3740
title = "Snow intensity",
3841
min = 0f, max = 1f,
3942
category = "Weather"
40-
)
41-
var snowStrength = 1f
43+
) var snowStrength = 1f
4244

4345
@Slider(
4446
title = "Thunder intensity",
4547
min = 0f, max = 1f,
4648
category = "Weather"
47-
)
48-
var thunderStrength = 1f
49+
) var thunderStrength = 1f
4950

5051
init {
51-
addDependency("weather", "IRL Weather") { if (irlWeather) Property.Display.DISABLED else Property.Display.SHOWN }
52-
addDependency("rainStrength", "Not Snowing") { if (PolyWeatherClient.isRaining && !PolyWeatherClient.isSnowing) Property.Display.SHOWN else Property.Display.DISABLED }
53-
addDependency("snowStrength", "Snowing") { if (PolyWeatherClient.isSnowing) Property.Display.SHOWN else Property.Display.DISABLED }
54-
addDependency("thunderStrength", "Thundering") { if (PolyWeatherClient.isThundering) Property.Display.SHOWN else Property.Display.DISABLED }
52+
addDependency("weather", "IRL Weather") { if (isIrlWeather) Property.Display.DISABLED else Property.Display.SHOWN }
53+
addDependency("rainStrength", "Not Snowing") { if (ClientWeatherManager.isRainy && !ClientWeatherManager.isSnowy) Property.Display.SHOWN else Property.Display.DISABLED }
54+
addDependency("snowStrength", "Snowing") { if (ClientWeatherManager.isSnowy) Property.Display.SHOWN else Property.Display.DISABLED }
55+
addDependency("thunderStrength", "Thundering") { if (ClientWeatherManager.isStormy) Property.Display.SHOWN else Property.Display.DISABLED }
5556
}
56-
}
57+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@file:Suppress("FunctionName")
2+
3+
package org.polyfrost.polyweather.client
4+
5+
interface WeatherStorage {
6+
fun `polyweather$isRaining`(): Boolean
7+
}

src/main/kotlin/org/polyfrost/polyweather/client/realtime/RealWeatherHandler.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ object RealWeatherHandler {
6363
return interpolate(currentCode.thunderStrength, nextCode.thunderStrength, currentTime)
6464
}
6565

66-
val isRaining: Boolean
66+
val isRainy: Boolean
6767
get() = rainStrength > 0.05
6868

69-
val isThundering: Boolean
69+
val isStormy: Boolean
7070
get() = thunderStrength > 0.05
7171

72-
val isSnowing: Boolean
72+
val isSnowy: Boolean
7373
get() {
7474
val currentCode = currentCode ?: return false // Caches the value
7575
return currentCode.snow
7676
}
7777

7878
fun initialize() {
79-
if (!PolyWeatherConfig.irlWeather) {
79+
if (!PolyWeatherConfig.isIrlWeather) {
8080
return
8181
}
8282

0 commit comments

Comments
 (0)