Public Access
This commit is contained in:
1 parent
251d0a2de8
commit
b65f9379e3
5 files changed
+83
-2
No files matched your search
@@ -12,6 +12,7 @@ import net.dnorberg.rivencraft.network.ModNetworking;
|
||||
import net.dnorberg.rivencraft.config.RivencraftConfig;
|
||||
import net.dnorberg.rivencraft.config.RivencraftClientConfig;
|
||||
import net.dnorberg.rivencraft.book.AgeDimensionService;
|
||||
import net.dnorberg.rivencraft.book.AgeWeatherService;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
@@ -36,6 +37,7 @@ public final class Rivencraft {
|
||||
ModSounds.register(modEventBus);
|
||||
ModCreativeTabs.register(modEventBus);
|
||||
NeoForge.EVENT_BUS.addListener(BookStandConversionHandler::onRightClickBlock);
|
||||
NeoForge.EVENT_BUS.addListener(AgeWeatherService::onLevelTickPost);
|
||||
LOGGER.info("Initializing Rivencraft");
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public record AgeDefinition(
|
||||
public static final ResourceLocation RANDOM_VANILLA_PROFILE = ResourceLocation.fromNamespaceAndPath(
|
||||
Rivencraft.MOD_ID, "random_vanilla"
|
||||
);
|
||||
public static final int CURRENT_GENERATION_VERSION = 4;
|
||||
public static final int CURRENT_GENERATION_VERSION = 5;
|
||||
|
||||
public AgeDefinition {
|
||||
Objects.requireNonNull(id, "id");
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.dnorberg.rivencraft.book;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||
|
||||
/** Applies persisted Legacy-inspired weather behavior to loaded Ages. */
|
||||
public final class AgeWeatherService {
|
||||
private static final int FIXED_WEATHER_DURATION = 6000;
|
||||
private static final Map<ServerLevel, WeatherState> STATES = new WeakHashMap<>();
|
||||
|
||||
private AgeWeatherService() {
|
||||
}
|
||||
|
||||
public static void onLevelTickPost(LevelTickEvent.Post event) {
|
||||
if (!(event.getLevel() instanceof ServerLevel level)
|
||||
|| !level.dimension().location().getNamespace().equals(Rivencraft.MOD_ID)) {
|
||||
return;
|
||||
}
|
||||
AgeDefinition age = AgeRegistrySavedData.get(level)
|
||||
.findByDimension(level.dimension().location())
|
||||
.orElse(null);
|
||||
if (age == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AgeTraits.Weather weather = age.traits().weather();
|
||||
if (weather == AgeTraits.Weather.NORMAL) {
|
||||
STATES.remove(level);
|
||||
return;
|
||||
}
|
||||
|
||||
if (weather == AgeTraits.Weather.FAST || weather == AgeTraits.Weather.SLOW) {
|
||||
applyVariableWeather(level, weather);
|
||||
} else {
|
||||
STATES.remove(level);
|
||||
applyFixedWeather(level, weather);
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyVariableWeather(
|
||||
ServerLevel level,
|
||||
AgeTraits.Weather weather
|
||||
) {
|
||||
WeatherState current = new WeatherState(level.isRaining(), level.isThundering());
|
||||
WeatherState previous = STATES.put(level, current);
|
||||
if (current.equals(previous)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int scale = weather == AgeTraits.Weather.FAST ? 1 : 4;
|
||||
int rainBase = 6000 * scale;
|
||||
int rainRange = (current.raining() ? 6000 : 84000) * scale;
|
||||
int duration = rainBase + level.getRandom().nextInt(rainRange);
|
||||
level.setWeatherParameters(0, duration, current.raining(), current.thundering());
|
||||
}
|
||||
|
||||
private static void applyFixedWeather(ServerLevel level, AgeTraits.Weather weather) {
|
||||
boolean raining = weather != AgeTraits.Weather.OFF;
|
||||
boolean thundering = weather == AgeTraits.Weather.STORM;
|
||||
if (level.isRaining() != raining || level.isThundering() != thundering
|
||||
|| level.getGameTime() % 200L == 0L) {
|
||||
level.setWeatherParameters(0, FIXED_WEATHER_DURATION, raining, thundering);
|
||||
}
|
||||
}
|
||||
|
||||
private record WeatherState(boolean raining, boolean thundering) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user