Java 类net.minecraft.nbt.NBTTagString 实例源码

项目:Minecoprocessors    文件:BookCreator.java   
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;
}
项目:Minecoprocessors    文件:ItemBookCode.java   
/**
 * Store the data to the specified NBT tag.
 *
 * @param nbt the tag to save the data to.
 */
public void writeToNBT(final NBTTagCompound nbt) {
  final NBTTagList pagesNbt = new NBTTagList();
  int removed = 0;
  for (int index = 0; index < pages.size(); index++) {
    final List<String> program = pages.get(index);
    if (program.size() > 1 || program.get(0).length() > 0) {
      pagesNbt.appendTag(new NBTTagString(String.join("\n", program)));
    } else if (index < selectedPage) {
      removed++;
    }
  }
  nbt.setTag(TAG_PAGES, pagesNbt);

  nbt.setInteger(TAG_SELECTED, selectedPage - removed);
}
项目:genera    文件:EventHandler.java   
@SubscribeEvent
public void playerJoin(PlayerEvent.PlayerLoggedInEvent event) {
    ItemStack guideBookStack = new ItemStack(Items.WRITTEN_BOOK, 1);
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("title", new TextComponentTranslation("book.title.guide").getFormattedText());
    nbt.setString("author", new TextComponentTranslation("book.author.guide").getFormattedText());
    nbt.setInteger("generation", 2);
    NBTTagList nbtList = new NBTTagList();
    for (int index = 0; index <= 15; index++)
        nbtList.appendTag(new NBTTagString(String.format("{\"text\": \"%s\"}", new TextComponentTranslation(String.format("book.pages.guide.%d", index)).getFormattedText())));
    nbt.setTag("pages", nbtList);
    guideBookStack.setTagCompound(nbt);
    if (!event.player.getEntityData().getBoolean("genera.joined_before")) {
        event.player.getEntityData().setBoolean("genera.joined_before", true);
        event.player.getEntityData().setInteger("genera.sacrifices_made", 0);
        event.player.addItemStackToInventory(guideBookStack);
    }
}
项目:Bewitchment    文件:TileEntityGlyph.java   
@Override
protected void readDataNBT(NBTTagCompound tag) {
    cooldown = tag.getInteger("cooldown");
    if (tag.hasKey("ritual"))
        ritual = Ritual.REGISTRY.getValue(new ResourceLocation(tag.getString("ritual")));
    if (tag.hasKey("player"))
        entityPlayer = UUID.fromString(tag.getString("player"));
    if (tag.hasKey("data"))
        ritualData = tag.getCompoundTag("data");
    if (tag.hasKey("entityList")) {
        entityList = new ArrayList<Tuple<String, String>>();
        tag.getTagList("entityList", NBT.TAG_STRING).forEach(nbts -> {
            String[] names = ((NBTTagString) nbts).getString().split("!");
            if (names.length == 2)
                entityList.add(new Tuple<String, String>(names[0], names[1]));
        });
    }
}
项目:Bewitchment    文件:TileEntityGlyph.java   
@Override
protected void writeDataNBT(NBTTagCompound tag) {
    tag.setInteger("cooldown", cooldown);
    if (ritual != null)
        tag.setString("ritual", ritual.getRegistryName().toString());
    if (entityPlayer != null)
        tag.setString("player", entityPlayer.toString());
    if (ritualData != null)
        tag.setTag("data", ritualData);
    NBTTagList list = new NBTTagList();
    for (int i = 0; i < entityList.size(); i++) {
        Tuple<String, String> t = entityList.get(i);
        list.appendTag(new NBTTagString(t.getFirst() + "!" + t.getSecond()));
    }
    tag.setTag("entityList", list);
}
项目:ObsidianSuite    文件:AnimationSequence.java   
private NBTTagList getActionsSaveData()
{
    NBTTagList actionList = new NBTTagList();
    for (Map.Entry<Integer, Set<String>> entry : actionPoints.entrySet())
    {
        int time = entry.getKey();
        NBTTagList nameList = new NBTTagList();
        for (String name : entry.getValue())
        {
            nameList.appendTag(new NBTTagString(name));
        }

        NBTTagCompound timeCompound = new NBTTagCompound();
        timeCompound.setInteger("Time", time);
        timeCompound.setTag("Names", nameList);

        actionList.appendTag(timeCompound);
    }
    return actionList;
}
项目:ForgeHax    文件:BookBot.java   
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));
}
项目:DecompiledMinecraft    文件:Minecraft.java   
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_)
{
    ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    p_181036_3_.writeToNBT(nbttagcompound);

    if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        itemstack.setTagCompound(nbttagcompound3);
        return itemstack;
    }
    else
    {
        itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        itemstack.setTagInfo("display", nbttagcompound1);
        return itemstack;
    }
}
项目:Wurst-MC-1.12    文件:AuthorCmd.java   
@Override
public void call(String[] args) throws CmdException
{
    if(args.length == 0)
        throw new CmdSyntaxError();
    if(!WMinecraft.getPlayer().capabilities.isCreativeMode)
        throw new CmdError("Creative mode only.");
    ItemStack item = WMinecraft.getPlayer().inventory.getCurrentItem();
    if(item == null || Item.getIdFromItem(item.getItem()) != 387)
        throw new CmdError(
            "You are not holding a written book in your hand.");
    String author = args[0];
    for(int i = 1; i < args.length; i++)
        author += " " + args[i];
    item.setTagInfo("author", new NBTTagString(author));
}
项目:BaseClient    文件:Minecraft.java   
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_)
{
    ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    p_181036_3_.writeToNBT(nbttagcompound);

    if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        itemstack.setTagCompound(nbttagcompound3);
        return itemstack;
    }
    else
    {
        itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        itemstack.setTagInfo("display", nbttagcompound1);
        return itemstack;
    }
}
项目:BaseClient    文件:Minecraft.java   
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_) {
    ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    p_181036_3_.writeToNBT(nbttagcompound);

    if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner")) {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        itemstack.setTagCompound(nbttagcompound3);
        return itemstack;
    } else {
        itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        itemstack.setTagInfo("display", nbttagcompound1);
        return itemstack;
    }
}
项目:Zombe-Modpack    文件:Minecraft.java   
private ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
    NBTTagCompound nbttagcompound = te.writeToNBT(new NBTTagCompound());

    if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        stack.setTagCompound(nbttagcompound3);
        return stack;
    }
    else
    {
        stack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        stack.setTagInfo("display", nbttagcompound1);
        return stack;
    }
}
项目:Backmemed    文件:GuiScreenBook.java   
public GuiScreenBook(EntityPlayer player, ItemStack book, boolean isUnsigned)
{
    this.editingPlayer = player;
    this.bookObj = book;
    this.bookIsUnsigned = isUnsigned;

    if (book.hasTagCompound())
    {
        NBTTagCompound nbttagcompound = book.getTagCompound();
        this.bookPages = nbttagcompound.getTagList("pages", 8).copy();
        this.bookTotalPages = this.bookPages.tagCount();

        if (this.bookTotalPages < 1)
        {
            this.bookTotalPages = 1;
        }
    }

    if (this.bookPages == null && isUnsigned)
    {
        this.bookPages = new NBTTagList();
        this.bookPages.appendTag(new NBTTagString(""));
        this.bookTotalPages = 1;
    }
}
项目:Backmemed    文件:Minecraft.java   
private ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
    NBTTagCompound nbttagcompound = te.writeToNBT(new NBTTagCompound());

    if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        stack.setTagCompound(nbttagcompound3);
        return stack;
    }
    else
    {
        stack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        stack.setTagInfo("display", nbttagcompound1);
        return stack;
    }
}
项目:CustomWorldGen    文件:Minecraft.java   
public ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
    NBTTagCompound nbttagcompound = te.writeToNBT(new NBTTagCompound());

    if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        stack.setTagCompound(nbttagcompound3);
        return stack;
    }
    else
    {
        stack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        stack.setTagInfo("display", nbttagcompound1);
        return stack;
    }
}
项目:ExtraUtilities    文件:XUHelper.java   
public static ItemStack addLore(final ItemStack a, final String... lore) {
    NBTTagCompound tag = a.getTagCompound();
    if (tag == null) {
        tag = new NBTTagCompound();
    }
    if (!tag.hasKey("display", 10)) {
        tag.setTag("display", (NBTBase)new NBTTagCompound());
    }
    final NBTTagList l = new NBTTagList();
    for (final String s : lore) {
        l.appendTag((NBTBase)new NBTTagString(s));
    }
    tag.getCompoundTag("display").setTag("Lore", (NBTBase)l);
    a.setTagCompound(tag);
    return a;
}
项目:wizards-of-lua    文件:ItemUtil.java   
/**
 * Originally copied from {@link Minecraft#storeTEInStack(ItemStack, TileEntity)}
 * 
 */
