3 Commits
1.1.0 ... 1.2.0

Author SHA1 Message Date
8c344ec47d 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
2024-10-21 19:05:51 +13:00
Amirhan-Taipovjan-Greatest-I
2dc3d64ca1 Actualized Tatar and Russian Translations! (#9)
* Actualized Vanilla-ish Tatar Translation!

* Updated ≈Vanilla-ish Russian Translation!
2024-08-18 14:00:50 +12:00
Thierry Schmid
c5f5a278e3 Timer functionality as suggested a month ago (#7)
* first implementation of timer

* first implementation of timer

* String message turned to a translatable text
2024-08-10 22:34:26 +12:00
8 changed files with 137 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import me.lucaslah.weatherchanger.keys.ToggleClearKey;
import me.lucaslah.weatherchanger.keys.ToggleOffKey;
import me.lucaslah.weatherchanger.keys.ToggleRainKey;
import me.lucaslah.weatherchanger.keys.ToggleThunderKey;
import me.lucaslah.weatherchanger.timerlogic.Timer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
@@ -27,6 +28,8 @@ public class WeatherChanger {
private static WeatherChangerPlatform platform;
private static KeybindingManager keybindingManager;
private static CommandManager commandManager;
private static Timer weatherTimer;
private static boolean timerEnabled = false; // Default to false
public static void init(WeatherChangerPlatform platform) {
WeatherChanger.platform = platform;
@@ -57,6 +60,8 @@ public class WeatherChanger {
.add(new ToggleThunderKey());
commandManager.add(new WeatherChangerCommand());
weatherTimer = new Timer();
}
private static void loadConfig() {
@@ -151,4 +156,12 @@ public class WeatherChanger {
public static void sendClientMessage(Text message) {
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(message);
}
public static void toggleTimer() {
timerEnabled = !timerEnabled;
}
public static boolean isTimerEnabled() {
return timerEnabled;
}
}

View File

@@ -48,6 +48,15 @@ public class WeatherChangerCommand extends Command {
})
);
command.then(LiteralArgumentBuilder.<T>literal("toggleTimer")
.executes(context -> {
WeatherChanger.toggleTimer();
Text message = WeatherChanger.isTimerEnabled() ? Text.translatable("commands.weatherchanger.timer.on") : Text.translatable("commands.weatherchanger.timer.off");
sendClientMessage(message);
return 1;
})
);
LiteralCommandNode<T> node = dispatcher.register(command);
dispatcher.register(LiteralArgumentBuilder.<T>literal("cweather").redirect(node));
}

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

@@ -0,0 +1,66 @@
package me.lucaslah.weatherchanger.timerlogic;
import me.lucaslah.weatherchanger.WeatherChanger;
import me.lucaslah.weatherchanger.config.WcMode;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.Random;
public class Timer {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final Random random = new Random();
public Timer() {
scheduleWeatherChange();
scheduleWeatherIntensityAdjustment();
}
private void scheduleWeatherChange() {
int initialDelay = 0; // Start immediately
int delay = 20 + random.nextInt(11); // 20-30 minutes
scheduler.scheduleWithFixedDelay(this::decideWeather, initialDelay, delay, TimeUnit.MINUTES);
}
private void decideWeather() {
if (!WeatherChanger.isTimerEnabled()) return;
if (random.nextDouble() < 0.75) { // 75% chance to change the weather
if (random.nextDouble() < 0.66) { // 66% chance for rain
WeatherChanger.setMode(WcMode.RAIN);
} else { // 33% chance for thunderstorm
WeatherChanger.setMode(WcMode.THUNDER);
}
}
}
private void scheduleWeatherIntensityAdjustment() {
int initialDelay = 1; // Start after 1 minute
int delay = 1 + random.nextInt(2); // 1-2 minutes
scheduler.scheduleWithFixedDelay(this::adjustWeatherIntensity, initialDelay, delay, TimeUnit.MINUTES);
}
private void adjustWeatherIntensity() {
if (!WeatherChanger.isTimerEnabled()) return;
WcMode currentMode = WeatherChanger.getMode();
double chance = random.nextDouble();
if (currentMode == WcMode.RAIN) {
if (chance < 0.05) { // 5% chance to worsen from rain to thunderstorm
WeatherChanger.setMode(WcMode.THUNDER);
} else if (chance < 0.20) { // 15% chance to clear up from rain
WeatherChanger.setMode(WcMode.CLEAR);
}
} else if (currentMode == WcMode.THUNDER) {
if (chance < 0.05) { // 5% chance to worsen, but already at worst so no change
// No change
} else if (chance < 0.20) { // 15% chance to improve from thunderstorm to rain
WeatherChanger.setMode(WcMode.RAIN);
}
} else if (currentMode == WcMode.CLEAR) {
// No change, clear weather cannot improve or worsen in this context
}
}
}

View File

@@ -3,6 +3,8 @@
"commands.weatherchanger.set.clear": "Set client weather to: Clear",
"commands.weatherchanger.set.rain": "Set client weather to: Rain",
"commands.weatherchanger.set.thunder": "Set client weather to: Thunder",
"commands.weatherchanger.timer.on": "Timer enabled",
"commands.weatherchanger.timer.off": "Timer disabled",
"keys.weatherchanger.off.name": "Toggle Weather Off",
"keys.weatherchanger.clear.name": "Toggle Weather Clear",
"keys.weatherchanger.rain.name": "Toggle Weather Rain",

View File

@@ -4,6 +4,8 @@
"commands.weatherchanger.set.clear": "Установлена клиентская погода: Ясная",
"commands.weatherchanger.set.rain": "Установлена клиентская погода: Дождливая",
"commands.weatherchanger.set.thunder": "Установлена клиентская погода: Гроза и дождь",
"commands.weatherchanger.timer.on": "Таймер включен",
"commands.weatherchanger.timer.off": "Таймер выключен",
"keys.weatherchanger.off.name": "Выключить клиентскую погоду",
"keys.weatherchanger.clear.name": "Переключить ясную погоду",
"keys.weatherchanger.rain.name": "Переключить дождливую погоду",

View File

@@ -5,6 +5,8 @@
"commands.weatherchanger.set.clear": "Клиентлы һава торышы урнаштырылды: Аяз",
"commands.weatherchanger.set.rain": "Клиентлы һава торышы урнаштырылды: Яңгырлы",
"commands.weatherchanger.set.thunder": "Клиентлы һава торышы урнаштырылды: Яшенле һәм яңгырлы",
"commands.weatherchanger.timer.on": "Таймер кушык",
"commands.weatherchanger.timer.off": "Таймер сүнек",
"keys.weatherchanger.off.name": "Клиентлы һава торышын сүндерү",
"keys.weatherchanger.clear.name": "Аяз һава торышын күчерү",
"keys.weatherchanger.rain.name": "Яңгырлы һава торышын күчерү",

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