use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockPalette method init.
public static void init() {
InputStream resourceAsStream = Bootstrap.class.getClassLoader().getResourceAsStream("block_palette.nbt");
if (resourceAsStream != null) {
try (NBTInputStream nbtReader = new NBTInputStream(new DataInputStream(new GZIPInputStream(resourceAsStream)))) {
NbtMap nbtMap = (NbtMap) nbtReader.readTag();
for (NbtMap blockMap : nbtMap.getList("blocks", NbtType.COMPOUND)) {
int runtimeId = RUNTIME_COUNTER.getAndIncrement();
BLOCK_PALETTE.put(runtimeId, blockMap);
BLOCK_DATA.put(new BlockData(blockMap.getString("name"), blockMap.getCompound("states")), runtimeId);
DEFAULTS.putIfAbsent(blockMap.getString("name"), runtimeId);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class ItemCrossbow method getChargedItem.
public Item getChargedItem() {
if (this.nbt != null && this.nbt.containsKey("chargedItem", NbtType.COMPOUND)) {
NbtMap chargedItem = this.nbt.getCompound("chargedItem");
String name = chargedItem.getString("Name", "minecraft:arrow");
Item item = ItemType.get(name);
item.setAmount(chargedItem.getByte("Count", (byte) 1));
item.setMeta(chargedItem.getByte("Damage", (byte) 0));
item.setNBT(chargedItem);
return item;
}
return null;
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class CreativeItems method init.
public static void init() {
Gson GSON = new Gson();
try (InputStream inputStream = Objects.requireNonNull(Bootstrap.class.getClassLoader().getResourceAsStream("creative_items.json"))) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
Map<String, List<Map<String, Object>>> itemEntries = GSON.fromJson(inputStreamReader, Map.class);
int netIdCounter = 0;
for (Map<String, Object> itemEntry : itemEntries.get("items")) {
Item item;
String identifier = (String) itemEntry.get("id");
if (itemEntry.containsKey("blockRuntimeId")) {
item = get(identifier, (int) (double) itemEntry.get("blockRuntimeId"));
} else {
item = get(identifier);
}
if (itemEntry.containsKey("damage")) {
item.setMeta((short) (double) itemEntry.get("damage"));
}
String nbtTag = (String) itemEntry.get("nbt_b64");
if (nbtTag != null)
try (NBTInputStream nbtReader = NbtUtils.createReaderLE(new ByteArrayInputStream(Base64.getDecoder().decode(nbtTag.getBytes())))) {
item.setNBT((NbtMap) nbtReader.readTag());
}
CREATIVE_ITEMS.add(item.toNetwork(netIdCounter++));
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class LevelDB method loadBlockEntities.
public static void loadBlockEntities(Chunk chunk, byte[] blockEntityData) {
ByteBuf byteBuf = Unpooled.wrappedBuffer(blockEntityData);
try {
NBTInputStream reader = NbtUtils.createReaderLE(new ByteBufInputStream(byteBuf));
while (byteBuf.readableBytes() > 0) {
try {
NbtMap nbtMap = (NbtMap) reader.readTag();
int x = nbtMap.getInt("x", 0);
int y = nbtMap.getInt("y", 0);
int z = nbtMap.getInt("z", 0);
Block block = chunk.getBlock(x, y, z, 0);
if (block != null && block.hasBlockEntity()) {
BlockEntity blockEntity = BlockEntityType.getBlockEntityById(nbtMap.getString("id"), block);
if (blockEntity != null) {
blockEntity.fromCompound(nbtMap);
chunk.setBlockEntity(x, y, z, blockEntity);
}
}
} catch (IOException e) {
break;
}
}
} finally {
byteBuf.release();
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class LevelDB method loadSection.
public static void loadSection(SubChunk chunk, byte[] chunkData) {
ByteBuf buffer = Unpooled.wrappedBuffer(chunkData);
try {
byte subChunkVersion = buffer.readByte();
chunk.setSubChunkVersion(subChunkVersion);
int storages = 1;
switch(subChunkVersion) {
case 9:
case 8:
storages = buffer.readByte();
chunk.setLayer(storages);
if (subChunkVersion == 9) {
byte subY = buffer.readByte();
}
case 1:
for (int layer = 0; layer < storages; layer++) {
try {
buffer.markReaderIndex();
chunk.blocks[layer].readFromStoragePersistent(buffer, compound -> {
String identifier = compound.getString("name");
NbtMap states = compound.getCompound("states");
return BlockPalette.getRuntimeId(identifier, Objects.requireNonNullElse(states, NbtMap.EMPTY));
});
} catch (IllegalArgumentException e) {
buffer.resetReaderIndex();
chunk.blocks[layer].readFromStorageRuntime(buffer, runtimeId -> runtimeId, null);
}
}
break;
}
} finally {
buffer.release();
}
}
Aggregations