private static ItemStack storeTEInStack(ItemStack stack, NBTTagCompound nbttagcompound) {
  if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner")) {
    NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
    NBTTagCompound nbttagcompound3 = new NBTTagCompound();
    nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
    stack.setTagCompound(nbttagcompound3);
    return stack;
  } else {
    stack.setTagInfo("BlockEntityTag", nbttagcompound);
    if (stack.isStackable()) {
      NBTTagCompound nbttagcompound1 = new NBTTagCompound();
      NBTTagList nbttaglist = new NBTTagList();
      nbttaglist.appendTag(new NBTTagString("(+NBT)"));
      nbttagcompound1.setTag("Lore", nbttaglist);
      stack.setTagInfo("display", nbttagcompound1);
    }
    return stack;
  }
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_toNbtCompound__With_two_StringEntries() {
  // Given:
  Table data = new DefaultTable();
  String key1 = "my_key1";
  String value1 = "my_value1";
  data.rawset(key1, value1);
  String key2 = "my_key2";
  String value2 = "my_value2";
  data.rawset(key2, value2);

  // When:
  NBTTagCompound actual = underTest.toNbtCompound(data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(key1, key2);
  assertThat(actual.getTag(key1)).isEqualTo(new NBTTagString(value1));
  assertThat(actual.getTag(key2)).isEqualTo(new NBTTagString(value2));
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_toNbtCompound__With_numeric_Key() {
  // Given:
  Table data = new DefaultTable();
  int key = 42;
  String value = "my_value";
  data.rawset(key, value);
  String keyString = String.valueOf(key);

  // When:
  NBTTagCompound actual = underTest.toNbtCompound(data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(keyString);
  assertThat(actual.getTag(keyString)).isEqualTo(new NBTTagString(value));
}
项目:wizards-of-lua    文件:NbtConverterTest.java   
@Test
public void test_toNbtCompound__With_List_Value() {
  // Given:
  Table data = new DefaultTable();
  String key = "my_key";
  Table value = new DefaultTable();
  data.rawset(key, value);
  long key2 = 1;
  String value2 = "my_value2";
  value.rawset(key2, value2);
  long key3 = 2;
  String value3 = "my_value3";
  value.rawset(key3, value3);

  // When:
  NBTTagCompound actual = underTest.toNbtCompound(data);

  // Then:
  assertThat(actual.getKeySet()).containsOnly(key);
  assertThat(actual.getTag(key)).isExactlyInstanceOf(NBTTagList.class);
  NBTTagList actualValue = actual.getTagList(key, NBT_STRING_TYPE);
  assertThat(actualValue).containsExactly(new NBTTagString(value2), new NBTTagString(value3));
}
项目:Age-of-Kingdom    文件:TileCore.java   
@Override
public void writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);

    compound.setBoolean("Using", isUsing);
    compound.setString("Lord", lord.toString());
    compound.setString("LordName", lordName);
    compound.setInteger("LordLevel", lordLevel);
    compound.setString("AokName", aokName);
    compound.setInteger("AokLevel", aokLevel);
    NBTTagList memberList = new NBTTagList();
    for (UUID member : members) {
        memberList.appendTag(new NBTTagString(member.toString()));
    }
    compound.setTag("Members", memberList);
}
项目:Age-of-Kingdom    文件:PlayerAokIEEP.java   
@Override
public void saveNBTData(NBTTagCompound compound) {
    NBTTagCompound tmp = new NBTTagCompound();

    tmp.setInteger("LordLevel", this.lordLevel);
    this.landPos.saveNBTData(tmp);
    tmp.setString("LordName", this.lordName);
    tmp.setString("AokName", this.aokName);
    tmp.setInteger("AokLevel", this.aokLevel);
    NBTTagList list = new NBTTagList();
    for(String member : this.members) {
        list.appendTag(new NBTTagString(member));
    }
    tmp.setTag("Members", list);
    compound.setTag(PROP_NAME, tmp);
}
项目:ToroQuest    文件:QuestMine.java   
@Override
public List<ItemStack> accept(QuestData data, List<ItemStack> in) {

    Block type = BLOCK_TYPES[getBlockType(data)];
    Province province = getQuestProvince(data);

    ItemStack tool;

    if (type == Blocks.GRAVEL) {
        tool = new ItemStack(Items.DIAMOND_SHOVEL);
    } else {
        tool = new ItemStack(Items.DIAMOND_PICKAXE);
    }

    tool.setStackDisplayName(tool.getDisplayName() + " of " + province.name);
    tool.addEnchantment(Enchantment.getEnchantmentByID(33), 1);
    tool.setTagInfo("mine_quest", new NBTTagString(data.getQuestId().toString()));
    tool.setTagInfo("province", new NBTTagString(province.id.toString()));

    in.add(tool);

    return in;
}
项目:Toms-Mod    文件:TileEntityMagCardReader.java   
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
    super.writeToNBT(tag);
    tag.setInteger("direction", this.direction);
    tag.setInteger("d", this.d.ordinal());
    NBTTagList list = new NBTTagList();
    for (String s : this.code) {
        list.appendTag(new NBTTagString(s));
    }
    tag.setTag("list", list);
    tag.setBoolean("codeMode", this.isCodeMode);
    tag.setInteger("linkX", this.posX);
    tag.setInteger("linkY", this.posY);
    tag.setInteger("linkZ", this.posZ);
    tag.setBoolean("linked", this.linked);
    // tag.setBoolean("debug", this.debug);
    return tag;
}
项目:NyaSamaRailway    文件:GuiNGTablet.java   
public GuiNGTablet(String modid, String texture, SimpleNetworkWrapper wrapper, ItemStack stack) {
    ngtGuiTextures = new ResourceLocation(modid.toLowerCase(),texture);
    this.wrapper = wrapper;
    this.ngtObj = stack;

    if (stack.hasTagCompound()) {
        NBTTagCompound var4 = stack.getTagCompound();
        this.ngtPages = var4.getTagList("pages", 8);
        if (this.ngtPages != null) {
            this.ngtPages = (NBTTagList)this.ngtPages.copy();
            this.ngtTotalPages = this.ngtPages.tagCount();
            if (this.ngtTotalPages < 1) {
                this.ngtTotalPages = 1;
            }
        }
    }

    if (this.ngtPages == null) {
        this.ngtPages = new NBTTagList();
        this.ngtPages.appendTag(new NBTTagString(""));
        this.ngtTotalPages = 1;
    }

}
项目:TMT-Refraction    文件:BlockAXYZ.java   
@Override
public void readFromNBT(@Nonnull NBTTagCompound nbttagcompound) {
    ModBlocks.AXYZ.mappedPositions.clear();

    Collection<String> tags = nbttagcompound.getKeySet();
    for (String key : tags) {
        NBTBase tag = nbttagcompound.getTag(key);
        if (tag instanceof NBTTagString) {
            String value = ((NBTTagString) tag).getString();
            DimWithPos dimWithPos = DimWithPos.fromString(key);
            World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dimWithPos.getDim());
            if (world.getBlockState(dimWithPos.getPos()).getBlock() == ModBlocks.AXYZ)
                ModBlocks.AXYZ.mappedPositions.put(DimWithPos.fromString(key), DimWithPos.fromString(value));
        }
    }
}
项目:pycode-minecraft    文件:GuiPythonBook.java   
private void sendBookToServer() throws IOException {
    if (!this.bookIsModified || this.bookPages == null) {
        return;
    }
    while (this.bookPages.tagCount() > 1) {
        String s = this.bookPages.getStringTagAt(this.bookPages.tagCount() - 1);
        if (!s.trim().isEmpty()) {
            break;
        }
        this.bookPages.removeTag(this.bookPages.tagCount() - 1);
    }
    this.bookObj.setTagInfo("pages", this.bookPages);
    String title = this.bookTitle;
    if (title.equals(TITLE_PLACEHOLDER)) title = "";
    this.bookObj.setTagInfo("title", new NBTTagString(title));

    PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
    packetbuffer.writeItemStackToBuffer(this.bookObj);
    this.mc.getConnection().sendPacket(new CPacketCustomPayload("MC|BEdit", packetbuffer));
}
项目:TaleCraft    文件:NBTHelper.java   
private static void asJson(NBTBase tag, StringBuilder builder) {
    switch(tag.getId()) {
    case NBT.TAG_BYTE: builder.append(((NBTTagByte)tag).getByte()).append('b'); break;
    case NBT.TAG_SHORT: builder.append(((NBTTagShort)tag).getByte()).append('b'); break;
    case NBT.TAG_INT: builder.append(((NBTTagInt)tag).getInt()); break;
    case NBT.TAG_LONG: builder.append(((NBTTagLong)tag).getByte()).append('l'); break;
    case NBT.TAG_FLOAT: builder.append(((NBTTagFloat)tag).getFloat()).append('f'); break;
    case NBT.TAG_DOUBLE: builder.append(((NBTTagDouble)tag).getDouble()).append('d'); break;
    case NBT.TAG_STRING: builder.append('"').append(((NBTTagString)tag).getString()).append('"'); break;
    case NBT.TAG_BYTE_ARRAY: builder.append(Arrays.toString(((NBTTagByteArray)tag).getByteArray())); break;
    case NBT.TAG_INT_ARRAY: builder.append(Arrays.toString(((NBTTagIntArray)tag).getIntArray())); break;
    case NBT.TAG_COMPOUND: asJson((NBTTagCompound) tag, builder); break;
    case NBT.TAG_LIST: asJson((NBTTagList) tag, builder); break;
    }

}
项目:CivCraft    文件:CraftUtils.java   
public static NBTTagCompound save() {
    NBTTagCompound nbt = new NBTTagCompound();
    for (Entry<Integer, Map<ChunkCoordIntPair, List<PlayerTechData>>> entry : levelPlayers.entrySet()) {
        int dimId = entry.getKey();
        NBTTagCompound dim = new NBTTagCompound();
        for (Entry<ChunkCoordIntPair, List<PlayerTechData>> innerEntry : entry.getValue().entrySet()) {
            ChunkCoordIntPair ccip = innerEntry.getKey();
            NBTTagList chunk = new NBTTagList();
            for (PlayerTechData ptd : innerEntry.getValue())
                chunk.appendTag(new NBTTagString(ptd.id.toString()));
            dim.setTag(ccip.chunkXPos + ":" + ccip.chunkZPos, chunk);
        }
        nbt.setTag(Integer.toString(dimId), dim);
    }
    return nbt;
}
项目:NordMod    文件:BlockAbstractMachine.java   
/**
 * Информация для отображения, вызывается в {@link #createItem}
 *
 * @param stack стак
 */
