From 5b1116b15a19f0b98568c95de03af4d59a40082a Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Fri, 24 Jul 2020 11:42:15 -0800 Subject: [PATCH] Creative items (#1013) --- .../network/session/GeyserSession.java | 4 +-- .../translators/item/ItemRegistry.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index d9aab359..b861f64c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -234,9 +234,7 @@ public class GeyserSession implements CommandSender { upstream.sendPacket(entityPacket); CreativeContentPacket creativePacket = new CreativeContentPacket(); - for (int i = 0; i < ItemRegistry.CREATIVE_ITEMS.length; i++) { - creativePacket.getEntries().put(i + 1, ItemRegistry.CREATIVE_ITEMS[i]); - } + creativePacket.setContents(ItemRegistry.CREATIVE_ITEMS); upstream.sendPacket(creativePacket); PlayStatusPacket playStatusPacket = new PlayStatusPacket(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java index 33f640f1..142f1451 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java @@ -163,23 +163,23 @@ public class ItemRegistry { throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.toolbox.fail.creative"), e); } + int netId = 1; List creativeItems = new ArrayList<>(); for (JsonNode itemNode : creativeItemEntries) { - short damage = 0; - if (itemNode.has("damage")) { - damage = itemNode.get("damage").numberValue().shortValue(); - } - if (itemNode.has("nbt_b64")) { - byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText()); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - try { - NbtMap tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag(); - creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1, tag)); - } catch (IOException e) { - e.printStackTrace(); + try { + short damage = 0; + NbtMap tag = null; + if (itemNode.has("damage")) { + damage = itemNode.get("damage").numberValue().shortValue(); } - } else { - creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1)); + if (itemNode.has("nbt_b64")) { + byte[] bytes = Base64.getDecoder().decode(itemNode.get("nbt_b64").asText()); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag(); + } + creativeItems.add(ItemData.fromNet(netId++, itemNode.get("id").asInt(), damage, 1, tag)); + } catch (IOException e) { + e.printStackTrace(); } } CREATIVE_ITEMS = creativeItems.toArray(new ItemData[0]);