Java Code Examples for net.minecraft.item.ItemStack#setTagInfo()
The following examples show how to use
net.minecraft.item.ItemStack#setTagInfo() .
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: GTTileUUMAssembler.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public List<ItemStack> getDrops() { List<ItemStack> list = new ArrayList<>(); ItemStack stack = GTMaterialGen.get(GTBlocks.tileUUMAssembler); if (this.digitalCount > 0) { StackUtil.getOrCreateNbtData(stack).setInteger(NBT_DIGITALCOUNT, this.digitalCount); } if (this.energy > 0) { StackUtil.getOrCreateNbtData(stack).setInteger(NBT_STOREDENERGY, this.energy); } NBTTagCompound nbt = new NBTTagCompound(); writeInventory(nbt, this, 9); stack.setTagInfo("ItemsStored", nbt); list.add(stack); list.addAll(getInventoryDrops()); return list; }
Example 2
Source File: BookCreator.java From Minecoprocessors with GNU General Public License v3.0 | 6 votes |
private static ItemStack loadBook(String name) throws IOException { ItemStack book = new ItemStack(Items.WRITTEN_BOOK); String line; int lineNumber = 1; StringBuilder page = newPage(); try (BufferedReader reader = openBookReader(name)) { while ((line = reader.readLine()) != null) { if (lineNumber == 1) { book.setTagInfo("title", new NBTTagString(line)); } else if (lineNumber == 2) { book.setTagInfo("author", new NBTTagString(line)); } else if (PAGE_DELIMITER.equals(line)) { writePage(book, page); page = newPage(); } else { page.append(line).append("\n"); } lineNumber++; } } writePage(book, page); return book; }
Example 3
Source File: BookBot.java From ForgeHax with MIT License | 6 votes |
private void sendBook(ItemStack stack) { NBTTagList pages = new NBTTagList(); // page tag list // copy pages into NBT for (int i = 0; i < MAX_PAGES && parser.hasNext(); i++) { pages.appendTag(new NBTTagString(parser.next().trim())); page++; } // set our client side book if (stack.hasTagCompound()) { stack.getTagCompound().setTag("pages", pages); } else { stack.setTagInfo("pages", pages); } // publish the book stack.setTagInfo("author", new NBTTagString(getLocalPlayer().getName())); stack.setTagInfo( "title", new NBTTagString(parent.name.get().replaceAll(NUMBER_TOKEN, "" + getBook()).trim())); PacketBuffer buff = new PacketBuffer(Unpooled.buffer()); buff.writeItemStack(stack); MC.getConnection().sendPacket(new CPacketCustomPayload("MC|BSign", buff)); }
Example 4
Source File: CommandOutputs.java From Electro-Magic-Tools with GNU General Public License v3.0 | 6 votes |
public void addOutputsBook(String title, String text, ICommandSender command, String[] astring) { ItemStack book = new ItemStack(Items.written_book); book.setTagInfo("author", new NBTTagString("Tombenpotter")); book.setTagInfo("title", new NBTTagString(title)); NBTTagCompound nbttagcompound = book.getTagCompound(); NBTTagList bookPages = new NBTTagList(); bookPages.appendTag(new NBTTagString(text.substring(0, 237))); bookPages.appendTag(new NBTTagString(text.substring(237, 476))); bookPages.appendTag(new NBTTagString(text.substring(476, 709))); bookPages.appendTag(new NBTTagString(text.substring(709))); nbttagcompound.setTag("pages", bookPages); System.out.println(text.length()); if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(book)) command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(book, 0); }
Example 5
Source File: BookBase.java From minecraft-roguelike with GNU General Public License v3.0 | 6 votes |
@Override public ItemStack get(){ ItemStack book = new ItemStack(Items.WRITTEN_BOOK, 1); NBTTagList nbtPages = new NBTTagList(); for(String page : this.pages){ ITextComponent text = new TextComponentString(page); String json = ITextComponent.Serializer.componentToJson(text); NBTTagString nbtPage = new NBTTagString(json); nbtPages.appendTag(nbtPage); } book.setTagInfo("pages", nbtPages); book.setTagInfo("author", new NBTTagString(this.author == null ? "Anonymous" : this.author)); book.setTagInfo("title", new NBTTagString(this.title == null ? "Book" : this.title)); return book; }
Example 6
Source File: ItemUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemStack storeTEInStack(ItemStack stack, TileEntity te) { NBTTagCompound nbt = te.writeToNBT(new NBTTagCompound()); if (stack.getItem() == Items.SKULL && nbt.hasKey("Owner")) { NBTTagCompound tagOwner = nbt.getCompoundTag("Owner"); NBTTagCompound tagSkull = new NBTTagCompound(); tagSkull.setTag("SkullOwner", tagOwner); stack.setTagCompound(tagSkull); return stack; } else { NBTTagCompound tagLore = new NBTTagCompound(); NBTTagList tagList = new NBTTagList(); tagList.appendTag(new NBTTagString("(+NBT)")); tagLore.setTag("Lore", tagList); stack.setTagInfo("display", tagLore); stack.setTagInfo("BlockEntityTag", nbt); return stack; } }
Example 7
Source File: QuestCourier.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
@Override public List<ItemStack> accept(QuestData data, List<ItemStack> in) { Province deliverToProvince = getDeliverToProvince(data); ItemStack note = new ItemStack(Items.PAPER); note.setStackDisplayName("Deliver to the Lord of " + deliverToProvince.name); note.setTagInfo("toProvince", new NBTTagString(deliverToProvince.id.toString())); note.setTagInfo("questId", new NBTTagString(data.getQuestId().toString())); in.add(note); return in; }
Example 8
Source File: ItemExtendedNodeJar.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
public void setNodeAttributes(ItemStack itemstack, NodeType type, NodeModifier mod, ExtendedNodeType extendedNodeType, String id) { if (!itemstack.hasTagCompound()) { itemstack.setTagCompound(new NBTTagCompound()); } itemstack.setTagInfo("nodetype", new NBTTagInt(type.ordinal())); if (mod != null) { itemstack.setTagInfo("nodemod", new NBTTagInt(mod.ordinal())); } if(extendedNodeType != null) { itemstack.setTagInfo("nodeExMod", new NBTTagInt(extendedNodeType.ordinal())); } itemstack.setTagInfo("nodeid", new NBTTagString(id)); }
Example 9
Source File: ItemExtendedNodeJar.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
public void setBehaviorSnapshot(ItemStack itemstack, NBTTagCompound tagCompound) { if(tagCompound == null) return; if (!itemstack.hasTagCompound()) { itemstack.setTagCompound(new NBTTagCompound()); } itemstack.setTagInfo("Behavior", tagCompound); }
Example 10
Source File: TileEntityBanner.java From Et-Futurum with The Unlicense | 5 votes |
public ItemStack createStack() { ItemStack stack = new ItemStack(ModBlocks.banner, 1, getBaseColor()); NBTTagCompound nbt = new NBTTagCompound(); writeToNBT(nbt); nbt.removeTag("x"); nbt.removeTag("y"); nbt.removeTag("z"); nbt.removeTag("id"); stack.setTagInfo("BlockEntityTag", nbt); return stack; }
Example 11
Source File: ItemBanner.java From Et-Futurum with The Unlicense | 5 votes |
public static NBTTagCompound getSubTag(ItemStack stack, String key, boolean create) { if (stack.stackTagCompound != null && stack.stackTagCompound.hasKey(key, 10)) return stack.stackTagCompound.getCompoundTag(key); else if (create) { NBTTagCompound nbttagcompound = new NBTTagCompound(); stack.setTagInfo(key, nbttagcompound); return nbttagcompound; } else return null; }
Example 12
Source File: TileUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemStack storeTileEntityNBTInStack(ItemStack stack, NBTTagCompound nbt, boolean addNBTLore) { nbt.removeTag("x"); nbt.removeTag("y"); nbt.removeTag("z"); if (stack.getItem() == Items.SKULL && nbt.hasKey("Owner")) { NBTTagCompound tagOwner = nbt.getCompoundTag("Owner"); NBTTagCompound nbtOwner2 = new NBTTagCompound(); nbtOwner2.setTag("SkullOwner", tagOwner); stack.setTagCompound(nbtOwner2); } else { stack.setTagInfo("BlockEntityTag", nbt); if (addNBTLore) { NBTTagCompound tagDisplay = new NBTTagCompound(); NBTTagList tagLore = new NBTTagList(); tagLore.appendTag(new NBTTagString("(+NBT)")); tagDisplay.setTag("Lore", tagLore); stack.setTagInfo("display", tagDisplay); } } return stack; }
Example 13
Source File: Shield.java From minecraft-roguelike with GNU General Public License v3.0 | 5 votes |
public static void applyBanner(ItemStack banner, ItemStack shield){ NBTTagCompound bannerNBT = banner.getSubCompound("BlockEntityTag"); NBTTagCompound shieldNBT = bannerNBT == null ? new NBTTagCompound() : bannerNBT.copy(); shieldNBT.setInteger("Base", banner.getMetadata() & 15); shield.setTagInfo("BlockEntityTag", shieldNBT); }
Example 14
Source File: BookCreator.java From Minecoprocessors with GNU General Public License v3.0 | 4 votes |
private static void writePage(ItemStack book, StringBuilder page) { NBTTagList pages = getPagesNbt(book); pages.appendTag(createPage(page.toString())); book.setTagInfo("pages", pages); }
Example 15
Source File: QuestMine.java From ToroQuest with GNU General Public License v3.0 | 4 votes |
@SubscribeEvent public void onMine(HarvestDropsEvent event) { if (event.getHarvester() == null) { return; } EntityPlayer player = event.getHarvester(); Province inProvince = loadProvince(event.getHarvester().world, event.getPos()); if (inProvince == null || inProvince.civilization == null) { return; } ItemStack tool = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND); if (!tool.hasTagCompound()) { return; } String questId = tool.getTagCompound().getString("mine_quest"); String provinceId = tool.getTagCompound().getString("province"); if (questId == null || provinceId == null || !provinceId.equals(inProvince.id.toString())) { return; } QuestData data = getQuestById(player, questId); if (data == null) { return; } if (notCurrentDepth(event, data)) { return; } if (event.getState().getBlock() != BLOCK_TYPES[getBlockType(data)]) { return; } event.setDropChance(1f); for (ItemStack drop : event.getDrops()) { drop.setTagInfo("mine_quest", new NBTTagString(questId)); drop.setTagInfo("province", new NBTTagString(provinceId)); drop.setStackDisplayName(drop.getDisplayName() + " for " + inProvince.name); } }
Example 16
Source File: BookCreator.java From ToroQuest with GNU General Public License v3.0 | 4 votes |
@Nullable private static ItemStack loadBook(BookTypes type, String name) throws IOException { String path = "/assets/toroquest/books/" + type.toString().toLowerCase() + "/" + name + ".txt"; InputStream is = BookCreator.class.getResourceAsStream(path); if (is == null) { System.out.println("Book file not found [" + path + "]"); return null; } ItemStack book = new ItemStack(Items.WRITTEN_BOOK); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; int lineNumber = 1; NBTTagList pages = new NBTTagList(); String[] words; StringBuilder page = new StringBuilder(256); try { while ((line = reader.readLine()) != null) { line = line.trim(); if (lineNumber < 4 && line.length() == 0) { continue; } if (lineNumber == 1) { book.setTagInfo("title", new NBTTagString(line)); } else if (lineNumber == 2) { book.setTagInfo("author", new NBTTagString(line)); } else { if (line.length() == 0) { page = writePage(pages, page); } words = line.split("\\s+"); for (String word : words) { if (page.length() + word.length() > 255) { page = writePage(pages, page); } else if (page.length() > 0) { page.append(" "); } page.append(word); } } lineNumber++; } page = writePage(pages, page); } catch (IndexOutOfBoundsException e) { System.out.println(e.getMessage()); } book.setTagInfo("pages", pages); return book; }