Search in sources :

Example 46 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Minechem by iopleke.

the class AugmentedItem method setAugment.

/**
     * Set {@link minechem.item.augment.augments.IAugment} on Item
     *
     * @param item        ItemStack to add augment to
     * @param augmentItem Augment to add
     */
@Override
public boolean setAugment(ItemStack item, ItemStack augmentItem) {
    IAugment augment = AugmentRegistry.getAugment(augmentItem);
    if (augment == null) {
        return false;
    }
    if (!item.hasTagCompound()) {
        item.setTagCompound(new NBTTagCompound());
    }
    NBTTagCompound tagCompound = item.getTagCompound();
    String augmentKey = augment.getKey();
    if (!tagCompound.hasKey(augmentKey, Compendium.NBTTags.tagCompound)) {
        NBTTagList augments = tagCompound.getTagList(augmentList, Compendium.NBTTags.tagString);
        augments.appendTag(new NBTTagString(augmentKey));
        tagCompound.setTag(augmentList, augments);
        NBTTagCompound augmentTag = new NBTTagCompound();
        augmentTag.setTag(Compendium.NBTTags.item, augmentItem.writeToNBT(new NBTTagCompound()));
        augmentTag.setByte(this.level, (byte) 0);
        tagCompound.setTag(augmentKey, augmentTag);
        return true;
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IAugment(minechem.item.augment.augments.IAugment) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 47 with NBTTagString

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

the class FluidRegistry method writeDefaultFluidList.

public static void writeDefaultFluidList(NBTTagCompound forgeData) {
    NBTTagList tagList = new NBTTagList();
    for (Entry<String, Fluid> def : fluids.entrySet()) {
        tagList.appendTag(new NBTTagString(getDefaultFluidName(def.getValue())));
    }
    forgeData.setTag("DefaultFluidList", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 48 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class ItemIdentifier method getNBTBaseAsMap.

@SuppressWarnings("rawtypes")
public static Map<Object, Object> getNBTBaseAsMap(NBTBase nbt) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    if (nbt == null) {
        return null;
    }
    if (nbt instanceof NBTTagByte) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagByte");
        map.put("value", ((NBTTagByte) nbt).func_150290_f());
        return map;
    } else if (nbt instanceof NBTTagByteArray) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagByteArray");
        map.put("value", ItemIdentifier.getArrayAsMap(((NBTTagByteArray) nbt).func_150292_c()));
        return map;
    } else if (nbt instanceof NBTTagDouble) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagDouble");
        map.put("value", ((NBTTagDouble) nbt).func_150286_g());
        return map;
    } else if (nbt instanceof NBTTagFloat) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagFloat");
        map.put("value", ((NBTTagFloat) nbt).func_150288_h());
        return map;
    } else if (nbt instanceof NBTTagInt) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagInt");
        map.put("value", ((NBTTagInt) nbt).func_150287_d());
        return map;
    } else if (nbt instanceof NBTTagIntArray) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagIntArray");
        map.put("value", ItemIdentifier.getArrayAsMap(((NBTTagIntArray) nbt).func_150302_c()));
        return map;
    } else if (nbt instanceof NBTTagList) {
        List internal = ((NBTTagList) nbt).tagList;
        HashMap<Integer, Object> content = new HashMap<>();
        int i = 1;
        for (Object object : internal) {
            if (object instanceof NBTBase) {
                content.put(i, ItemIdentifier.getNBTBaseAsMap((NBTBase) object));
            }
            i++;
        }
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagList");
        map.put("value", content);
        return map;
    } else if (nbt instanceof NBTTagCompound) {
        Map internal = ((NBTTagCompound) nbt).tagMap;
        HashMap<Object, Object> content = new HashMap<>();
        HashMap<Integer, Object> keys = new HashMap<>();
        int i = 1;
        for (Object object : internal.entrySet()) {
            Entry e = (Entry) object;
            if (e.getValue() instanceof NBTBase) {
                content.put(e.getKey(), ItemIdentifier.getNBTBaseAsMap((NBTBase) e.getValue()));
                keys.put(i, e.getKey());
            }
            i++;
        }
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagCompound");
        map.put("value", content);
        map.put("keys", keys);
        return map;
    } else if (nbt instanceof NBTTagLong) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagLong");
        map.put("value", ((NBTTagLong) nbt).func_150291_c());
        return map;
    } else if (nbt instanceof NBTTagShort) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagShort");
        map.put("value", ((NBTTagShort) nbt).func_150287_d());
        return map;
    } else if (nbt instanceof NBTTagString) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("type", "NBTTagString");
        map.put("value", ((NBTTagString) nbt).func_150285_a_());
        return map;
    } else {
        throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) FinalNBTTagCompound(logisticspipes.utils.FinalNBTTagCompound) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) Entry(java.util.Map.Entry) NBTBase(net.minecraft.nbt.NBTBase) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagLong(net.minecraft.nbt.NBTTagLong)

