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.Getter;
import lombok.ToString; import lombok.ToString;
import net.minestom.server.utils.NamespaceID; 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 org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -15,95 +17,102 @@ import java.util.concurrent.atomic.AtomicInteger;
@EqualsAndHashCode @EqualsAndHashCode
public class Biome { public class Biome {
public static final AtomicInteger idCounter = new AtomicInteger(0); public static final AtomicInteger idCounter = new AtomicInteger(0);
//A plains biome has to be registered or else minecraft will crash private static final BiomeEffects DEFAULT_EFFECTS = BiomeEffects.builder()
public static final Biome PLAINS = Biome.builder() .fog_color(0xC0D8FF)
.category(Category.NONE) .sky_color(0x78A7FF)
.name(NamespaceID.from("minecraft:plains")) .water_color(0x3F76E4)
.temperature(0.8F) .water_fog_color(0x50533)
.downfall(0.4F) .build();
.depth(0.125F)
.scale(0.05F)
.effects(BiomeEffects.builder()
.fog_color(0xC0D8FF)
.sky_color(0x78A7FF)
.water_color(0x3F76E4)
.water_fog_color(0x50533)
.build())
.build();
private final int id = idCounter.getAndIncrement(); //A plains biome has to be registered or else minecraft will crash
public static final Biome PLAINS = Biome.builder()
.category(Category.NONE)
.name(NamespaceID.from("minecraft:plains"))
.temperature(0.8F)
.downfall(0.4F)
.depth(0.125F)
.scale(0.05F)
.effects(DEFAULT_EFFECTS)
.build();
private final NamespaceID name; private final int id = idCounter.getAndIncrement();
@Builder.Default
private final float depth = 0.2F;
@Builder.Default
private final float temperature = 0.25F;
@Builder.Default
private final float scale = 0.2F;
@Builder.Default
private final float downfall = 0.8F;
@Builder.Default
private final Category category = Category.NONE;
private final BiomeEffects effects;
@Builder.Default
private final Precipitation precipitation = Precipitation.RAIN;
@Builder.Default
private final TemperatureModifier temperature_modifier = TemperatureModifier.NONE;
public NBTCompound toNbt() { private final NamespaceID name;
NBTCompound nbt = new NBTCompound(); @Builder.Default
nbt.setString("name", name.toString()); private final float depth = 0.2F;
nbt.setInt("id", getId()); @Builder.Default
private final float temperature = 0.25F;
@Builder.Default
private final float scale = 0.2F;
@Builder.Default
private final float downfall = 0.8F;
@Builder.Default
private final Category category = Category.NONE;
@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;
NBTCompound element = new NBTCompound(); @NotNull
element.setFloat("depth", depth); public NBTCompound toNbt() {
element.setFloat("temperature", temperature); Check.notNull(name, "The biome namespace cannot be null");
element.setFloat("scale", scale); Check.notNull(effects, "The biome effects cannot be null");
element.setFloat("downfall", downfall);
element.setString("category", category.getType());
element.setString("precipitation", precipitation.getType());
if (temperature_modifier != TemperatureModifier.NONE)
element.setString("temperature_modifier", temperature_modifier.getType());
element.set("effects", effects.toNbt());
nbt.set("element", element);
return nbt;
}
public enum Precipitation { NBTCompound nbt = new NBTCompound();
RAIN("rain"), NONE("none"), SNOW("snow"); nbt.setString("name", name.toString());
nbt.setInt("id", getId());
@Getter NBTCompound element = new NBTCompound();
String type; element.setFloat("depth", depth);
element.setFloat("temperature", temperature);
element.setFloat("scale", scale);
element.setFloat("downfall", downfall);
element.setString("category", category.getType());
element.setString("precipitation", precipitation.getType());
if (temperature_modifier != TemperatureModifier.NONE)
element.setString("temperature_modifier", temperature_modifier.getType());
element.set("effects", effects.toNbt());
nbt.set("element", element);
return nbt;
}
Precipitation(String type) { public enum Precipitation {
this.type = type; RAIN("rain"), NONE("none"), SNOW("snow");
}
}
public enum Category { @Getter
NONE("none"), TAIGA("taiga"), EXTREME_HILLS("extreme_hills"), JUNGLE("jungle"), MESA("mesa"), PLAINS("plains"), String type;
SAVANNA("savanna"), ICY("icy"), THE_END("the_end"), BEACH("beach"), FOREST("forest"), OCEAN("ocean"),
DESERT("desert"), RIVER("river"), SWAMP("swamp"), MUSHROOM("mushroom"), NETHER("nether");
@Getter Precipitation(String type) {
String type; this.type = type;
}
}
Category(String type) { public enum Category {
this.type = type; NONE("none"), TAIGA("taiga"), EXTREME_HILLS("extreme_hills"), JUNGLE("jungle"), MESA("mesa"), PLAINS("plains"),
} SAVANNA("savanna"), ICY("icy"), THE_END("the_end"), BEACH("beach"), FOREST("forest"), OCEAN("ocean"),
} DESERT("desert"), RIVER("river"), SWAMP("swamp"), MUSHROOM("mushroom"), NETHER("nether");
public enum TemperatureModifier { @Getter
NONE("none"), FROZEN("frozen"); String type;
@Getter Category(String type) {
String type; this.type = type;
}
}
TemperatureModifier(String type) { public enum TemperatureModifier {
this.type = type; NONE("none"), FROZEN("frozen");
}
} @Getter
String type;
TemperatureModifier(String type) {
this.type = type;
}
}
} }