mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add byte conversion to allow int NBT values for Fireworks (#681)
Firework NBT data might be either an int or byte and bedrock only takes it as a byte. Co-authored-by: Arktisfox <65837019+Arktisfox@users.noreply.github.com>
This commit is contained in:
parent
14fcd77925
commit
1a92f6974c
3 changed files with 35 additions and 11 deletions
|
@ -37,6 +37,7 @@ import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.utils.FireworkColor;
|
import org.geysermc.connector.utils.FireworkColor;
|
||||||
|
import org.geysermc.connector.utils.MathUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -63,7 +64,7 @@ public class FireworkEntity extends Entity {
|
||||||
|
|
||||||
CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();
|
CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();
|
||||||
if (fireworks.get("Flight") != null) {
|
if (fireworks.get("Flight") != null) {
|
||||||
fireworksBuilder.byteTag("Flight", (Byte) fireworks.get("Flight").getValue());
|
fireworksBuilder.byteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<com.nukkitx.nbt.tag.CompoundTag> explosions = new ArrayList<>();
|
List<com.nukkitx.nbt.tag.CompoundTag> explosions = new ArrayList<>();
|
||||||
|
@ -73,7 +74,7 @@ public class FireworkEntity extends Entity {
|
||||||
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder();
|
CompoundTagBuilder effectBuilder = CompoundTagBuilder.builder();
|
||||||
|
|
||||||
if (effectData.get("Type") != null) {
|
if (effectData.get("Type") != null) {
|
||||||
effectBuilder.byteTag("FireworkType", (Byte) effectData.get("Type").getValue());
|
effectBuilder.byteTag("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Colors") != null) {
|
if (effectData.get("Colors") != null) {
|
||||||
|
@ -101,11 +102,11 @@ public class FireworkEntity extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Trail") != null) {
|
if (effectData.get("Trail") != null) {
|
||||||
effectBuilder.byteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue());
|
effectBuilder.byteTag("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Flicker") != null) {
|
if (effectData.get("Flicker") != null) {
|
||||||
effectBuilder.byteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue());
|
effectBuilder.byteTag("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
explosions.add(effectBuilder.buildRootTag());
|
explosions.add(effectBuilder.buildRootTag());
|
||||||
|
|
|
@ -27,9 +27,10 @@ package org.geysermc.connector.network.translators.item.translators.nbt;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import org.geysermc.connector.network.translators.ItemRemapper;
|
import org.geysermc.connector.network.translators.ItemRemapper;
|
||||||
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
|
import org.geysermc.connector.network.translators.item.NbtItemStackTranslator;
|
||||||
import org.geysermc.connector.utils.FireworkColor;
|
import org.geysermc.connector.utils.FireworkColor;
|
||||||
|
import org.geysermc.connector.utils.MathUtils;
|
||||||
|
|
||||||
@ItemRemapper
|
@ItemRemapper
|
||||||
public class FireworkTranslator extends NbtItemStackTranslator {
|
public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
|
@ -41,6 +42,10 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundTag fireworks = itemTag.get("Fireworks");
|
CompoundTag fireworks = itemTag.get("Fireworks");
|
||||||
|
if (fireworks.get("Flight") != null) {
|
||||||
|
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
|
||||||
|
}
|
||||||
|
|
||||||
ListTag explosions = fireworks.get("Explosions");
|
ListTag explosions = fireworks.get("Explosions");
|
||||||
if (explosions == null) {
|
if (explosions == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -51,7 +56,7 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
CompoundTag newEffectData = new CompoundTag("");
|
CompoundTag newEffectData = new CompoundTag("");
|
||||||
|
|
||||||
if (effectData.get("Type") != null) {
|
if (effectData.get("Type") != null) {
|
||||||
newEffectData.put(new ByteTag("FireworkType", (Byte) effectData.get("Type").getValue()));
|
newEffectData.put(new ByteTag("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Colors") != null) {
|
if (effectData.get("Colors") != null) {
|
||||||
|
@ -79,11 +84,11 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Trail") != null) {
|
if (effectData.get("Trail") != null) {
|
||||||
newEffectData.put(new ByteTag("FireworkTrail", (Byte) effectData.get("Trail").getValue()));
|
newEffectData.put(new ByteTag("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("Flicker") != null) {
|
if (effectData.get("Flicker") != null) {
|
||||||
newEffectData.put(new ByteTag("FireworkFlicker", (Byte) effectData.get("Flicker").getValue()));
|
newEffectData.put(new ByteTag("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
explosions.remove(effect);
|
explosions.remove(effect);
|
||||||
|
@ -94,6 +99,9 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
CompoundTag fireworks = itemTag.get("Fireworks");
|
CompoundTag fireworks = itemTag.get("Fireworks");
|
||||||
|
if (fireworks.get("Flight") != null) {
|
||||||
|
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
|
||||||
|
}
|
||||||
|
|
||||||
ListTag explosions = fireworks.get("Explosions");
|
ListTag explosions = fireworks.get("Explosions");
|
||||||
for (Tag effect : explosions.getValue()) {
|
for (Tag effect : explosions.getValue()) {
|
||||||
|
@ -102,7 +110,7 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
CompoundTag newEffectData = new CompoundTag("");
|
CompoundTag newEffectData = new CompoundTag("");
|
||||||
|
|
||||||
if (effectData.get("FireworkType") != null) {
|
if (effectData.get("FireworkType") != null) {
|
||||||
newEffectData.put(new ByteTag("Type", (Byte) effectData.get("FireworkType").getValue()));
|
newEffectData.put(new ByteTag("Type", MathUtils.convertByte(effectData.get("FireworkType").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("FireworkColor") != null) {
|
if (effectData.get("FireworkColor") != null) {
|
||||||
|
@ -130,11 +138,11 @@ public class FireworkTranslator extends NbtItemStackTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("FireworkTrail") != null) {
|
if (effectData.get("FireworkTrail") != null) {
|
||||||
newEffectData.put(new ByteTag("Trail", (Byte) effectData.get("FireworkTrail").getValue()));
|
newEffectData.put(new ByteTag("Trail", MathUtils.convertByte(effectData.get("FireworkTrail").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (effectData.get("FireworkFlicker") != null) {
|
if (effectData.get("FireworkFlicker") != null) {
|
||||||
newEffectData.put(new ByteTag("Flicker", (Byte) effectData.get("FireworkFlicker").getValue()));
|
newEffectData.put(new ByteTag("Flicker", MathUtils.convertByte(effectData.get("FireworkFlicker").getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
explosions.remove(effect);
|
explosions.remove(effect);
|
||||||
|
|
|
@ -37,4 +37,19 @@ public class MathUtils {
|
||||||
int truncated = (int) floatNumber;
|
int truncated = (int) floatNumber;
|
||||||
return floatNumber > truncated ? truncated + 1 : truncated;
|
return floatNumber > truncated ? truncated + 1 : truncated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given object from an int or byte to byte.
|
||||||
|
* This is used for NBT data that might be either an int
|
||||||
|
* or byte and bedrock only takes it as an byte
|
||||||
|
*
|
||||||
|
* @param value The value to convert
|
||||||
|
* @return The converted byte
|
||||||
|
*/
|
||||||
|
public static Byte convertByte(Object value) {
|
||||||
|
if (value instanceof Integer) {
|
||||||
|
return ((Integer) value).byteValue();
|
||||||
|
}
|
||||||
|
return (Byte) value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue