mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-10 09:21:28 +01:00
Add multiple colors for FireworkEffect
This commit is contained in:
parent
9977df556e
commit
96155e826e
@ -2,44 +2,32 @@ package net.minestom.server.item.firework;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.color.Color;
|
||||
import net.minestom.server.exception.ExceptionManager;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import org.jglrxavpok.hephaistos.nbt.*;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class FireworkEffect {
|
||||
|
||||
private final boolean flicker;
|
||||
private final boolean trail;
|
||||
private final FireworkEffectType type;
|
||||
private final Color color;
|
||||
private final Color fadeColor;
|
||||
private final List<Color> color;
|
||||
private final List<Color> fadeColor;
|
||||
|
||||
//FIXME: fix javadoc
|
||||
/**
|
||||
* Initializes a new firework effect.
|
||||
*
|
||||
* @param flicker {@code true} if this explosion has the Twinkle effect (glowstone dust), otherwise {@code false}.
|
||||
* @param trail {@code true} if this explosion hsa the Trail effect (diamond), otherwise {@code false}.
|
||||
* @param type The shape of this firework's explosion.
|
||||
* @param color The primary color of this firework effect.
|
||||
* @param fadeColor The secondary color of this firework effect.
|
||||
* @deprecated Use {@link #FireworkEffect(boolean, boolean, FireworkEffectType, Color, Color)}
|
||||
* @param color The primary colors of this firework effect.
|
||||
* @param fadeColor The secondary colors of this firework effect.
|
||||
*/
|
||||
@Deprecated
|
||||
public FireworkEffect(boolean flicker, boolean trail, FireworkEffectType type, ChatColor color, ChatColor fadeColor) {
|
||||
this(flicker, trail, type, color.asColor(), fadeColor.asColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new firework effect.
|
||||
*
|
||||
* @param flicker {@code true} if this explosion has the Twinkle effect (glowstone dust), otherwise {@code false}.
|
||||
* @param trail {@code true} if this explosion hsa the Trail effect (diamond), otherwise {@code false}.
|
||||
* @param type The shape of this firework's explosion.
|
||||
* @param color The primary color of this firework effect.
|
||||
* @param fadeColor The secondary color of this firework effect.
|
||||
*/
|
||||
public FireworkEffect(boolean flicker, boolean trail, FireworkEffectType type, Color color, Color fadeColor) {
|
||||
public FireworkEffect(boolean flicker, boolean trail, FireworkEffectType type, List<Color> color, List<Color> fadeColor) {
|
||||
this.flicker = flicker;
|
||||
this.trail = trail;
|
||||
this.type = type;
|
||||
@ -55,18 +43,21 @@ public class FireworkEffect {
|
||||
*/
|
||||
public static FireworkEffect fromCompound(@NotNull NBTCompound compound) {
|
||||
|
||||
Color primaryColor = null;
|
||||
Color secondaryColor = null;
|
||||
List<Color> primaryColor = new ArrayList<>();
|
||||
List<Color> secondaryColor = new ArrayList<>();
|
||||
|
||||
if (compound.containsKey("Colors")) {
|
||||
int[] color = compound.getIntArray("Colors");
|
||||
primaryColor = new Color(color[0], color[1], color[2]);
|
||||
for (int i = 0; i < color.length; i++) {
|
||||
primaryColor.add(new Color(color[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (compound.containsKey("FadeColors")) {
|
||||
int[] fadeColor = compound.getIntArray("FadeColors");
|
||||
secondaryColor = new Color(fadeColor[0], fadeColor[1], fadeColor[2]);
|
||||
|
||||
for (int i = 0; i < fadeColor.length; i++) {
|
||||
secondaryColor.add(new Color(fadeColor[i]));
|
||||
}
|
||||
}
|
||||
|
||||
boolean flicker = compound.containsKey("Flicker") && compound.getByte("Flicker") == 1;
|
||||
@ -118,11 +109,11 @@ public class FireworkEffect {
|
||||
* @return An array of integer values corresponding to the primary colors of this firework's explosion.
|
||||
*/
|
||||
public int[] getColors() {
|
||||
return new int[]{
|
||||
this.color.getRed(),
|
||||
this.color.getGreen(),
|
||||
this.color.getBlue()
|
||||
};
|
||||
int[] primary = new int[color.size()];
|
||||
for (int i = 0; i < color.size(); i++) {
|
||||
primary[i] = color.get(i).asRGB();
|
||||
}
|
||||
return primary;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,11 +124,11 @@ public class FireworkEffect {
|
||||
* @return An array of integer values corresponding to the fading colors of this firework's explosion.
|
||||
*/
|
||||
public int[] getFadeColors() {
|
||||
return new int[]{
|
||||
this.fadeColor.getRed(),
|
||||
this.fadeColor.getGreen(),
|
||||
this.fadeColor.getBlue()
|
||||
};
|
||||
int[] secondary = new int[fadeColor.size()];
|
||||
for (int i = 0; i < fadeColor.size(); i++) {
|
||||
secondary[i] = fadeColor.get(i).asRGB();
|
||||
}
|
||||
return secondary;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user