Java Code Examples for cn.nukkit.item.Item#setNamedTag()
The following examples show how to use
cn.nukkit.item.Item#setNamedTag() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockShulkerBoxUndyed.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public Item toItem() { Item item = Item.get(Item.SHULKER_BOX, this.meta); BlockEntity blockEntity = this.level.getBlockEntity(this); if (blockEntity instanceof BlockEntityShulkerBox) { item.setNamedTag(blockEntity.namedTag); List<String> lore = new ArrayList<>(); int count = 0; Collection<Item> items = ((BlockEntityShulkerBox) blockEntity).getInventory().getContents().values(); for (Item i : items) { lore.add(i.getName() + " x" + i.getCount()); ++count; if (count == 5 && items.size() - count > 0){ lore.add("and " + (items.size() - count) + " more..."); break; } } item.setLore((String[])lore.toArray(new String[lore.size()])); } return item; }
Example 2
Source File: BlockShulkerBox.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public Item toItem() { Item item = Item.get(Item.SHULKER_BOX, this.meta); BlockEntity blockEntity = this.level.getBlockEntity(this); if (blockEntity instanceof BlockEntityShulkerBox) { item.setNamedTag(blockEntity.namedTag); List<String> lore = new ArrayList<>(); int count = 0; Collection<Item> items = ((BlockEntityShulkerBox) blockEntity).getInventory().getContents().values(); for (Item i : items) { lore.add(i.getName() + " x" + i.getCount()); ++count; if (count == 5 && items.size() - count > 0){ lore.add("and " + (items.size() - count) + " more..."); break; } } item.setLore((String[])lore.toArray(new String[lore.size()])); } return item; }
Example 3
Source File: NBTIO.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public static Item getItemHelper(CompoundTag tag) { if (!tag.contains("id") || !tag.contains("Count")) { return Item.get(0); } Item item; try { item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count")); } catch (Exception e) { item = Item.fromString(tag.getString("id")); item.setDamage(!tag.contains("Damage") ? 0 : tag.getShort("Damage")); item.setCount(tag.getByte("Count")); } Tag tagTag = tag.get("tag"); if (tagTag instanceof CompoundTag) { item.setNamedTag((CompoundTag) tagTag); } return item; }
Example 4
Source File: BlockBanner.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public Item toItem() { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); Item item = Item.get(Item.BANNER); if (blockEntity instanceof BlockEntityBanner) { BlockEntityBanner banner = (BlockEntityBanner) blockEntity; item.setDamage(banner.getBaseColor() & 0xf); item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag()) .putInt("Base", banner.getBaseColor() & 0xf)); int type = banner.namedTag.getInt("Type"); if (type > 0) { item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag()) .putInt("Type", type)); } ListTag<CompoundTag> patterns = banner.namedTag.getList("Patterns", CompoundTag.class); if (patterns.size() > 0) { item.setNamedTag((item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag()) .putList(patterns)); } } return item; }
Example 5
Source File: NBTIO.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public static Item getItemHelper(CompoundTag tag) { if (!tag.contains("id") || !tag.contains("Count")) { return Item.get(0); } Item item; try { item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count")); } catch (Exception e) { item = Item.fromString(tag.getString("id")); item.setDamage(!tag.contains("Damage") ? 0 : tag.getShort("Damage")); item.setCount(tag.getByte("Count")); } if (tag.contains("tag") && tag.get("tag") instanceof CompoundTag) { item.setNamedTag(tag.getCompound("tag")); } return item; }
Example 6
Source File: NBTIO.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static Item getItemHelper(CompoundTag tag) { if (!tag.contains("id") || !tag.contains("Count")) { return Item.get(0); } Item item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count")); if (tag.contains("tag") && tag.get("tag") instanceof CompoundTag) { CompoundTag nbt = tag.getCompound("tag").clone(); nbt.setName(""); item.setNamedTag(nbt); } return item; }