Prevent important biome fields from being null

This commit is contained in:
themode 2020-11-14 01:06:04 +01:00
parent 2ea2efb5a2
commit 669e7ea711

View File

@ -5,6 +5,8 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.concurrent.atomic.AtomicInteger;
@ -17,6 +19,13 @@ public class Biome {
public static final AtomicInteger idCounter = new AtomicInteger(0);
private static final BiomeEffects DEFAULT_EFFECTS = BiomeEffects.builder()
.fog_color(0xC0D8FF)
.sky_color(0x78A7FF)
.water_color(0x3F76E4)
.water_fog_color(0x50533)
.build();
//A plains biome has to be registered or else minecraft will crash
public static final Biome PLAINS = Biome.builder()
.category(Category.NONE)
@ -25,12 +34,7 @@ public class Biome {
.downfall(0.4F)
.depth(0.125F)
.scale(0.05F)
.effects(BiomeEffects.builder()
.fog_color(0xC0D8FF)
.sky_color(0x78A7FF)
.water_color(0x3F76E4)
.water_fog_color(0x50533)
.build())
.effects(DEFAULT_EFFECTS)
.build();
private final int id = idCounter.getAndIncrement();
@ -46,13 +50,18 @@ public class Biome {
private final float downfall = 0.8F;
@Builder.Default
private final Category category = Category.NONE;
private final BiomeEffects effects;
@Builder.Default
private final BiomeEffects effects = DEFAULT_EFFECTS;
@Builder.Default
private final Precipitation precipitation = Precipitation.RAIN;
@Builder.Default
private final TemperatureModifier temperature_modifier = TemperatureModifier.NONE;
@NotNull
public NBTCompound toNbt() {
Check.notNull(name, "The biome namespace cannot be null");
Check.notNull(effects, "The biome effects cannot be null");
NBTCompound nbt = new NBTCompound();
nbt.setString("name", name.toString());
nbt.setInt("id", getId());