Skip to content

Commit

Permalink
Refactor and arrangement for future port
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Jan 3, 2025
1 parent 822514c commit bac5533
Show file tree
Hide file tree
Showing 23 changed files with 212 additions and 146 deletions.
4 changes: 4 additions & 0 deletions common/src/main/java/org/orecruncher/dsurround/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.orecruncher.dsurround.eventing.ClientState;
import org.orecruncher.dsurround.lib.registry.ReloadListener;
import org.orecruncher.dsurround.lib.resources.ResourceUtilities;
import org.orecruncher.dsurround.lib.seasons.ISeasonalInformation;
import org.orecruncher.dsurround.lib.seasons.SeasonManager;
import org.orecruncher.dsurround.lib.version.IVersionChecker;
import org.orecruncher.dsurround.lib.version.VersionChecker;
import org.orecruncher.dsurround.lib.version.VersionResult;
Expand Down Expand Up @@ -127,6 +129,8 @@ public void initializeClient() {
.registerSingleton(ISoundLibrary.class, SoundLibrary.class)
.registerSingleton(IBiomeLibrary.class, BiomeLibrary.class)
.registerSingleton(IDimensionLibrary.class, DimensionLibrary.class)
.registerSingleton(IDimensionInformation.class, DimensionInformation.class)
.registerFactory(ISeasonalInformation.class, () -> SeasonManager.HANDLER)
.registerSingleton(IBlockLibrary.class, BlockLibrary.class)
.registerSingleton(IItemLibrary.class, ItemLibrary.class)
.registerSingleton(IEntityEffectLibrary.class, EntityEffectLibrary.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.orecruncher.dsurround.config.dimension;
package org.orecruncher.dsurround.config;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.orecruncher.dsurround.config.libraries;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.resources.ResourceLocation;

public interface IDimensionInformation {
/**
* The resource location ID of the dimension
*/
ResourceLocation name();
/**
* The client level for the dimension
*/
ClientLevel level();
/**
* The sea level configured for the dimension
*/
int seaLevel();
/**
* Whether the dimension is considered always outside, like Nether.
*/
boolean alwaysOutside();
/**
* The vertical Y level which is the threshold of outer space.
*/
int getSpaceHeight();
/**
* The veritical Y level where clouds are expected to be
*/
int getCloudHeight();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.orecruncher.dsurround.config.libraries;

import net.minecraft.world.level.Level;
import org.orecruncher.dsurround.config.dimension.DimensionInfo;
import org.orecruncher.dsurround.config.DimensionInfo;

public interface IDimensionLibrary extends ILibrary {
DimensionInfo getData(final Level world);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.orecruncher.dsurround.config.libraries.impl;

import dev.architectury.event.events.client.ClientLifecycleEvent;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.resources.ResourceLocation;
import org.orecruncher.dsurround.config.DimensionInfo;
import org.orecruncher.dsurround.config.libraries.AssetLibraryEvent;
import org.orecruncher.dsurround.config.libraries.IDimensionInformation;
import org.orecruncher.dsurround.config.libraries.IDimensionLibrary;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.events.HandlerPriority;

public class DimensionInformation implements IDimensionInformation {

private final IDimensionLibrary dimensionLibrary;
private DimensionInfo info;

public DimensionInformation(IDimensionLibrary dimensionLibrary) {
this.dimensionLibrary = dimensionLibrary;

// Need to reset the cached dimension info whenever the client world
// changes or if there is a resource reload.
ClientLifecycleEvent.CLIENT_LEVEL_LOAD.register(state -> this.info = null);
AssetLibraryEvent.RELOAD.register((x, y) -> this.info = null, HandlerPriority.HIGH);
}

public ResourceLocation name() {
return this.getInfo().getName();
}

public ClientLevel level() {
return GameUtils.getWorld().orElseThrow();
}

public int seaLevel() {
return this.getInfo().getSeaLevel();
}

public boolean alwaysOutside() {
return this.getInfo().alwaysOutside();
}

public int getSpaceHeight() {
return this.getInfo().getSpaceHeight();
}

public int getCloudHeight() {
return this.getInfo().getCloudHeight();
}

private DimensionInfo getInfo() {
if (this.info == null)
this.info = this.dimensionLibrary.getData(this.level());
return this.info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import org.orecruncher.dsurround.config.data.DimensionConfigRule;
import org.orecruncher.dsurround.config.dimension.DimensionInfo;
import org.orecruncher.dsurround.config.DimensionInfo;
import org.orecruncher.dsurround.config.libraries.IDimensionLibrary;
import org.orecruncher.dsurround.config.libraries.IReloadEvent;
import org.orecruncher.dsurround.lib.collections.ObjectArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.orecruncher.dsurround.effects.particles.FrostBreathParticle;
import org.orecruncher.dsurround.lib.GameUtils;
import org.orecruncher.dsurround.lib.di.ContainerManager;
import org.orecruncher.dsurround.lib.seasons.ISeasonalInformation;
import org.orecruncher.dsurround.lib.system.ITickCount;
import org.orecruncher.dsurround.lib.random.MurmurHash3;
import org.orecruncher.dsurround.lib.world.WorldUtils;

public class BreathEffect extends EntityEffectBase {

Expand Down Expand Up @@ -83,8 +81,7 @@ protected boolean showWaterBubbles(final BlockState headBlock) {

protected boolean showFrostBreath(final LivingEntity entity, final BlockState headBlock, final BlockPos pos) {
if (headBlock.isAir()) {
final Level world = entity.level();
return SEASONAL_INFORMATION.isColdTemperature(world, pos);
return SEASONAL_INFORMATION.isColdTemperature(pos);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tick(Minecraft client) {

this.clockDisplay.clear();
this.clockDisplay.add(this.clock.getFormattedTime());
this.seasonalInformation.getCurrentSeasonTranslated(player.level()).ifPresent(this.clockDisplay::add);
this.seasonalInformation.getCurrentSeasonTranslated().ifPresent(this.clockDisplay::add);

var textRender = GameUtils.getTextRenderer();
this.renderWidth = textRender.width(this.clockDisplay.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void onCollect(CollectDiagnosticsEvent event) {
this.clock.update(world);
event.add(CollectDiagnosticsEvent.Section.Header, this.clock.getFormattedTime());

var seasonInfo = this.seasonalInformation.getCurrentSeasonTranslated(world).orElse(Component.literal("UNKNOWN"));
var seasonInfo = this.seasonalInformation.getCurrentSeasonTranslated().orElse(Component.literal("UNKNOWN"));
var seasonText = Component.translatable("Season: %s (%s)", seasonInfo, this.seasonalInformation.getProviderName());
event.add(CollectDiagnosticsEvent.Section.Header, seasonText);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.orecruncher.dsurround.lib.platform.*;
import org.orecruncher.dsurround.eventing.ClientState;
import org.orecruncher.dsurround.lib.logging.IModLog;
import org.orecruncher.dsurround.lib.seasons.ISeasonalInformation;
import org.orecruncher.dsurround.lib.seasons.SeasonManager;
import org.orecruncher.dsurround.lib.system.ISystemClock;
import org.orecruncher.dsurround.lib.system.ITickCount;
import org.orecruncher.dsurround.lib.system.SystemClock;
Expand Down Expand Up @@ -52,7 +50,6 @@ private static void configureServiceDependencies() {
.registerSingleton(ISystemClock.class, SystemClock.class)
.registerSingleton(IMinecraftDirectories.class, modInfo)
.registerSingleton(IClientTasking.class, ClientTasking.class)
.registerSingleton(ITickCount.class, TickCounter.class)
.registerSingleton(ISeasonalInformation.class, SeasonManager.HANDLER);
.registerSingleton(ITickCount.class, TickCounter.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.orecruncher.dsurround.lib.seasons;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.Heightmap;
import org.orecruncher.dsurround.lib.GameUtils;

import java.util.Optional;

Expand All @@ -18,95 +19,99 @@ public interface ISeasonalInformation {
/**
* Gets the name of the current season, if any
*/
Optional<Component> getCurrentSeason(Level world);
Optional<Component> getCurrentSeason();

/**
* Gets the translated season name from the provider resources.
*/
Optional<Component> getCurrentSeasonTranslated(Level world);
Optional<Component> getCurrentSeasonTranslated();

/**
* Indicates if the current season is considered Spring.
*/
default boolean isSpring(Level world) {
default boolean isSpring() {
return true;
}

/**
* Indicates if the current season is considered Summer.
*/
default boolean isSummer(Level world) {
default boolean isSummer() {
return false;
}

/**
* Indicates if the current season is considered Autumn/Fall.
*/
default boolean isAutumn(Level world) {
default boolean isAutumn() {
return false;
}

/**
* Indicates if the current season is considered Winter.
*/
default boolean isWinter(Level world) {
default boolean isWinter() {
return false;
}

/**
* Gets the temperature at the specified block location taking into account any seasonal variance.
*/
float getTemperature(Level world, BlockPos blockPos);
float getTemperature(BlockPos blockPos);

/**
* Indicates whether the temperature at the given position is considered cold. For example, if the temp
* is cold, the frost breath effect can be produced.
*/
default boolean isColdTemperature(Level world, BlockPos blockPos) {
return this.getTemperature(world, blockPos) < 0.2F;
default boolean isColdTemperature(BlockPos blockPos) {
return this.getTemperature(blockPos) < 0.2F;
}

/**
* Indicates whether the temperature at the given position is considered cold enough for snow.
*/
default boolean isSnowTemperature(Level world, BlockPos blockPos) {
return this.getTemperature(world, blockPos) < 0.15F;
default boolean isSnowTemperature(BlockPos blockPos) {
return this.getTemperature(blockPos) < 0.15F;
}

/**
* Gets the Y on the XZ plane at which precipitation will strike.
*/
default int getPrecipitationHeight(Level world, BlockPos pos) {
return world.getHeight(Heightmap.Types.MOTION_BLOCKING, pos.getX(), pos.getZ());
default int getPrecipitationHeight(BlockPos pos) {
return this.level().getHeight(Heightmap.Types.MOTION_BLOCKING, pos.getX(), pos.getZ());
}

/**
* Gets the possible precipitation that can occur in the biome at the specified position.
*/
default Biome.Precipitation getPrecipitationAt(Level world, BlockPos blockPos) {
return world.getBiome(blockPos).value().getPrecipitationAt(blockPos);
default Biome.Precipitation getPrecipitationAt(BlockPos blockPos) {
return this.level().getBiome(blockPos).value().getPrecipitationAt(blockPos);
}

/**
* Gets the active precipitation occurring at the specified position.
*/
default Biome.Precipitation getActivePrecipitation(Level world, BlockPos pos) {
if (!world.isRaining()) {
default Biome.Precipitation getActivePrecipitation(BlockPos pos) {
if (!this.level().isRaining()) {
// Not currently raining
return Biome.Precipitation.NONE;
}

// If the biome has no rain...
if (this.getPrecipitationAt(world, pos) == Biome.Precipitation.NONE)
if (this.getPrecipitationAt(pos) == Biome.Precipitation.NONE)
return Biome.Precipitation.NONE;

// Is there a block above that is blocking the rainfall?
var p = this.getPrecipitationHeight(world, pos);
var p = this.getPrecipitationHeight(pos);
if (p > pos.getY()) {
return Biome.Precipitation.NONE;
}

// Use the temperature of the biome to get whether it is raining or snowing
return this.isSnowTemperature(world, pos) ? Biome.Precipitation.SNOW : Biome.Precipitation.RAIN;
return this.isSnowTemperature(pos) ? Biome.Precipitation.SNOW : Biome.Precipitation.RAIN;
}

default ClientLevel level() {
return GameUtils.getWorld().orElseThrow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.architectury.platform.Platform;
import org.orecruncher.dsurround.Constants;
import org.orecruncher.dsurround.lib.Library;
import org.orecruncher.dsurround.lib.di.ContainerManager;
import org.orecruncher.dsurround.lib.seasons.compat.SereneSeasons;
import org.orecruncher.dsurround.lib.seasons.compat.VanillaSeasons;

Expand All @@ -12,9 +13,9 @@ public class SeasonManager {

static {
if (Platform.isModLoaded(Constants.SERENE_SEASONS)) {
HANDLER = new SereneSeasons();
HANDLER = ContainerManager.resolve(SereneSeasons.class);
} else {
HANDLER = new VanillaSeasons();
HANDLER = ContainerManager.resolve(VanillaSeasons.class);
}

Library.LOGGER.info("Season provider: %s", HANDLER.getProviderName());
Expand Down
Loading

0 comments on commit bac5533

Please sign in to comment.