private void displayInformation(ItemStack stack) {
    NBTTagCompound dataTag = !stack.hasTagCompound() ? new NBTTagCompound() : stack.getTagCompound();
    String message = dataTag.hasKey("energy") && dataTag.hasKey("maxEnergy") ? "Energy: " + TextFormatting.RED + dataTag.getInteger("energy") / Constants.SHARE_MULTIPLE
            + "/" + dataTag.getInteger("maxEnergy") / Constants.SHARE_MULTIPLE + " " + Constants.ENERGY : "Energy: 0/0 " + Constants.ENERGY;

    NBTTagCompound displayTag;
    if (dataTag.hasKey("display")) {
        displayTag = dataTag.getCompoundTag("display");
    } else {
        displayTag = new NBTTagCompound();
        dataTag.setTag("display", displayTag);
    }

    NBTTagList loreTag;
    if (dataTag.hasKey("Lore")) {
        loreTag = displayTag.getTagList("Lore", net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
    } else {
        loreTag = new NBTTagList();
        displayTag.setTag("Lore", loreTag);
    }
    loreTag.appendTag(new NBTTagString(message));
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
    }
}
项目:ThermalRecycling    文件:ItemStackHelper.java   
/**
 * Sets the lore of the ItemStack.
 * 
 * @param stack
 * @param lore
 */
