Cleanup BiomeParticle

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-12 19:02:43 +01:00
parent 72448d6481
commit b3f1bfdf59
2 changed files with 14 additions and 62 deletions

View File

@ -8,7 +8,7 @@ import java.util.Locale;
public record BiomeEffects(int fogColor, int skyColor, int waterColor, int waterFogColor, int foliageColor,
int grassColor,
GrassColorModifier grassColorModifier, BiomeParticles biomeParticles,
GrassColorModifier grassColorModifier, BiomeParticle biomeParticle,
NamespaceID ambientSound, MoodSound moodSound, AdditionsSound additionsSound,
Music music) {
@ -26,8 +26,8 @@ public record BiomeEffects(int fogColor, int skyColor, int waterColor, int water
nbt.setInt("water_fog_color", waterFogColor);
if (grassColorModifier != null)
nbt.setString("grass_color_modifier", grassColorModifier.name().toLowerCase(Locale.ROOT));
if (biomeParticles != null)
nbt.set("particle", biomeParticles.toNbt());
if (biomeParticle != null)
nbt.set("particle", biomeParticle.toNbt());
if (ambientSound != null)
nbt.setString("ambient_sound", ambientSound.toString());
if (moodSound != null)
@ -82,7 +82,7 @@ public record BiomeEffects(int fogColor, int skyColor, int waterColor, int water
private int foliageColor = -1;
private int grassColor = -1;
private GrassColorModifier grassColorModifier;
private BiomeParticles biomeParticles;
private BiomeParticle biomeParticle;
private NamespaceID ambientSound;
private MoodSound moodSound;
private AdditionsSound additionsSound;
@ -126,8 +126,8 @@ public record BiomeEffects(int fogColor, int skyColor, int waterColor, int water
return this;
}
public Builder biomeParticles(BiomeParticles biomeParticles) {
this.biomeParticles = biomeParticles;
public Builder biomeParticle(BiomeParticle biomeParticle) {
this.biomeParticle = biomeParticle;
return this;
}
@ -153,7 +153,7 @@ public record BiomeEffects(int fogColor, int skyColor, int waterColor, int water
public BiomeEffects build() {
return new BiomeEffects(fogColor, skyColor, waterColor, waterFogColor, foliageColor,
grassColor, grassColorModifier, biomeParticles,
grassColor, grassColorModifier, biomeParticle,
ambientSound, moodSound, additionsSound, music);
}
}

View File

@ -3,43 +3,26 @@ package net.minestom.server.world.biomes;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Map;
public class BiomeParticles {
private final float probability;
private final ParticleOptions options;
public BiomeParticles(float probability, ParticleOptions options) {
this.probability = probability;
this.options = options;
}
public record BiomeParticle(float probability, Option option) {
public NBTCompound toNbt() {
NBTCompound nbt = new NBTCompound();
nbt.setFloat("probability", probability);
nbt.set("options", options.toNbt());
nbt.set("options", option.toNbt());
return nbt;
}
public interface ParticleOptions {
public interface Option {
NBTCompound toNbt();
}
public static class BlockParticle implements ParticleOptions {
public record BlockOption(Block block) implements Option {
//TODO also can be falling_dust
private static final String type = "block";
private final Block block;
public BlockParticle(Block block) {
this.block = block;
}
@Override
public NBTCompound toNbt() {
NBTCompound nbtCompound = new NBTCompound();
@ -53,25 +36,11 @@ public class BiomeParticles {
}
return nbtCompound;
}
}
public static class DustParticle implements ParticleOptions {
public record DustOption(float red, float green, float blue, float scale) implements Option {
private static final String type = "dust";
private final float red;
private final float green;
private final float blue;
private final float scale;
public DustParticle(float red, float green, float blue, float scale) {
this.red = red;
this.green = green;
this.blue = blue;
this.scale = scale;
}
@Override
public NBTCompound toNbt() {
NBTCompound nbtCompound = new NBTCompound();
@ -82,19 +51,11 @@ public class BiomeParticles {
nbtCompound.setFloat("scale", scale);
return nbtCompound;
}
}
public static class ItemParticle implements ParticleOptions {
public record ItemOption(ItemStack item) implements Option {
private static final String type = "item";
private final ItemStack item;
public ItemParticle(ItemStack item) {
this.item = item;
}
@Override
public NBTCompound toNbt() {
//todo test count might be wrong type
@ -102,23 +63,14 @@ public class BiomeParticles {
nbtCompound.setString("type", type);
return nbtCompound;
}
}
public static class NormalParticle implements ParticleOptions {
private final NamespaceID type;
public NormalParticle(@NotNull NamespaceID type) {
this.type = type;
}
public record NormalOption(NamespaceID type) implements Option {
@Override
public NBTCompound toNbt() {
NBTCompound nbtCompound = new NBTCompound();
nbtCompound.setString("type", type.toString());
return nbtCompound;
}
}
}