Skip to content

Commit

Permalink
Condition for applying fog based on the temperature of the biome the …
Browse files Browse the repository at this point in the history
…player is in
  • Loading branch information
NaoCraftLab committed Oct 9, 2024
1 parent 5b18b2d commit 91bfd04
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ They can be used in any combination thanks to AND, OR, and NOT conditions

- Dimension the player is in
- Biome the player is in
- World difficulty level
- Biome temperature
- Weather
- Time of day
- World difficulty level

### Full Configuration

Expand Down Expand Up @@ -151,6 +152,16 @@ Preset files are located in the `config/foggypalegarden` directory. Each file co

// (optional) list of biomes where this binding is applied
"biomeIdIn": [""],

// (optional) biome temperature range where this binding is applied
"biomeTemperature": {

// (optional) minimum temperature (inclusive)
"min": 0.0,

// (optional) maximum temperature (exclusive)
"max": 0.0
},

// (optional) list of difficulty levels where this binding is applied
"difficultyIn": [""],
Expand Down Expand Up @@ -237,8 +248,8 @@ If you encounter compatibility issues between Foggy Pale Garden and other mods,
✅ Add fog to the Pale Garden<br/>
✅ Add configurations<br/>
✅ Apply fog conditions depending on player’s current dimension<br/>
✅ Apply fog conditions based on biome temperature<br/>
🚀 Disable fog based on game mode<br/>
🚀 Apply fog conditions based on biome temperature<br/>
🚀 Control the shape of fog<br/>
🚀 (After the Winter Drop release) Port to NeoForge<br/>
🚀 (After the Winter Drop release) Add visual configuration<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public record Binding(
public record Condition(
Set<String> dimensionIn,
Set<String> biomeIdIn,
Temperature biomeTemperature,
Set<Difficulty> difficultyIn,
Set<Weather> weatherIn,
TimePeriod timeIn,
Expand All @@ -77,10 +78,28 @@ public record TimePeriod(

public void validate() {
if (start == null || end == null) {
throw new IllegalStateException("TimePeriod start and end cannot be null");
throw new FoggyPaleGardenConfigurationException("TimePeriod start and end cannot be null");
}
if (start < 0 || start >= 24000 || end < 0 || end >= 24000) {
throw new IllegalStateException("TimePeriod start and end must be in the range [0, 24000)");
throw new FoggyPaleGardenConfigurationException(
"TimePeriod start and end must be in the range [0, 24000)"
);
}
}
}

@Builder
public record Temperature(
Float min,
Float max
) {

public void validate() {
if (min == null && max == null) {
throw new FoggyPaleGardenConfigurationException("Temperature min and max cannot be both null");
}
if (min != null && max != null && min >= max) {
throw new FoggyPaleGardenConfigurationException("Temperature min must be less than max");
}
}
}
Expand All @@ -90,6 +109,10 @@ public void validate() {
if (dimensionIn != null && !dimensionIn.isEmpty()) {
filledFields++;
}
if (biomeTemperature != null) {
filledFields++;
biomeTemperature.validate();
}
if (biomeIdIn != null && !biomeIdIn.isEmpty()) {
filledFields++;
}
Expand All @@ -107,7 +130,7 @@ public void validate() {
filledFields++;
for (Condition condition : and) {
if (condition == null) {
throw new IllegalStateException("AND list contains a null condition");
throw new FoggyPaleGardenConfigurationException("AND list contains a null condition");
}
condition.validate();
}
Expand All @@ -116,7 +139,7 @@ public void validate() {
filledFields++;
for (Condition condition : or) {
if (condition == null) {
throw new IllegalStateException("OR list contains a null condition");
throw new FoggyPaleGardenConfigurationException("OR list contains a null condition");
}
condition.validate();
}
Expand All @@ -127,7 +150,9 @@ public void validate() {
}

if (filledFields != 1) {
throw new IllegalStateException("In one instance of condition, only one of the fields should be filled");
throw new FoggyPaleGardenConfigurationException(
"In one instance of condition, only one of the fields should be filled"
);
}
}

Expand All @@ -152,6 +177,20 @@ public Predicate<Environment> toPredicate() {
if (biomeIdIn != null && !biomeIdIn.isEmpty()) {
predicate = predicate.and(env -> biomeIdIn.contains(env.biome()));
}
if (biomeTemperature != null) {
val min = biomeTemperature.min();
val max = biomeTemperature.max();
predicate = predicate.and(env -> {
val temperature = env.biomeTemperature();
if (min != null && max != null) {
return temperature >= min && temperature <= max;
} else if (min != null) {
return temperature >= min;
} else {
return temperature <= max;
}
});
}
if (difficultyIn != null && !difficultyIn.isEmpty()) {
predicate = predicate.and(env -> difficultyIn.contains(env.difficulty()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public record Environment(
String dimension,
String biome,
Float biomeTemperature,
Difficulty difficulty,
Weather weather,
long timeOfDay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private static void injectApplyFog(
Environment.builder()
.dimension(world.getRegistryKey().getValue().toString())
.biome(biomeEntry.getIdAsString())
.biomeTemperature(biomeEntry.value().getTemperature())
.difficulty(world.getDifficulty())
.weather(resolveWeather(world))
.timeOfDay(world.getTimeOfDay())
Expand Down

0 comments on commit 91bfd04

Please sign in to comment.