Java Code Examples for codechicken.lib.inventory.InventoryUtils#savePersistant()

The following examples show how to use codechicken.lib.inventory.InventoryUtils#savePersistant() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NEIServerConfig.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void saveBannedItems() {
    File file = new File(saveDir, "banneditems.cfg");
    try {
        if (!file.exists()) {
            file.createNewFile();
        }

        PrintWriter p = new PrintWriter(file);
        p.println("#Saved in this format for external editing. The format isn't that hard to figure out. If you think you're up to it, modify it here!");

        for (ItemStackMap.Entry<Set<String>> entry : bannedItems.entries()) {
            NBTTagCompound key = InventoryUtils.savePersistant(entry.key, new NBTTagCompound());
            key.removeTag("Count");
            if (key.getByte("Damage") == 0) {
                key.removeTag("Damage");
            }

            p.print(key.toString());
            p.print("=[");
            int i = 0;
            for (String s : entry.value) {
                if (i++ != 0) {
                    p.print(", ");
                }
                p.print(s);
            }
            p.println("]");
        }
        p.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: NEIServerConfig.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void saveBannedItems() {
    File file = new File(saveDir, "banneditems.cfg");
    try {
        if(!file.exists())
            file.createNewFile();

        PrintWriter p = new PrintWriter(file);
        p.println("#Saved in this format for external editing. The format isn't that hard to figure out. If you think you're up to it, modify it here!");

        for (ItemStackMap.Entry<Set<String>> entry : bannedItems.entries()) {
            NBTTagCompound key = InventoryUtils.savePersistant(entry.key, new NBTTagCompound());
            key.removeTag("Count");
            if(key.getByte("Damage") == 0) key.removeTag("Damage");

            p.print(key.toString());
            p.print("=[");
            int i = 0;
            for (String s : entry.value) {
                if(i++ != 0) p.print(", ");
                p.print(s);
            }
            p.println("]");
        }
        p.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}