mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 03:11:25 +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.chat.ChatColor;
|
||||||
import net.minestom.server.color.Color;
|
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.jetbrains.annotations.NotNull;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.*;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
|
|
||||||
public class FireworkEffect {
|
public class FireworkEffect {
|
||||||
|
|
||||||
private final boolean flicker;
|
private final boolean flicker;
|
||||||
private final boolean trail;
|
private final boolean trail;
|
||||||
private final FireworkEffectType type;
|
private final FireworkEffectType type;
|
||||||
private final Color color;
|
private final List<Color> color;
|
||||||
private final Color fadeColor;
|
private final List<Color> fadeColor;
|
||||||
|
|
||||||
|
//FIXME: fix javadoc
|
||||||
/**
|
/**
|
||||||
* Initializes a new firework effect.
|
* Initializes a new firework effect.
|
||||||
*
|
*
|
||||||
* @param flicker {@code true} if this explosion has the Twinkle effect (glowstone dust), otherwise {@code false}.
|
* @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 trail {@code true} if this explosion hsa the Trail effect (diamond), otherwise {@code false}.
|
||||||
* @param type The shape of this firework's explosion.
|
* @param type The shape of this firework's explosion.
|
||||||
* @param color The primary color of this firework effect.
|
* @param color The primary colors of this firework effect.
|
||||||
* @param fadeColor The secondary color of this firework effect.
|
* @param fadeColor The secondary colors of this firework effect.
|
||||||
* @deprecated Use {@link #FireworkEffect(boolean, boolean, FireworkEffectType, Color, Color)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public FireworkEffect(boolean flicker, boolean trail, FireworkEffectType type, List<Color> color, List<Color> fadeColor) {
|
||||||
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) {
|
|
||||||
this.flicker = flicker;
|
this.flicker = flicker;
|
||||||
this.trail = trail;
|
this.trail = trail;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -55,18 +43,21 @@ public class FireworkEffect {
|
|||||||
*/
|
*/
|
||||||
public static FireworkEffect fromCompound(@NotNull NBTCompound compound) {
|
public static FireworkEffect fromCompound(@NotNull NBTCompound compound) {
|
||||||
|
|
||||||
Color primaryColor = null;
|
List<Color> primaryColor = new ArrayList<>();
|
||||||
Color secondaryColor = null;
|
List<Color> secondaryColor = new ArrayList<>();
|
||||||
|
|
||||||
if (compound.containsKey("Colors")) {
|
if (compound.containsKey("Colors")) {
|
||||||
int[] color = compound.getIntArray("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")) {
|
if (compound.containsKey("FadeColors")) {
|
||||||
int[] fadeColor = compound.getIntArray("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;
|
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.
|
* @return An array of integer values corresponding to the primary colors of this firework's explosion.
|
||||||
*/
|
*/
|
||||||
public int[] getColors() {
|
public int[] getColors() {
|
||||||
return new int[]{
|
int[] primary = new int[color.size()];
|
||||||
this.color.getRed(),
|
for (int i = 0; i < color.size(); i++) {
|
||||||
this.color.getGreen(),
|
primary[i] = color.get(i).asRGB();
|
||||||
this.color.getBlue()
|
}
|
||||||
};
|
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.
|
* @return An array of integer values corresponding to the fading colors of this firework's explosion.
|
||||||
*/
|
*/
|
||||||
public int[] getFadeColors() {
|
public int[] getFadeColors() {
|
||||||
return new int[]{
|
int[] secondary = new int[fadeColor.size()];
|
||||||
this.fadeColor.getRed(),
|
for (int i = 0; i < fadeColor.size(); i++) {
|
||||||
this.fadeColor.getGreen(),
|
secondary[i] = fadeColor.get(i).asRGB();
|
||||||
this.fadeColor.getBlue()
|
}
|
||||||
};
|
return secondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user