fix: client allowing trident use while server weather not thundering

This change fixes some issues where when using weather changer and setting your client weather to thunder trident usage would be allowed even when the server weather was not thundering, also fixes an issue where on single player mobs would spawn when client weather was set to rain or thunder

This commit also releases version 1.2.0
This commit is contained in:
2024-10-21 19:05:51 +13:00
parent 2dc3d64ca1
commit 8c344ec47d
2 changed files with 43 additions and 1 deletions

View File

@@ -2,14 +2,21 @@ package me.lucaslah.weatherchanger.mixin;
import me.lucaslah.weatherchanger.WeatherChanger;
import me.lucaslah.weatherchanger.config.WcMode;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Environment(EnvType.CLIENT)
@Mixin(World.class)
public class WorldMixin {
@Shadow
@@ -21,6 +28,23 @@ public class WorldMixin {
@Shadow
protected float thunderGradient;
@Shadow @Final private RegistryEntry<DimensionType> dimensionEntry;
@Unique
private float weatherChanger$getRainGradientOg(float delta) {
return MathHelper.lerp(delta, this.rainGradientPrev, this.rainGradient);
}
@Unique
private float weatherChanger$getThunderGradientOg(float delta) {
return MathHelper.lerp(delta, this.thunderGradientPrev, this.thunderGradient) * this.weatherChanger$getRainGradientOg(delta);
}
@Unique
public DimensionType weatherChanger$getDimension() {
return this.dimensionEntry.value();
}
@Inject(method = "getRainGradient", at = @At("HEAD"), cancellable = true)
public void getRainGradient(float delta, CallbackInfoReturnable<Float> callback) {
WcMode mode = WeatherChanger.getMode();
@@ -50,4 +74,22 @@ public class WorldMixin {
callback.cancel();
}
@Inject(method = "isRaining", at = @At("HEAD"), cancellable = true)
public void isRaining(CallbackInfoReturnable<Boolean> callback) {
callback.setReturnValue((double)this.weatherChanger$getRainGradientOg(1.0F) > 0.2);
callback.cancel();
}
@Inject(method = "isThundering", at = @At("HEAD"), cancellable = true)
public void isThundering(CallbackInfoReturnable<Boolean> callback) {
if (this.weatherChanger$getDimension().hasSkyLight() && !(this.weatherChanger$getDimension().hasCeiling())) {
callback.setReturnValue((double)this.weatherChanger$getThunderGradientOg(1.0F) > 0.9);
} else {
callback.setReturnValue(false);
}
callback.cancel();
}
}

View File

@@ -13,7 +13,7 @@ yarn_mappings=1.21+build.7
enabled_platforms=fabric,forge
# Mod Properties
mod_version = 1.1.0
mod_version = 1.2.0
mod_id = weatherchanger
maven_group = me.lucaslah.weatherchanger
archives_base_name = weather-changer