use of org.spongepowered.api.event.world.ChangeWeatherEvent in project SpongeCommon by SpongePowered.
the class ServerLevelMixin method impl$onSetWeatherParameters.
@Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "FIELD", target = "Lnet/minecraft/server/level/ServerLevel;oRainLevel:F", shift = At.Shift.BEFORE, ordinal = 1))
public void impl$onSetWeatherParameters(final BooleanSupplier param0, final CallbackInfo ci, final ProfilerFiller var0, final boolean wasRaining) {
final boolean isRaining = this.shadow$isRaining();
if (this.oRainLevel != this.rainLevel || this.oThunderLevel != this.thunderLevel || wasRaining != isRaining) {
Weather newWeather = ((ServerWorld) this).properties().weather();
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
final Transaction<Weather> weatherTransaction = new Transaction<>(this.impl$prevWeather, newWeather);
final ChangeWeatherEvent event = SpongeEventFactory.createChangeWeatherEvent(currentCause, ((ServerWorld) this), weatherTransaction);
if (Sponge.eventManager().post(event)) {
newWeather = event.weather().original();
} else {
newWeather = event.weather().finalReplacement();
}
// Set event results
this.impl$prevWeather = newWeather;
if (newWeather.type() == WeatherTypes.CLEAR.get()) {
this.serverLevelData.setThunderTime(0);
this.serverLevelData.setRainTime(0);
this.serverLevelData.setClearWeatherTime((int) newWeather.remainingDuration().ticks());
this.serverLevelData.setThundering(false);
this.serverLevelData.setRaining(false);
} else {
final int newTime = (int) newWeather.remainingDuration().ticks();
this.serverLevelData.setRaining(true);
this.serverLevelData.setClearWeatherTime(0);
this.serverLevelData.setRainTime(newTime);
if (newWeather.type() == WeatherTypes.THUNDER.get()) {
this.serverLevelData.setThunderTime(newTime);
this.serverLevelData.setThundering(true);
} else {
this.serverLevelData.setThunderTime(0);
this.serverLevelData.setThundering(false);
}
}
}
}
Aggregations