public static void setItemLore(final ItemStack stack, final List<String> lore) {

    if (stack == null)
        return;

    NBTTagCompound nbt = stack.getTagCompound();
    if (nbt == null)
        nbt = new NBTTagCompound();

    final NBTTagList l = new NBTTagList();
    for (final String s : lore)
        l.appendTag(new NBTTagString(s));
    NBTTagCompound display = nbt.getCompoundTag("display");
    if (display == null)
        display = new NBTTagCompound();
    display.setTag("Lore", l);

    nbt.setTag("display", display);
    stack.setTagCompound(nbt);
}
项目:UHC-Reloaded    文件:Misc.java   
/**
 * Add a tooltip for an item stack. It will be auto formatted to reset.
 *
 * @param stack   The original item stack that needs a tool tip
 * @param tooltip The list of tool tips to be added
 * @return The new item stack with these tool tip
 */
public static ItemStack appendToolTip(ItemStack stack, Iterable<String> tooltip) {
    NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
    boolean needAppend = false;
    NBTTagCompound tag1;
    if (tag.hasKey("display", NBT.TAG_COMPOUND)) {
        tag1 = tag.getCompoundTag("display");
        if (tag.hasKey("Lore", NBT.TAG_LIST)) {
            needAppend = true;
        }
    } else {
        tag.setTag("display", new NBTTagCompound());
        tag1 = tag.getCompoundTag("display");
    }
    if (!needAppend) {
        tag1.setTag("Lore", new NBTTagList());
    }
    for (String s : tooltip) {
        tag1.getTagList("Lore", NBT.TAG_LIST).appendTag(new NBTTagString(TextFormatting.RESET + s));
    }
    tag.setTag("display", tag1);
    ItemStack output = stack.copy();
    output.setTagCompound(tag);
    return output;
}
项目:Easy-Editors    文件:NBTToJson.java   
private static StringBuilder any(StringBuilder sb, NBTBase nbt) {
    switch (nbt.getId()) {
    case Constants.NBT.TAG_COMPOUND:
        return compound(sb, (NBTTagCompound) nbt);
    case Constants.NBT.TAG_LIST:
        return list(sb, (NBTTagList) nbt);
    case Constants.NBT.TAG_INT_ARRAY:
        return intArray(sb, (NBTTagIntArray) nbt);
    case Constants.NBT.TAG_STRING:
        return string(sb, (NBTTagString) nbt);
    case Constants.NBT.TAG_DOUBLE:
        return _double(sb, (NBTTagDouble) nbt);
    case Constants.NBT.TAG_FLOAT:
        return _float(sb, (NBTTagFloat) nbt);
    default:
        return other(sb, nbt);
    }
}
项目:Easy-Editors    文件:NBTToJson.java   
private static StringBuilder string(StringBuilder sb, NBTTagString str) {
    String theStr = str.getString();
    boolean requireQuotes = false;
    if (theStr.startsWith("{") || theStr.startsWith("["))
        requireQuotes = true;
    else if (numberPattern.matcher(theStr).matches() || theStr.equalsIgnoreCase("false")
            || theStr.equalsIgnoreCase("true"))
        requireQuotes = true;
    else if (theStr.contains(",") || theStr.contains("}") || theStr.contains("]"))
        requireQuotes = true;
    else if (theStr.startsWith("\""))
        requireQuotes = true;
    if (requireQuotes)
        theStr = "\"" + theStr.replace("\"", "\\\"") + "\"";

    return sb.append(theStr);
}
项目:Easy-Editors    文件:NBTTagHandler.java   
@Override
public void writeToNBT(NBTTagCompound nbt) {
    NBTTagCompound display = new NBTTagCompound();

    String displayNameText = displayName.getTextAsString();
    if (!displayNameText.isEmpty()) {
        display.setString("Name", displayNameText);
    }

    NBTTagList lore = new NBTTagList();
    for (int i = 0; i < this.lore.entryCount(); i++) {
        lore.appendTag(new NBTTagString(((ITextField<?>) this.lore.getEntry(i)).getTextAsString()));
    }
    if (!lore.hasNoTags())
        display.setTag("Lore", lore);

    if (!display.hasNoTags()) {
        if (nbt.hasKey("display", Constants.NBT.TAG_COMPOUND))
            display.merge(nbt.getCompoundTag("display"));
        nbt.setTag("display", display);
    }
}
项目:Husbandry    文件:Traits.java   
/**
 * Writes the traits instance to an {@link NBTTagCompound}
 * @return The traits tag
 */
public NBTTagCompound writeToTag() {
    NBTTagCompound traitsTag = new NBTTagCompound();
    NBTTagCompound fatherTag = new NBTTagCompound();
    NBTTagList fatherIds = new NBTTagList();
    for (Gene fatherGene : fatherGenes) {
        fatherTag.setTag(fatherGene.getUnlocalizedName(), fatherGene.toNBT());
        fatherIds.appendTag(new NBTTagString(fatherGene.getUnlocalizedName()));
    }
    traitsTag.setTag("father", fatherTag);
    traitsTag.setTag("fatherIds", fatherIds);
    NBTTagCompound motherTag = new NBTTagCompound();
    NBTTagList motherIds = new NBTTagList();
    for (Gene motherGene : motherGenes) {
        motherTag.setTag(motherGene.getUnlocalizedName(), motherGene.toNBT());
        motherIds.appendTag(new NBTTagString(motherGene.getUnlocalizedName()));
    }
    traitsTag.setTag("mother", motherTag);
    traitsTag.setTag("motherIds", motherIds);
    traitsTag.setString("gender", gender.toString());
    return traitsTag;
}
项目:Framez    文件:TileMotor.java   
@Override
public void writeToNBT(NBTTagCompound tag) {

    super.writeToNBT(tag);

    tag.setBoolean("redstoneInput", redstoneInput);

    tag.setInteger("face", getFace().ordinal());

    NBTTagCompound movement = new NBTTagCompound();
    getMovement().writeToNBT(movement);
    tag.setTag("movement", movement);

    NBTTagList l = new NBTTagList();
    for (MotorSetting s : settings)
        l.appendTag(new NBTTagString(s.ordinal() + ""));
    tag.setTag("settings", l);

    tag.setDouble("power", getEnergyBuffer());
}
项目:Framez    文件:TileMotor.java   
protected void readFromPacketNBT(NBTTagCompound tag) {

        face = ForgeDirection.getOrientation(tag.getInteger("face"));

        getMovement().readFromNBT(tag.getCompoundTag("movement"));

        settings.clear();
        NBTTagList l = tag.getTagList("settings", new NBTTagString().getId());
        for (int i = 0; i < l.tagCount(); i++)
            settings.add(MotorSetting.values()[Integer.parseInt(l.getStringTagAt(i))]);

        blocking = new ArrayList<Vec3i>();
        if (tag.hasKey("blocking")) {
            NBTTagList blocking = tag.getTagList("blocking", new NBTTagCompound().getId());
            for (int i = 0; i < blocking.tagCount(); i++) {
                NBTTagCompound t = blocking.getCompoundTagAt(i);
                this.blocking.add(new Vec3i(t.getInteger("x"), t.getInteger("y"), t.getInteger("z")));
            }
        }

        storedPower = tag.getDouble("power");

        markForRenderUpdate();
    }
项目:Framez    文件:PartFrame.java   
@Override
public void save(NBTTagCompound tag) {

    if (hidden == null)
        hidden = new boolean[6];

    super.save(tag);

    for (int i = 0; i < 6; i++) {
        tag.setBoolean("hidden_" + i, hidden[i]);
        NBTTagList l = new NBTTagList();
        for (IFrameSideModifier m : getSideModifiers(ForgeDirection.getOrientation(i)))
            l.appendTag(new NBTTagString(m.getType()));
        tag.setTag("sidemods_" + i, l);
    }
}
项目:Framez    文件:PartFrame.java   
@Override
public void load(NBTTagCompound tag) {

    if (hidden == null)
        hidden = new boolean[6];

    super.load(tag);

    for (int i = 0; i < 6; i++) {
        hidden[i] = tag.getBoolean("hidden_" + i);
        NBTTagList l = tag.getTagList("sidemods_" + i, new NBTTagString().getId());
        Collection<IFrameSideModifier> c = getSideModifiers(ForgeDirection.getOrientation(i));
        c.clear();
        for (int j = 0; j < l.tagCount(); j++)
            c.add((IFrameSideModifier) FrameModifierRegistry.instance().findModifier(l.getStringTagAt(j)));
    }
}