|
1 | 1 | package org.polyfrost.polyweather.mixin; |
2 | 2 |
|
| 3 | +import net.minecraft.client.multiplayer.WorldClient; |
| 4 | +import net.minecraft.profiler.Profiler; |
| 5 | +import net.minecraft.util.BlockPos; |
3 | 6 | 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; |
4 | 12 | import org.polyfrost.polyweather.client.PolyWeatherClient; |
5 | 13 | import org.polyfrost.polyweather.client.PolyWeatherConfig; |
| 14 | +import org.polyfrost.polyweather.client.WeatherStorage; |
6 | 15 | import org.spongepowered.asm.mixin.Mixin; |
| 16 | +import org.spongepowered.asm.mixin.Unique; |
7 | 17 | import org.spongepowered.asm.mixin.injection.At; |
8 | 18 | import org.spongepowered.asm.mixin.injection.Inject; |
9 | 19 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
10 | 20 |
|
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); |
17 | 30 | } |
| 31 | + |
| 32 | + return super.getRainStrength(delta); |
18 | 33 | } |
19 | 34 |
|
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); |
24 | 38 | } |
| 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; |
25 | 71 | } |
26 | 72 | } |
0 commit comments