mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-15 20:51:34 +01:00
Prevent important biome fields from being null
This commit is contained in:
parent
2ea2efb5a2
commit
669e7ea711
@ -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;
|
||||
@ -15,95 +17,102 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
@EqualsAndHashCode
|
||||
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
|
||||
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(BiomeEffects.builder()
|
||||
.fog_color(0xC0D8FF)
|
||||
.sky_color(0x78A7FF)
|
||||
.water_color(0x3F76E4)
|
||||
.water_fog_color(0x50533)
|
||||
.build())
|
||||
.build();
|
||||
private static final BiomeEffects DEFAULT_EFFECTS = BiomeEffects.builder()
|
||||
.fog_color(0xC0D8FF)
|
||||
.sky_color(0x78A7FF)
|
||||
.water_color(0x3F76E4)
|
||||
.water_fog_color(0x50533)
|
||||
.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;
|
||||
@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;
|
||||
private final int id = idCounter.getAndIncrement();
|
||||
|
||||
public NBTCompound toNbt() {
|
||||
NBTCompound nbt = new NBTCompound();
|
||||
nbt.setString("name", name.toString());
|
||||
nbt.setInt("id", getId());
|
||||
private final NamespaceID name;
|
||||
@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;
|
||||
@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();
|
||||
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;
|
||||
}
|
||||
@NotNull
|
||||
public NBTCompound toNbt() {
|
||||
Check.notNull(name, "The biome namespace cannot be null");
|
||||
Check.notNull(effects, "The biome effects cannot be null");
|
||||
|
||||
public enum Precipitation {
|
||||
RAIN("rain"), NONE("none"), SNOW("snow");
|
||||
NBTCompound nbt = new NBTCompound();
|
||||
nbt.setString("name", name.toString());
|
||||
nbt.setInt("id", getId());
|
||||
|
||||
@Getter
|
||||
String type;
|
||||
NBTCompound element = new NBTCompound();
|
||||
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) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
public enum Precipitation {
|
||||
RAIN("rain"), NONE("none"), SNOW("snow");
|
||||
|
||||
public enum Category {
|
||||
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");
|
||||
@Getter
|
||||
String type;
|
||||
|
||||
@Getter
|
||||
String type;
|
||||
Precipitation(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
Category(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
public enum Category {
|
||||
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 {
|
||||
NONE("none"), FROZEN("frozen");
|
||||
@Getter
|
||||
String type;
|
||||
|
||||
@Getter
|
||||
String type;
|
||||
Category(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
TemperatureModifier(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
public enum TemperatureModifier {
|
||||
NONE("none"), FROZEN("frozen");
|
||||
|
||||
@Getter
|
||||
String type;
|
||||
|
||||
TemperatureModifier(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user