Search in sources :

Example 26 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BuildCraft by BuildCraft.

the class InvUtils method addItemToolTip.

public static void addItemToolTip(ItemStack stack, String msg) {
    NBTTagCompound nbt = getItemData(stack);
    NBTTagCompound display = nbt.getCompoundTag("display");
    nbt.setTag("display", display);
    NBTTagList lore = display.getTagList("Lore", Constants.NBT.TAG_STRING);
    display.setTag("Lore", lore);
    lore.appendTag(new NBTTagString(msg));
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 27 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Railcraft by Railcraft.

the class ItemRoutingTable method setPages.

public static void setPages(ItemStack routingTable, List<List<String>> pages) {
    cleanEmptyPages(pages);
    NBTTagList data = new NBTTagList();
    for (List<String> page : pages) {
        NBTTagList pageNBT = new NBTTagList();
        data.appendTag(pageNBT);
        for (String line : page) {
            pageNBT.appendTag(new NBTTagString(line));
        }
    }
    NBTTagCompound nbt = InvTools.getItemData(routingTable);
    nbt.setTag("pages", data);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 28 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Railcraft by Railcraft.

the class ItemRoutingTable method getContents.

@Nullable
public static Deque<String> getContents(ItemStack routingTable) {
    if (InvTools.isEmpty(routingTable) || !isRoutingTable(routingTable))
        return null;
    NBTTagCompound nbt = routingTable.getTagCompound();
    if (nbt == null)
        return null;
    Deque<String> contents = new LinkedList<>();
    List<NBTTagList> pages = NBTPlugin.getNBTList(nbt, "pages", NBTTagList.class);
    for (NBTTagList page : pages) {
        List<NBTTagString> lines = NBTPlugin.asList(page);
        for (NBTTagString line : lines) {
            contents.add(line.getString());
        }
    }
    return contents;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project PneumaticCraft by MineMaarten.

the class NBTToJsonConverter method getObject.

private JsonObject getObject(NBTTagCompound tag) {
    Set<String> keys = tag.func_150296_c();
    JsonObject jsonRoot = new JsonObject();
    for (String key : keys) {
        JsonObject keyObject = new JsonObject();
        jsonRoot.add(key, keyObject);
        NBTBase nbt = tag.getTag(key);
        keyObject.addProperty("type", nbt.getId());
        if (nbt instanceof NBTTagCompound) {
            keyObject.add("value", getObject((NBTTagCompound) nbt));
        } else if (nbt instanceof NBTPrimitive) {
            keyObject.addProperty("value", ((NBTPrimitive) nbt).func_150286_g());
        } else if (nbt instanceof NBTTagString) {
            keyObject.addProperty("value", ((NBTTagString) nbt).func_150285_a_());
        } else if (nbt instanceof NBTTagList) {
            JsonArray array = new JsonArray();
            NBTTagList tagList = (NBTTagList) nbt;
            for (int i = 0; i < tagList.tagCount(); i++) {
                array.add(getObject(tagList.getCompoundTagAt(i)));
            }
            keyObject.add("value", array);
        } else if (nbt instanceof NBTTagIntArray) {
            JsonArray array = new JsonArray();
            NBTTagIntArray intArray = (NBTTagIntArray) nbt;
            for (int i : intArray.func_150302_c()) {
                array.add(new JsonPrimitive(i));
            }
            keyObject.add("value", array);
        } else {
            throw new IllegalArgumentException("NBT to JSON converter doesn't support the nbt tag: " + NBTBase.NBTTypes[nbt.getId()] + ", tag: " + nbt);
        }
    }
    return jsonRoot;
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTBase.NBTPrimitive) JsonPrimitive(com.google.gson.JsonPrimitive) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) JsonArray(com.google.gson.JsonArray) NBTBase(net.minecraft.nbt.NBTBase) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 30 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project ArsMagica2 by Mithion.

the class Story method WriteMultiplePartsToNBT.

public void WriteMultiplePartsToNBT(NBTTagCompound compound, List<Short> parts) {
    // title
    NBTTagString title = new NBTTagString(this.title);
    compound.setTag("title", title);
    // author
    NBTTagString author = new NBTTagString(this.author);
    compound.setTag("author", author);
    Collections.sort(parts);
    NBTTagList pages = new NBTTagList();
    for (Short i : parts) {
        ArrayList<NBTTagString> storyData = getStoryPart(i);
        if (storyData.equals(""))
            continue;
        for (NBTTagString page : storyData) {
            pages.appendTag(page);
        }
    }
    compound.setTag("pages", pages);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)98 NBTTagList (net.minecraft.nbt.NBTTagList)79 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)16 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTBase (net.minecraft.nbt.NBTBase)9 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 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 List (java.util.List)6 Map (java.util.Map)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4