From ca1f87d4642e9a6b9ca555aa9264ee319d352793 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Sat, 31 Oct 2020 22:38:56 -0400 Subject: [PATCH] MapItemTranslator: support map tag being of short value (#1475) GSigns sends this as a short. Who knows why. --- .../translators/nbt/MapItemTranslator.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java index c9b49efd..d325af48 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/MapItemTranslator.java @@ -25,10 +25,7 @@ package org.geysermc.connector.network.translators.item.translators.nbt; -import com.github.steveice10.opennbt.tag.builtin.ByteTag; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.LongTag; +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.ItemEntry; @@ -39,14 +36,22 @@ public class MapItemTranslator extends NbtItemStackTranslator { @Override public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) { - IntTag mapId = itemTag.get("map"); + // Can be either an IntTag or ShortTag + Tag mapId = itemTag.get("map"); + if (mapId == null) return; - if (mapId != null) { - itemTag.put(new LongTag("map_uuid", mapId.getValue())); - itemTag.put(new IntTag("map_name_index", mapId.getValue())); - itemTag.put(new ByteTag("map_display_players", (byte) 1)); - itemTag.remove("map"); + int mapValue; + if (mapId.getValue() instanceof Short) { + // Convert to int if necessary + mapValue = (int) (short) mapId.getValue(); + } else { + mapValue = (int) mapId.getValue(); } + + itemTag.put(new LongTag("map_uuid", mapValue)); + itemTag.put(new IntTag("map_name_index", mapValue)); + itemTag.put(new ByteTag("map_display_players", (byte) 1)); + itemTag.remove("map"); } @Override