Remove precipitation enum and add boolean (#2648)

This commit is contained in:
GreatWyrm 2025-02-04 04:24:30 -08:00 committed by GitHub
parent 87f6524aeb
commit 10c7d711de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 18 deletions

View File

@ -37,16 +37,12 @@ public sealed interface Biome extends Biomes, ProtocolObject permits BiomeImpl {
@NotNull BiomeEffects effects();
@NotNull Precipitation precipitation();
boolean hasPrecipitation();
@NotNull TemperatureModifier temperatureModifier();
@Nullable Registry.BiomeEntry registry();
enum Precipitation {
NONE, RAIN, SNOW;
}
enum TemperatureModifier {
NONE, FROZEN;
}
@ -78,7 +74,7 @@ public sealed interface Biome extends Biomes, ProtocolObject permits BiomeImpl {
private float temperature = 0.25f;
private float downfall = 0.8f;
private BiomeEffects effects = DEFAULT_EFFECTS;
private Precipitation precipitation = Precipitation.RAIN;
private boolean hasPrecipitation = false;
private TemperatureModifier temperatureModifier = TemperatureModifier.NONE;
private Builder() {
@ -103,8 +99,8 @@ public sealed interface Biome extends Biomes, ProtocolObject permits BiomeImpl {
}
@Contract(value = "_ -> this", pure = true)
public @NotNull Builder precipitation(@NotNull Biome.Precipitation precipitation) {
this.precipitation = precipitation;
public @NotNull Builder hasPrecipitation(boolean precipitation) {
this.hasPrecipitation = precipitation;
return this;
}
@ -116,7 +112,7 @@ public sealed interface Biome extends Biomes, ProtocolObject permits BiomeImpl {
@Contract(pure = true)
public @NotNull Biome build() {
return new BiomeImpl(temperature, downfall, effects, precipitation, temperatureModifier, null);
return new BiomeImpl(temperature, downfall, effects, hasPrecipitation, temperatureModifier, null);
}
}
}

View File

@ -12,12 +12,12 @@ record BiomeImpl(
float temperature,
float downfall,
@NotNull BiomeEffects effects,
@NotNull Precipitation precipitation,
boolean hasPrecipitation,
@NotNull TemperatureModifier temperatureModifier,
@Nullable Registry.BiomeEntry registry
) implements Biome {
// https://minecraft.wiki/w/Rain
private final static Double SNOW_TEMPERATURE = 0.15;
private final static double SNOW_TEMPERATURE = 0.15;
static final BinaryTagSerializer<Biome> REGISTRY_NBT_TYPE = BinaryTagSerializer.COMPOUND.map(
tag -> {
@ -27,8 +27,7 @@ record BiomeImpl(
CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder()
.putFloat("temperature", biome.temperature())
.putFloat("downfall", biome.downfall())
.putByte("has_precipitation", (byte) (biome.precipitation() == Precipitation.NONE ? 0 : 1))
.putString("precipitation", biome.precipitation().name().toLowerCase(Locale.ROOT));
.putBoolean("has_precipitation", biome.hasPrecipitation());
if (biome.temperatureModifier() != TemperatureModifier.NONE)
builder.putString("temperature_modifier", biome.temperatureModifier().name().toLowerCase(Locale.ROOT));
return builder
@ -39,11 +38,7 @@ record BiomeImpl(
BiomeImpl(Registry.BiomeEntry entry) {
this(entry.temperature(), entry.downfall(), getBuilder(entry).build(),
entry.hasPrecipitation()
? entry.temperature() < SNOW_TEMPERATURE
? Precipitation.SNOW
: Precipitation.RAIN
: Precipitation.NONE,
entry.hasPrecipitation(),
entry.temperature() < SNOW_TEMPERATURE ? TemperatureModifier.FROZEN : TemperatureModifier.NONE,
entry
);