Example 49 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class ItemModuleInformationManager method saveInfotmation.

public static void saveInfotmation(ItemStack itemStack, LogisticsModule module) {
    if (module == null) {
        return;
    }
    NBTTagCompound nbt = new NBTTagCompound();
    module.writeToNBT(nbt);
    if (nbt.equals(new NBTTagCompound())) {
        return;
    }
    if (MainProxy.isClient()) {
        NBTTagList list = new NBTTagList();
        String info1 = "Please reopen the window";
        String info2 = "to see the information.";
        list.appendTag(new NBTTagString(info1));
        list.appendTag(new NBTTagString(info2));
        if (!itemStack.hasTagCompound()) {
            itemStack.setTagCompound(new NBTTagCompound());
        }
        NBTTagCompound stacktag = itemStack.getTagCompound();
        stacktag.setTag("informationList", list);
        stacktag.setDouble("Random-Stack-Prevent", new Random().nextDouble());
        return;
    }
    if (!itemStack.hasTagCompound()) {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    NBTTagCompound stacktag = itemStack.getTagCompound();
    stacktag.setTag("moduleInformation", nbt);
    if (module instanceof IClientInformationProvider) {
        List<String> information = ((IClientInformationProvider) module).getClientInformation();
        if (information.size() > 0) {
            NBTTagList list = new NBTTagList();
            for (String info : information) {
                list.appendTag(new NBTTagString(info));
            }
            stacktag.setTag("informationList", list);
        }
    }
    stacktag.setDouble("Random-Stack-Prevent", new Random().nextDouble());
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Random(java.util.Random) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider)

Example 50 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class DebugHelper method addNBTToTree.

@SuppressWarnings("rawtypes")
private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    if (nbt == null) {
        return;
    }
    if (nbt instanceof NBTTagByte) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).func_150290_f()));
        node.add(type);
    } else if (nbt instanceof NBTTagByteArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByteArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (byte byt : ((NBTTagByteArray) nbt).func_150292_c()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + Byte.toString(byt)));
            i++;
        }
        node.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagDouble) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagDouble");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagDouble) nbt).func_150286_g()));
        node.add(type);
    } else if (nbt instanceof NBTTagFloat) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).func_150288_h()));
        node.add(type);
    } else if (nbt instanceof NBTTagInt) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).func_150287_d()));
        node.add(type);
    } else if (nbt instanceof NBTTagIntArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagIntArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (int byt : ((NBTTagIntArray) nbt).func_150302_c()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagList) {
        List internal = ((NBTTagList) nbt).tagList;
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (Object object : internal) {
            if (object instanceof NBTBase) {
                DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
                addNBTToTree((NBTBase) object, nbtNode);
                content.add(nbtNode);
                i++;
            }
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagCompound) {
        Map internal = ((NBTTagCompound) nbt).tagMap;
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        for (Object objectKey : internal.keySet()) {
            if (internal.get(objectKey) instanceof NBTBase) {
                DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(objectKey);
                addNBTToTree((NBTBase) internal.get(objectKey), nbtNode);
                content.add(nbtNode);
            }
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagLong) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagLong");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagLong) nbt).func_150291_c()));
        node.add(type);
    } else if (nbt instanceof NBTTagShort) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).func_150289_e()));
        node.add(type);
    } else if (nbt instanceof NBTTagString) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
        type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).func_150285_a_() + "'"));
        node.add(type);
    } else {
        throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) Map(java.util.Map) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagLong(net.minecraft.nbt.NBTTagLong)

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