Search in sources :

Example 51 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Bookshelf by Darkhax-Minecraft.

the class StackUtils method setLore.

/**
     * Sets the lore for an ItemStack. This will override any existing lore on that item.
     *
     * @param stackAn instance of an ItemStack to write the lore to.
     * @param loreAn array containing the lore to write. Each line is a new entry.
     * @return ItemStackThe same instance of ItemStack that was passed to this method.
     */
public static ItemStack setLore(ItemStack stack, String[] lore) {
    prepareStackTag(stack);
    final NBTTagCompound tag = stack.getTagCompound();
    final NBTTagList loreList = new NBTTagList();
    if (!tag.hasKey("display", 10)) {
        tag.setTag("display", new NBTTagCompound());
    }
    for (final String line : lore) {
        loreList.appendTag(new NBTTagString(line));
    }
    tag.getCompoundTag("display").setTag("Lore", loreList);
    stack.setTagCompound(tag);
    return stack;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 52 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project NetherEx by LogicTechCorp.

the class TradeListManager method init.

public static void init(File directory) {
    for (TradeCareer.EnumType career : TradeCareer.EnumType.values()) {
        offerLists.put(career, Maps.newHashMap());
    }
    try {
        LOGGER.info("Copying the Trade List Directory to the config folder.");
        if (NetherEx.IS_DEV_ENV) {
            FileUtils.copyDirectory(new File(NetherEx.class.getResource("/assets/nex/trade_lists").getFile()), directory);
        } else {
            FileUtil.extractFromJar("/assets/nex/trade_lists", directory.getPath());
        }
    } catch (IOException e) {
        LOGGER.fatal("The attempt to copy the Trade List Directory to the config folder was unsuccessful.");
        LOGGER.fatal(e);
    }
    try {
        Gson gson = new Gson();
        List<File> tradeFiles = Lists.newArrayList(directory.listFiles());
        for (File tradeFile : tradeFiles) {
            String jsonText = Files.toString(tradeFile, Charsets.UTF_8);
            TradeList tradeList = gson.fromJson(jsonText, TradeList.class);
            LOGGER.info("Adding trades from the " + tradeList.getName() + ".");
            for (TradeProfession profession : tradeList.getProfessions()) {
                for (TradeCareer career : profession.getCareers()) {
                    for (TradeOffer offer : career.getTrades()) {
                        ItemStack outputStack;
                        TradeOffer.Output output = offer.getOutput();
                        String outputId = output.getName();
                        int outputMeta = output.getMeta();
                        TradeOffer.Amount outputAmount = output.getAmount();
                        List<TradeOffer.Enchantment> outputEnchantments = output.getEnchantments();
                        TradeOffer.Display outputDisplay = output.getDisplay();
                        if (Item.getByNameOrId(outputId) != null) {
                            outputStack = new ItemStack(Item.getByNameOrId(outputId), 1, outputMeta);
                        } else if (Block.getBlockFromName(outputId) != null) {
                            outputStack = new ItemStack(Block.getBlockFromName(outputId), 1, outputMeta);
                        } else {
                            continue;
                        }
                        if (outputEnchantments == null) {
                            outputEnchantments = Lists.newArrayList();
                        }
                        if (outputDisplay != null) {
                            if (!Strings.isNullOrEmpty(outputDisplay.getName())) {
                                outputStack.setStackDisplayName(outputDisplay.getName());
                            }
                            if (outputDisplay.getLore().size() > 0) {
                                NBTUtil.setTag(outputStack);
                                NBTTagList loreList = new NBTTagList();
                                for (String lore : outputDisplay.getLore()) {
                                    loreList.appendTag(new NBTTagString(lore));
                                }
                                NBTTagCompound displayCompound = new NBTTagCompound();
                                displayCompound.setTag("Lore", loreList);
                                NBTTagCompound compound = new NBTTagCompound();
                                compound.setTag("display", displayCompound);
                                NBTUtil.setTag(outputStack, compound);
                            }
                        }
                        ItemStack inputStackA;
                        TradeOffer.Input inputA = offer.getInputA();
                        String inputAId = inputA.getName();
                        int inputAMeta = inputA.getMeta();
                        TradeOffer.Amount inputAAmount = inputA.getAmount();
                        if (Item.getByNameOrId(inputAId) != null) {
                            inputStackA = new ItemStack(Item.getByNameOrId(inputAId), 1, inputAMeta);
                        } else if (Block.getBlockFromName(inputAId) != null) {
                            inputStackA = new ItemStack(Block.getBlockFromName(inputAId), 1, inputAMeta);
                        } else {
                            continue;
                        }
                        ItemStack inputStackB;
                        TradeOffer.Input inputB = offer.getInputB();
                        if (inputB == null) {
                            inputB = new TradeOffer.Input("minecraft:air", 0, new TradeOffer.Amount(1, 1));
                        }
                        String inputBId = inputB.getName();
                        int inputBMeta = inputB.getMeta();
                        TradeOffer.Amount inputBAmount = inputB.getAmount();
                        if (Item.getByNameOrId(inputBId) != null) {
                            inputStackB = new ItemStack(Item.getByNameOrId(inputBId), 1, inputBMeta);
                        } else if (Block.getBlockFromName(inputBId) != null) {
                            inputStackB = new ItemStack(Block.getBlockFromName(inputBId), 1, inputBMeta);
                        } else {
                            continue;
                        }
                        TradeOffer.Amount offerAmount = offer.getAmount();
                        Trade trade = new Trade(outputStack, outputAmount, inputStackA, inputAAmount, inputStackB, inputBAmount, offerAmount, outputEnchantments);
                        offerLists.get(TradeCareer.EnumType.fromCareer(career)).computeIfAbsent(offer.getLevel(), k -> Lists.newArrayList()).add(trade);
                    }
                }
            }
        }
    } catch (IOException e) {
        LOGGER.fatal("NetherEx was unable to read the Trade lists.");
        LOGGER.fatal(e);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Charsets(com.google.common.base.Charsets) Item(net.minecraft.item.Item) FileUtil(nex.util.FileUtil) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) NetherEx(nex.NetherEx) Maps(com.google.common.collect.Maps) NBTTagString(net.minecraft.nbt.NBTTagString) File(java.io.File) NBTUtil(nex.util.NBTUtil) Strings(com.google.common.base.Strings) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) Lists(com.google.common.collect.Lists) Logger(org.apache.logging.log4j.Logger) Block(net.minecraft.block.Block) Files(com.google.common.io.Files) Gson(com.google.gson.Gson) LogManager(org.apache.logging.log4j.LogManager) NetherEx(nex.NetherEx) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Gson(com.google.gson.Gson) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) File(java.io.File)

