Search in sources :

Example 56 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project SpongeCommon by SpongePowered.

the class BreakablePlaceableUtils method set.

public static boolean set(ItemStack stack, String nbtKey, Set<BlockType> value) {
    NBTTagCompound stackTag = stack.getTagCompound();
    if (value.isEmpty()) {
        if (stackTag != null) {
            stackTag.removeTag(nbtKey);
            if (stackTag.hasNoTags()) {
                stack.setTagCompound(null);
            }
        }
    } else {
        NBTTagList breakableIds = new NBTTagList();
        for (BlockType breakable : value) {
            String id = breakable.getId();
            if (id.startsWith("minecraft:")) {
                id = id.substring("minecraft:".length());
            }
            breakableIds.appendTag(new NBTTagString(id));
        }
        if (stackTag == null) {
            stackTag = new NBTTagCompound();
            stack.setTagCompound(stackTag);
        }
        stackTag.setTag(nbtKey, breakableIds);
    }
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) BlockType(org.spongepowered.api.block.BlockType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 57 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Geolosys by oitsjustjose.

the class ItemFieldManual method getBook.

@SideOnly(Side.CLIENT)
public ItemStack getBook(Book book) {
    NBTTagCompound tags = new NBTTagCompound();
    List<NBTTagString> pages = Lists.newArrayList();
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    TIntObjectHashMap<String> contents = new TIntObjectHashMap<>();
    for (Page page : book.pages) {
        StringBuilder sb = new StringBuilder();
        String title = page.getTitle();
        String text = page.getText();
        if (title == null || text == null || title.isEmpty() || text.isEmpty()) {
            System.out.println("Well you succ");
            break;
        }
        contents.put(pages.size(), title);
        sb.append(TextFormatting.UNDERLINE).append(title).append(TextFormatting.RESET).append("\n\n").append(text);
        String formattedString = sb.toString();
        List<String> splitStrings = fontRenderer.listFormattedStringToWidth(formattedString, 116);
        StringBuilder sb2 = new StringBuilder();
        int lineNumber = 0;
        for (String s : splitStrings) {
            sb2.append(s).append("\n");
            lineNumber++;
            if (lineNumber >= 13) {
                pages.add(new NBTTagString(sb2.toString()));
                sb2 = new StringBuilder();
                lineNumber = 0;
            }
        }
        if (lineNumber != 0) {
            pages.add(new NBTTagString(sb2.toString()));
        }
    }
    final NBTTagList pageList = new NBTTagList();
    pageList.appendTag((NBTBase) new NBTTagString(TextFormatting.BOLD + "\n\n\n\n      Geolosys\n    Field Manual"));
    final int offset = 3 + contents.size() / 13;
    final int[] keys = contents.keys();
    Arrays.sort(keys);
    StringBuilder builder3 = new StringBuilder("Contents:\n\n");
    int i = 2;
    for (final int key : keys) {
        String line;
        int a;
        for (line = contents.get(key), a = key + offset; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() > 1; line = line.substring(0, line.length() - 1)) {
            ;
        }
        for (line += " "; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() == 1; line += " ") {
            ;
        }
        line += a;
        builder3.append(line).append('\n');
        if (++i >= 13) {
            i = 0;
            pageList.appendTag(new NBTTagString(builder3.toString()));
            builder3 = new StringBuilder();
        }
    }
    if (i != 0) {
        pageList.appendTag(new NBTTagString(builder3.toString()));
    }
    for (final NBTTagString page2 : pages) {
        pageList.appendTag(page2);
    }
    tags.setTag("pages", pageList);
    tags.setString("title", HelperFunctions.getTranslation("geolosys.field_manual.name"));
    tags.setString("author", "oitsjustjose");
    final ItemStack stack = new ItemStack(Items.WRITTEN_BOOK);
    stack.setTagCompound(tags);
    return stack;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) NBTTagString(net.minecraft.nbt.NBTTagString) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 58 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project NyaSamaRailway by NSDN.

the class GuiNGTablet method func_146457_a.

private void func_146457_a(String p_146457_1_) {
    if (this.ngtPages != null && this.currPage >= 0 && this.currPage < this.ngtPages.tagCount()) {
        this.ngtPages.func_150304_a(this.currPage, new NBTTagString(p_146457_1_));
        this.isNotEmpty = true;
    }
}
Also used : NBTTagString(net.minecraft.nbt.NBTTagString)

Example 59 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project NyaSamaRailway by NSDN.

the class GuiNGTablet method addNewPage.

private void addNewPage() {
    if (this.ngtPages != null && this.ngtPages.tagCount() < 50) {
        this.ngtPages.appendTag(new NBTTagString(""));
        ++this.ngtTotalPages;
        this.isNotEmpty = true;
    }
}
Also used : NBTTagString(net.minecraft.nbt.NBTTagString)

Example 60 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Charset by CharsetMC.

the class TileEntityDayBarrel method writeNBTData.

@Override
public NBTTagCompound writeNBTData(NBTTagCompound compound, boolean isClient) {
    ItemUtils.writeToNBT(item, compound, "item");
    compound.setInteger("count", item.getCount());
    woodLog.writeToNBT(compound, "log");
    woodSlab.writeToNBT(compound, "slab");
    compound.setByte("dir", (byte) orientation.ordinal());
    NBTTagList upgradeNBT = new NBTTagList();
    for (BarrelUpgrade u : upgrades) {
        upgradeNBT.appendTag(new NBTTagString(u.name()));
    }
    compound.setTag("upgrades", upgradeNBT);
    if (!isClient) {
        compound.setTag("lock", lockable.serializeNBT());
    }
    return compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)101 NBTTagList (net.minecraft.nbt.NBTTagList)82 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)18 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTBase (net.minecraft.nbt.NBTBase)10 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 List (java.util.List)7 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4