use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntityContainer method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder compound = super.toCompound();
compound.put("CustomName", this.customName);
return compound;
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockEntityFurnace method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder builder = super.toCompound();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < this.furnaceInventory.getSize(); slot++) {
NbtMapBuilder itemCompound = NbtMap.builder();
Item item = this.furnaceInventory.getItem(slot);
itemCompound.putByte("Slot", (byte) slot);
this.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
return builder;
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockUndyedShulkerBox method toItem.
@Override
public ItemUndyedShulkerBox toItem() {
ItemUndyedShulkerBox itemShulkerBox = new ItemUndyedShulkerBox();
BlockEntityShulkerBox blockEntity = this.getBlockEntity();
if (blockEntity == null) {
return itemShulkerBox;
}
ShulkerBoxInventory shulkerBoxInventory = blockEntity.getShulkerBoxInventory();
NbtMapBuilder builder = NbtMap.builder();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < shulkerBoxInventory.getSize(); slot++) {
Item item = shulkerBoxInventory.getItem(slot);
if (item != null && !(item instanceof ItemAir)) {
NbtMapBuilder itemCompound = NbtMap.builder();
itemCompound.putByte("Slot", (byte) slot);
blockEntity.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
itemShulkerBox.setNBT(builder.build());
return itemShulkerBox;
}
use of com.nukkitx.nbt.NbtMapBuilder in project JukeboxMC by LucGamesYT.
the class BlockShulkerBox method toItem.
@Override
public ItemShulkerBox toItem() {
ItemShulkerBox itemShulkerBox = new ItemShulkerBox(this.runtimeId);
BlockEntityShulkerBox blockEntity = this.getBlockEntity();
if (blockEntity == null) {
return itemShulkerBox;
}
ShulkerBoxInventory shulkerBoxInventory = blockEntity.getShulkerBoxInventory();
NbtMapBuilder builder = NbtMap.builder();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < shulkerBoxInventory.getSize(); slot++) {
Item item = shulkerBoxInventory.getItem(slot);
if (item != null && !(item instanceof ItemAir)) {
NbtMapBuilder itemCompound = NbtMap.builder();
itemCompound.putByte("Slot", (byte) slot);
blockEntity.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
itemShulkerBox.setNBT(builder.build());
return itemShulkerBox;
}
use of com.nukkitx.nbt.NbtMapBuilder in project BlockStateUpdater by CloudburstMC.
the class TagUtils method toImmutable.
public static Object toImmutable(Object mutable) {
if (mutable instanceof Map) {
Map<String, Object> map = (Map<String, Object>) mutable;
NbtMapBuilder immutable = NbtMap.builder();
for (Map.Entry<String, Object> entry : map.entrySet()) {
immutable.put(entry.getKey(), toImmutable(entry.getValue()));
}
return immutable.build();
} else if (mutable instanceof List) {
List<Object> list = new ArrayList<>();
NbtType<?> type = NbtType.END;
for (Object value : (List<?>) mutable) {
if (type == NbtType.END) {
type = NbtType.byClass(value.getClass());
}
list.add(toImmutable(value));
}
return new NbtList(type, list);
}
return mutable;
}
Aggregations