mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add null check for fireworks tag (Closes #636)
This commit is contained in:
parent
d918139c44
commit
6dabc22d22
1 changed files with 47 additions and 43 deletions
|
@ -36,54 +36,58 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
|||
|
||||
@Override
|
||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (!itemTag.contains("Fireworks")) {
|
||||
return;
|
||||
}
|
||||
|
||||
CompoundTag fireworks = itemTag.get("Fireworks");
|
||||
|
||||
ListTag explosions = fireworks.get("Explosions");
|
||||
if (explosions != null) {
|
||||
for (Tag effect : explosions.getValue()) {
|
||||
CompoundTag effectData = (CompoundTag) effect;
|
||||
if (explosions == null) {
|
||||
return;
|
||||
}
|
||||
for (Tag effect : explosions.getValue()) {
|
||||
CompoundTag effectData = (CompoundTag) effect;
|
||||
|
||||
CompoundTag newEffectData = new CompoundTag("");
|
||||
CompoundTag newEffectData = new CompoundTag("");
|
||||
|
||||
if (effectData.get("Type") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Colors") != null) {
|
||||
int[] oldColors = (int[]) effectData.get("Colors").getValue();
|
||||
byte[] colors = new byte[oldColors.length];
|
||||
|
||||
int i = 0;
|
||||
for (int color : oldColors) {
|
||||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
newEffectData.put(new ByteArrayTag("FireworkColor", colors));
|
||||
}
|
||||
|
||||
if (effectData.get("FadeColors") != null) {
|
||||
int[] oldColors = (int[]) effectData.get("FadeColors").getValue();
|
||||
byte[] colors = new byte[oldColors.length];
|
||||
|
||||
int i = 0;
|
||||
for (int color : oldColors) {
|
||||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
newEffectData.put(new ByteArrayTag("FireworkFade", colors));
|
||||
}
|
||||
|
||||
if (effectData.get("Trail") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Flicker") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue()));
|
||||
}
|
||||
|
||||
explosions.remove(effect);
|
||||
explosions.add(newEffectData);
|
||||
if (effectData.get("Type") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Colors") != null) {
|
||||
int[] oldColors = (int[]) effectData.get("Colors").getValue();
|
||||
byte[] colors = new byte[oldColors.length];
|
||||
|
||||
int i = 0;
|
||||
for (int color : oldColors) {
|
||||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
newEffectData.put(new ByteArrayTag("FireworkColor", colors));
|
||||
}
|
||||
|
||||
if (effectData.get("FadeColors") != null) {
|
||||
int[] oldColors = (int[]) effectData.get("FadeColors").getValue();
|
||||
byte[] colors = new byte[oldColors.length];
|
||||
|
||||
int i = 0;
|
||||
for (int color : oldColors) {
|
||||
colors[i++] = FireworkColor.fromJavaID(color).getBedrockID();
|
||||
}
|
||||
|
||||
newEffectData.put(new ByteArrayTag("FireworkFade", colors));
|
||||
}
|
||||
|
||||
if (effectData.get("Trail") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Flicker") != null) {
|
||||
newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue()));
|
||||
}
|
||||
|
||||
explosions.remove(effect);
|
||||
explosions.add(newEffectData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue