Add support for color gradients and sizes in particle configurations
Enhanced `ParticleConfig` to handle color gradients and sizes for particles with `DustOptions` and `DustTransition`. Updated `ParticleInfo` to include `colorGradientEnd` and `size` properties. Refactored particle data handling for improved flexibility.
This commit is contained in:
parent
481cb007bf
commit
8aa22a3e7a
|
|
@ -37,6 +37,7 @@ public class ParticleConfig {
|
|||
|
||||
/**
|
||||
* Finds all files in particles directory that are valid .json files
|
||||
*
|
||||
* @return all files found
|
||||
*/
|
||||
private List<File> getJsonFiles() {
|
||||
|
|
@ -59,6 +60,7 @@ public class ParticleConfig {
|
|||
|
||||
/**
|
||||
* Converts a ParticleData object to a ParticleSet
|
||||
*
|
||||
* @param particleData The ParticleData object to convert
|
||||
* @return A ParticleSet created from the ParticleData
|
||||
*/
|
||||
|
|
@ -78,24 +80,33 @@ public class ParticleConfig {
|
|||
double z = particleInfo.getZ();
|
||||
|
||||
ParticleBuilder particleBuilder = new ParticleBuilder(particleType);
|
||||
Class<?> dataType = particleType.getDataType();
|
||||
|
||||
// Handle different particle data types
|
||||
if (particleType.getDataType().equals(Particle.DustOptions.class) && particleInfo.getColor() != null) {
|
||||
int rgb = HexFormat.fromHexDigits(particleInfo.getColor());
|
||||
particleBuilder.data(new Particle.DustOptions(Color.fromRGB(rgb), 1));
|
||||
}
|
||||
// else if (particleType.getDataType().equals(MaterialData.class)) {
|
||||
// //TODO implement
|
||||
// }
|
||||
else if (particleType.getDataType().equals(BlockData.class)) {
|
||||
if ((dataType.equals(Particle.DustOptions.class)
|
||||
|| dataType.equals(Particle.DustTransition.class))) {
|
||||
if (particleInfo.getColor() != null) {
|
||||
if (particleInfo.getColorGradientEnd() != null) {
|
||||
particleBuilder.colorTransition(getColor(particleInfo.getColor()),
|
||||
getColor(particleInfo.getColorGradientEnd()),
|
||||
particleInfo.getSize());
|
||||
} else {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()));
|
||||
}
|
||||
}
|
||||
} else if (dataType.equals(Color.class)) {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()));
|
||||
} else if (dataType.equals(BlockData.class)) {
|
||||
particleBuilder.data(Material.STONE.createBlockData());
|
||||
//TODO implement
|
||||
} else if (particleType.getDataType().equals(Integer.class)) {
|
||||
} else if (dataType.equals(Integer.class)) {
|
||||
particleBuilder.data(1);
|
||||
//TODO implement
|
||||
} else if (particleType.getDataType().equals(Float.class)) {
|
||||
} else if (dataType.equals(Float.class)) {
|
||||
particleBuilder.data(1f);
|
||||
//TODO implement
|
||||
} else if (particleType.getDataType().equals(Particle.DustTransition.class)) {
|
||||
//TODO implement
|
||||
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
||||
} else if (dataType.equals(ItemStack.class)) {
|
||||
particleBuilder.data(new ItemStack(Material.STONE));
|
||||
//TODO implement
|
||||
} else if (particleInfo.getExtra() != null) {
|
||||
particleBuilder.extra(particleInfo.getExtra());
|
||||
|
|
@ -110,21 +121,30 @@ public class ParticleConfig {
|
|||
// Create and return the ParticleSet
|
||||
ItemStack displayItem = new ItemStack(Material.valueOf(particleData.getDisplayItem()));
|
||||
return new ParticleSet(
|
||||
loadedFrames,
|
||||
particleData.getDisplayName(),
|
||||
List.of(particleData.getLore().split("\n")),
|
||||
particleData.getFrameDelay(),
|
||||
particleData.getRepeat(),
|
||||
particleData.getRepeatDelay(),
|
||||
particleData.isStationary(),
|
||||
particleData.getAPartType(),
|
||||
particleData.getParticleName(),
|
||||
particleData.getPermission(),
|
||||
particleData.getPackagePermission(),
|
||||
displayItem
|
||||
loadedFrames,
|
||||
particleData.getDisplayName(),
|
||||
List.of(particleData.getLore().split("\n")),
|
||||
particleData.getFrameDelay(),
|
||||
particleData.getRepeat(),
|
||||
particleData.getRepeatDelay(),
|
||||
particleData.isStationary(),
|
||||
particleData.getAPartType(),
|
||||
particleData.getParticleName(),
|
||||
particleData.getPermission(),
|
||||
particleData.getPackagePermission(),
|
||||
displayItem
|
||||
);
|
||||
}
|
||||
|
||||
private Color getColor(String hexColor) {
|
||||
int color = HexFormat.fromHexDigits(hexColor);
|
||||
if (hexColor.length() == 6) {
|
||||
return Color.fromARGB(color);
|
||||
} else {
|
||||
return Color.fromRGB(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
ParticleStorage.clear();
|
||||
ParticleConfig instance = getInstance();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ public class ParticleInfo {
|
|||
|
||||
// For DustOptions
|
||||
private String color;
|
||||
@JsonProperty("color_gradient_end")
|
||||
private String colorGradientEnd;
|
||||
// For DustOptions
|
||||
|
||||
@JsonProperty(value = "size", defaultValue = "1")
|
||||
private int size;
|
||||
|
||||
// For other particle types
|
||||
private Double extra;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user