Example 53 with NBTTagString

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

the class InvTools method markItemSynthetic.

@SuppressWarnings("unused")
public static void markItemSynthetic(ItemStack stack) {
    NBTTagCompound nbt = getItemData(stack);
    nbt.setBoolean("synthetic", true);
    NBTTagCompound display = nbt.getCompoundTag("display");
    nbt.setTag("display", display);
    NBTTagList lore = display.getTagList("Lore", 8);
    display.setTag("Lore", lore);
    lore.appendTag(new NBTTagString("§7§o" + LocalizationPlugin.translate("item.synthetic")));
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 54 with NBTTagString

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

the class ItemRoutingTable method setPages.

public static void setPages(ItemStack routingTable, LinkedList<LinkedList<String>> pages) {
    cleanEmptyPages(pages);
    NBTTagList data = new NBTTagList();
    for (LinkedList<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 55 with NBTTagString

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

the class NbtTranslator method fromTagBase.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object fromTagBase(NBTBase base, byte type) {
    switch(type) {
        case NbtDataUtil.TAG_BYTE:
            return ((NBTTagByte) base).getByte();
        case NbtDataUtil.TAG_SHORT:
            return (((NBTTagShort) base)).getShort();
        case NbtDataUtil.TAG_INT:
            return ((NBTTagInt) base).getInt();
        case NbtDataUtil.TAG_LONG:
            return ((NBTTagLong) base).getLong();
        case NbtDataUtil.TAG_FLOAT:
            return ((NBTTagFloat) base).getFloat();
        case NbtDataUtil.TAG_DOUBLE:
            return ((NBTTagDouble) base).getDouble();
        case NbtDataUtil.TAG_BYTE_ARRAY:
            return ((NBTTagByteArray) base).getByteArray();
        case NbtDataUtil.TAG_STRING:
            return ((NBTTagString) base).getString();
        case NbtDataUtil.TAG_LIST:
            NBTTagList list = (NBTTagList) base;
            byte listType = (byte) list.getTagType();
            int count = list.tagCount();
            List objectList = Lists.newArrayListWithCapacity(count);
            for (int i = 0; i < list.tagCount(); i++) {
                objectList.add(fromTagBase(list.get(i), listType));
            }
            return objectList;
        case NbtDataUtil.TAG_COMPOUND:
            return getViewFromCompound((NBTTagCompound) base);
        case NbtDataUtil.TAG_INT_ARRAY:
            return ((NBTTagIntArray) base).getIntArray();
        default:
            return null;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray)

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