mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add more sanity checks for shulker boxes
Also properly implements reading byte tags from Java Edition.
This commit is contained in:
parent
4b05b74a9a
commit
58e00b2645
5 changed files with 21 additions and 23 deletions
|
@ -81,7 +81,7 @@ public class FireworkEntity extends Entity {
|
|||
|
||||
NbtMapBuilder fireworksBuilder = NbtMap.builder();
|
||||
if (fireworks.get("Flight") != null) {
|
||||
fireworksBuilder.putByte("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue()));
|
||||
fireworksBuilder.putByte("Flight", MathUtils.getNbtByte(fireworks.get("Flight").getValue()));
|
||||
}
|
||||
|
||||
List<NbtMap> explosions = new ArrayList<>();
|
||||
|
@ -91,7 +91,7 @@ public class FireworkEntity extends Entity {
|
|||
NbtMapBuilder effectBuilder = NbtMap.builder();
|
||||
|
||||
if (effectData.get("Type") != null) {
|
||||
effectBuilder.putByte("FireworkType", MathUtils.convertByte(effectData.get("Type").getValue()));
|
||||
effectBuilder.putByte("FireworkType", MathUtils.getNbtByte(effectData.get("Type").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Colors") != null) {
|
||||
|
@ -119,11 +119,11 @@ public class FireworkEntity extends Entity {
|
|||
}
|
||||
|
||||
if (effectData.get("Trail") != null) {
|
||||
effectBuilder.putByte("FireworkTrail", MathUtils.convertByte(effectData.get("Trail").getValue()));
|
||||
effectBuilder.putByte("FireworkTrail", MathUtils.getNbtByte(effectData.get("Trail").getValue()));
|
||||
}
|
||||
|
||||
if (effectData.get("Flicker") != null) {
|
||||
effectBuilder.putByte("FireworkFlicker", MathUtils.convertByte(effectData.get("Flicker").getValue()));
|
||||
effectBuilder.putByte("FireworkFlicker", MathUtils.getNbtByte(effectData.get("Flicker").getValue()));
|
||||
}
|
||||
|
||||
explosions.add(effectBuilder.build());
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class FireworkBaseTranslator extends NbtItemStackTranslator {
|
|||
CompoundTag newExplosionData = new CompoundTag(newName);
|
||||
|
||||
if (explosion.get("Type") != null) {
|
||||
newExplosionData.put(new ByteTag("FireworkType", MathUtils.convertByte(explosion.get("Type").getValue())));
|
||||
newExplosionData.put(new ByteTag("FireworkType", MathUtils.getNbtByte(explosion.get("Type").getValue())));
|
||||
}
|
||||
|
||||
if (explosion.get("Colors") != null) {
|
||||
|
@ -70,11 +70,11 @@ public abstract class FireworkBaseTranslator extends NbtItemStackTranslator {
|
|||
}
|
||||
|
||||
if (explosion.get("Trail") != null) {
|
||||
newExplosionData.put(new ByteTag("FireworkTrail", MathUtils.convertByte(explosion.get("Trail").getValue())));
|
||||
newExplosionData.put(new ByteTag("FireworkTrail", MathUtils.getNbtByte(explosion.get("Trail").getValue())));
|
||||
}
|
||||
|
||||
if (explosion.get("Flicker") != null) {
|
||||
newExplosionData.put(new ByteTag("FireworkFlicker", MathUtils.convertByte(explosion.get("Flicker").getValue())));
|
||||
newExplosionData.put(new ByteTag("FireworkFlicker", MathUtils.getNbtByte(explosion.get("Flicker").getValue())));
|
||||
}
|
||||
|
||||
return newExplosionData;
|
||||
|
@ -84,7 +84,7 @@ public abstract class FireworkBaseTranslator extends NbtItemStackTranslator {
|
|||
CompoundTag newExplosionData = new CompoundTag(newName);
|
||||
|
||||
if (explosion.get("FireworkType") != null) {
|
||||
newExplosionData.put(new ByteTag("Type", MathUtils.convertByte(explosion.get("FireworkType").getValue())));
|
||||
newExplosionData.put(new ByteTag("Type", MathUtils.getNbtByte(explosion.get("FireworkType").getValue())));
|
||||
}
|
||||
|
||||
if (explosion.get("FireworkColor") != null) {
|
||||
|
@ -112,11 +112,11 @@ public abstract class FireworkBaseTranslator extends NbtItemStackTranslator {
|
|||
}
|
||||
|
||||
if (explosion.get("FireworkTrail") != null) {
|
||||
newExplosionData.put(new ByteTag("Trail", MathUtils.convertByte(explosion.get("FireworkTrail").getValue())));
|
||||
newExplosionData.put(new ByteTag("Trail", MathUtils.getNbtByte(explosion.get("FireworkTrail").getValue())));
|
||||
}
|
||||
|
||||
if (explosion.get("FireworkFlicker") != null) {
|
||||
newExplosionData.put(new ByteTag("Flicker", MathUtils.convertByte(explosion.get("FireworkFlicker").getValue())));
|
||||
newExplosionData.put(new ByteTag("Flicker", MathUtils.getNbtByte(explosion.get("FireworkFlicker").getValue())));
|
||||
}
|
||||
|
||||
return newExplosionData;
|
||||
|
|
|
@ -45,7 +45,7 @@ public class FireworkRocketTranslator extends FireworkBaseTranslator {
|
|||
}
|
||||
|
||||
if (fireworks.get("Flight") != null) {
|
||||
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
|
||||
fireworks.put(new ByteTag("Flight", MathUtils.getNbtByte(fireworks.get("Flight").getValue())));
|
||||
}
|
||||
|
||||
ListTag explosions = fireworks.get("Explosions");
|
||||
|
@ -69,7 +69,7 @@ public class FireworkRocketTranslator extends FireworkBaseTranslator {
|
|||
}
|
||||
|
||||
if (fireworks.contains("Flight")) {
|
||||
fireworks.put(new ByteTag("Flight", MathUtils.convertByte(fireworks.get("Flight").getValue())));
|
||||
fireworks.put(new ByteTag("Flight", MathUtils.getNbtByte(fireworks.get("Flight").getValue())));
|
||||
}
|
||||
|
||||
ListTag explosions = fireworks.get("Explosions");
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
|
||||
package org.geysermc.connector.network.translators.item.translators.nbt;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.ItemRemapper;
|
||||
import org.geysermc.connector.network.translators.item.*;
|
||||
import org.geysermc.connector.registry.type.ItemMapping;
|
||||
import org.geysermc.connector.utils.MathUtils;
|
||||
|
||||
@ItemRemapper
|
||||
public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
|
||||
|
@ -44,14 +46,14 @@ public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
|
|||
for (Tag item : (ListTag) blockEntityTag.get("Items")) {
|
||||
CompoundTag itemData = (CompoundTag) item; // Information about the item
|
||||
CompoundTag boxItemTag = new CompoundTag(""); // Final item tag to add to the list
|
||||
boxItemTag.put(new ByteTag("Slot", ((ByteTag) itemData.get("Slot")).getValue()));
|
||||
boxItemTag.put(new ByteTag("Slot", (byte) (MathUtils.getNbtByte(itemData.get("Slot").getValue()) & 255)));
|
||||
boxItemTag.put(new ByteTag("WasPickedUp", (byte) 0)); // ???
|
||||
|
||||
ItemMapping boxMapping = session.getItemMappings().getMapping(((StringTag) itemData.get("id")).getValue());
|
||||
ItemMapping boxMapping = session.getItemMappings().getMapping(Identifier.formalize(((StringTag) itemData.get("id")).getValue()));
|
||||
|
||||
boxItemTag.put(new StringTag("Name", boxMapping.getBedrockIdentifier()));
|
||||
boxItemTag.put(new ShortTag("Damage", (short) boxMapping.getBedrockData()));
|
||||
boxItemTag.put(new ByteTag("Count", ((ByteTag) itemData.get("Count")).getValue()));
|
||||
boxItemTag.put(new ByteTag("Count", MathUtils.getNbtByte(itemData.get("Count").getValue())));
|
||||
// Only the display name is what we have interest in, so just translate that if relevant
|
||||
CompoundTag displayTag = itemData.get("tag");
|
||||
if (displayTag == null && boxMapping.hasTranslation()) {
|
||||
|
|
|
@ -85,18 +85,14 @@ public class MathUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Ensures the resulting object is a byte. Java Edition does not care whether a byte is encoded as an integer or not;
|
||||
* it converts it into a byte anyway.
|
||||
*
|
||||
* @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;
|
||||
public static byte getNbtByte(Object value) {
|
||||
return ((Number) value).byteValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue