java类net.minecraft.nbt.NBTTagString的实例源码

BookCreator.java 文件源码 项目:Minecoprocessors 阅读 15 收藏 0 点赞 0 评论 0
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;
}
ItemBookCode.java 文件源码 项目:Minecoprocessors 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}
EventHandler.java 文件源码 项目:genera 阅读 21 收藏 0 点赞 0 评论 0
@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);
    }
}
TileEntityGlyph.java 文件源码 项目:Bewitchment 阅读 31 收藏 0 点赞 0 评论 0
@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]));
        });
    }
}
TileEntityGlyph.java 文件源码 项目:Bewitchment 阅读 18 收藏 0 点赞 0 评论 0
@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);
}
AnimationSequence.java 文件源码 项目:ObsidianSuite 阅读 16 收藏 0 点赞 0 评论 0
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;
}
BookBot.java 文件源码 项目:ForgeHax 阅读 24 收藏 0 点赞 0 评论 0
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));
}
Minecraft.java 文件源码 项目:DecompiledMinecraft 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
}
AuthorCmd.java 文件源码 项目:Wurst-MC-1.12 阅读 17 收藏 0 点赞 0 评论 0
@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));
}
Minecraft.java 文件源码 项目:BaseClient 阅读 18 收藏 0 点赞 0 评论 0
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;
    }
}
Minecraft.java 文件源码 项目:BaseClient 阅读 16 收藏 0 点赞 0 评论 0
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;
    }
}
Minecraft.java 文件源码 项目:Zombe-Modpack 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
}
GuiScreenBook.java 文件源码 项目:Backmemed 阅读 29 收藏 0 点赞 0 评论 0
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;
    }
}
Minecraft.java 文件源码 项目:Backmemed 阅读 18 收藏 0 点赞 0 评论 0
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;
    }
}
Minecraft.java 文件源码 项目:CustomWorldGen 阅读 20 收藏 0 点赞 0 评论 0
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;
    }
}
XUHelper.java 文件源码 项目:ExtraUtilities 阅读 15 收藏 0 点赞 0 评论 0
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;
}
ItemUtil.java 文件源码 项目:wizards-of-lua 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
  }
}
NbtConverterTest.java 文件源码 项目:wizards-of-lua 阅读 15 收藏 0 点赞 0 评论 0
@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));
}
NbtConverterTest.java 文件源码 项目:wizards-of-lua 阅读 16 收藏 0 点赞 0 评论 0
@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));
}
NbtConverterTest.java 文件源码 项目:wizards-of-lua 阅读 17 收藏 0 点赞 0 评论 0
@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));
}
TileCore.java 文件源码 项目:Age-of-Kingdom 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
PlayerAokIEEP.java 文件源码 项目:Age-of-Kingdom 阅读 17 收藏 0 点赞 0 评论 0
@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);
}
QuestMine.java 文件源码 项目:ToroQuest 阅读 18 收藏 0 点赞 0 评论 0
@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;
}
TileEntityMagCardReader.java 文件源码 项目:Toms-Mod 阅读 15 收藏 0 点赞 0 评论 0
@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;
}
GuiNGTablet.java 文件源码 项目:NyaSamaRailway 阅读 20 收藏 0 点赞 0 评论 0
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;
    }

}
BlockAXYZ.java 文件源码 项目:TMT-Refraction 阅读 16 收藏 0 点赞 0 评论 0
@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));
        }
    }
}
GuiPythonBook.java 文件源码 项目:pycode-minecraft 阅读 21 收藏 0 点赞 0 评论 0
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));
}
NBTHelper.java 文件源码 项目:TaleCraft 阅读 20 收藏 0 点赞 0 评论 0
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;
    }

}
CraftUtils.java 文件源码 项目:CivCraft 阅读 24 收藏 0 点赞 0 评论 0
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;
}
BlockAbstractMachine.java 文件源码 项目:NordMod 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Информация для отображения, вызывается в {@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());
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号