forked from GeyserMC/Geyser
Creative items (#1013)
This commit is contained in:
parent
b103d86ff9
commit
5b1116b15a
2 changed files with 15 additions and 17 deletions
|
@ -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();
|
||||
|
|
|
@ -163,24 +163,24 @@ public class ItemRegistry {
|
|||
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.toolbox.fail.creative"), e);
|
||||
}
|
||||
|
||||
int netId = 1;
|
||||
List<ItemData> creativeItems = new ArrayList<>();
|
||||
for (JsonNode itemNode : creativeItemEntries) {
|
||||
try {
|
||||
short damage = 0;
|
||||
NbtMap tag = null;
|
||||
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));
|
||||
tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
|
||||
}
|
||||
creativeItems.add(ItemData.fromNet(netId++, itemNode.get("id").asInt(), damage, 1, tag));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
creativeItems.add(ItemData.of(itemNode.get("id").asInt(), damage, 1));
|
||||
}
|
||||
}
|
||||
CREATIVE_ITEMS = creativeItems.toArray(new ItemData[0]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue