use of com.nukkitx.nbt.NbtMap in project ProxyPass by CloudburstMC.
the class DownstreamPacketHandler method dumpCreativeItems.
private void dumpCreativeItems(ItemData[] contents) {
// Load up block palette for conversion, if we can find it.
Object object = proxy.loadGzipNBT("block_palette.nbt");
List<NbtMap> paletteTags = null;
if (object instanceof NbtMap) {
NbtMap map = (NbtMap) object;
paletteTags = map.getList("blocks", NbtType.COMPOUND);
} else {
log.warn("Failed to load block palette for creative content dump. Output will contain block runtime IDs!");
}
List<CreativeItemEntry> entries = new ArrayList<>();
for (ItemData data : contents) {
int runtimeId = data.getId();
StartGamePacket.ItemEntry entry = this.itemEntries.get(runtimeId);
if (entry == null) {
log.info("Could not find entry for item with runtime ID {}", runtimeId);
continue;
}
String id = entry.getIdentifier();
Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage();
String blockTag = null;
Integer blockRuntimeId = null;
if (data.getBlockRuntimeId() != 0 && paletteTags != null) {
blockTag = encodeNbtToString(paletteTags.get(data.getBlockRuntimeId()));
} else if (data.getBlockRuntimeId() != 0) {
blockRuntimeId = data.getBlockRuntimeId();
}
NbtMap tag = data.getTag();
String tagData = null;
if (tag != null) {
tagData = encodeNbtToString(tag);
}
entries.add(new CreativeItemEntry(id, damage, blockRuntimeId, blockTag, tagData));
}
CreativeItems items = new CreativeItems(entries);
proxy.saveJson("creative_items.json", items);
}
use of com.nukkitx.nbt.NbtMap in project BlockStateUpdater by CloudburstMC.
the class TagUtils method toMutable.
public static Object toMutable(Object immutable) {
if (immutable instanceof NbtMap) {
NbtMap map = (NbtMap) immutable;
Map<String, Object> mutable = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
mutable.put(entry.getKey(), toMutable(entry.getValue()));
}
return mutable;
} else if (immutable instanceof NbtList) {
List<Object> list = new ArrayList<>();
for (Object value : (List<?>) immutable) {
list.add(toMutable(value));
}
return list;
}
return immutable;
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntity method toItem.
public Item toItem(NbtMap compound) {
if (compound == null) {
return new ItemAir();
}
short data = compound.getShort("Damage", (short) 0);
byte amount = compound.getByte("Count", (byte) 0);
String name = compound.getString("Name", null);
NbtMap tag = compound.getCompound("tag", NbtMap.EMPTY);
if (name != null) {
return new Item(name).setAmount(amount).setMeta(data).setNBT(tag);
}
return new ItemAir();
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntity method fromItem.
public void fromItem(Item item, NbtMapBuilder builder) {
builder.putString("Name", item.getIdentifier());
builder.putShort("Damage", (short) item.getMeta());
builder.putByte("Count", (byte) item.getAmount());
if (item.getNBT() != null) {
NbtMap nbt = item.getNBT();
builder.putCompound("tag", nbt);
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntityBanner method fromCompound.
@Override
public void fromCompound(NbtMap compound) {
super.fromCompound(compound);
this.baseColor = compound.getInt("Base", 0);
this.type = compound.getInt("Type", 0);
List<NbtMap> patterns = compound.getList("blocks", NbtType.COMPOUND);
if (patterns != null) {
for (NbtMap pattern : patterns) {
this.patterns.put(pattern.getString("Pattern", "ss"), pattern.getInt("Color", 0));
}
}
}
Aggregations