mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 13:30:10 +00:00
feat: add additional data support for particles on Minestom platform
This commit is contained in:
1 file changed
+31
-5
+31
-5
@@ -3,11 +3,15 @@ package com.dfsek.terra.minestom.config;
|
|||||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||||
|
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||||
|
import net.minestom.server.adventure.MinestomAdventure;
|
||||||
|
import net.minestom.server.codec.Transcoder;
|
||||||
import net.minestom.server.particle.Particle;
|
import net.minestom.server.particle.Particle;
|
||||||
import net.minestom.server.world.attribute.AmbientParticle;
|
import net.minestom.server.world.attribute.AmbientParticle;
|
||||||
import net.minestom.server.world.biome.BiomeEffects;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticle> {
|
public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientParticle> {
|
||||||
@Value("particle")
|
@Value("particle")
|
||||||
@@ -25,11 +29,13 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientPartic
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] parts = particle.split("\\{");
|
String[] parts = particle.split("\\{");
|
||||||
Particle parsedParticle = Particle.fromKey(parts[0]);
|
String key = parts[0];
|
||||||
|
Particle parsedParticle = Particle.fromKey(key);
|
||||||
if(parts.length > 1) {
|
if(parts.length > 1) {
|
||||||
LoggerFactory.getLogger(BiomeParticleConfigTemplate.class).warn("Particle {} has additional data, particle will be ignored.",
|
int start = particle.indexOf("{");
|
||||||
particle);
|
String dataString = particle.substring(start);
|
||||||
return null;
|
parsedParticle = parseAdditionalParticleData(dataString, key);
|
||||||
|
if (parsedParticle == null) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AmbientParticle(
|
return new AmbientParticle(
|
||||||
@@ -37,4 +43,24 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<AmbientPartic
|
|||||||
probability
|
probability
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Particle parseAdditionalParticleData(String dataString, String key) {
|
||||||
|
CompoundBinaryTag nbt = null;
|
||||||
|
Particle parsedParticle;
|
||||||
|
try {
|
||||||
|
nbt = MinestomAdventure.NBT_CODEC.decode(dataString);
|
||||||
|
// transform minecraft:x{a:"b"} into {type:"minecraft:x", a:"b"} as described in Particle.CODEC
|
||||||
|
nbt = nbt.putString("type", key);
|
||||||
|
parsedParticle = Particle.CODEC.decode(Transcoder.NBT, nbt).orElseThrow();
|
||||||
|
} catch(Exception e) {
|
||||||
|
String nbtString = "null";
|
||||||
|
try {
|
||||||
|
nbtString = (nbt == null ? "null" : MinestomAdventure.NBT_CODEC.encode(nbt));
|
||||||
|
} catch(IOException _) { }
|
||||||
|
LoggerFactory.getLogger(BiomeParticleConfigTemplate.class).warn(
|
||||||
|
"Failed to decode particle from '" + particle + "', nbt: '" + nbtString + "'. This particle will be ignored.", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return parsedParticle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user