package refinedstorage.item;

import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import refinedstorage.RefinedStorageItems;
import refinedstorage.apiimpl.storage.NBTStorage;
import refinedstorage.block.EnumStorageType;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ItemStorageDisk extends ItemBase {
    public static final int TYPE_1K = 0;
    public static final int TYPE_4K = 1;
    public static final int TYPE_16K = 2;
    public static final int TYPE_64K = 3;
    public static final int TYPE_CREATIVE = 4;

    public ItemStorageDisk() {
        super("storage_disk");

        setMaxStackSize(1);
        setHasSubtypes(true);
        setMaxDamage(0);
    }

    @Override
    public void getSubItems(Item item, CreativeTabs tab, List list) {
        for (int i = 0; i < 5; ++i) {
            list.add(NBTStorage.createStackWithNBT(new ItemStack(item, 1, i)));
        }
    }

    @Override
    public void addInformation(ItemStack disk, EntityPlayer player, List list, boolean b) {
        int capacity = EnumStorageType.getById(disk.getItemDamage()).getCapacity();

        if (capacity == -1) {
            list.add(I18n.format("misc.refinedstorage:storage.stored", NBTStorage.getStoredFromNBT(disk.getTagCompound())));
        } else {
            list.add(I18n.format("misc.refinedstorage:storage.stored_capacity", NBTStorage.getStoredFromNBT(disk.getTagCompound()), capacity));
        }
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
        if (!world.isRemote) {
            ItemStack debugDisk = new ItemStack(RefinedStorageItems.STORAGE_DISK, 1, ItemStorageDisk.TYPE_CREATIVE);

            debugDisk.setTagCompound(NBTStorage.createNBT());

            NBTStorage storage = new NBTStorage(debugDisk.getTagCompound(), -1, null) {
                @Override
                public int getPriority() {
                    return 0;
                }
            };

            Iterator<Item> it = Item.REGISTRY.iterator();

            while (it.hasNext()) {
                Item item = it.next();

                List<ItemStack> stacks = new ArrayList<ItemStack>();

                item.getSubItems(item, CreativeTabs.BREWING, stacks);

                for (ItemStack itemStack : stacks) {
                    storage.push(itemStack, 1000, false);
                }
            }

            storage.writeToNBT();

            return new ActionResult(EnumActionResult.SUCCESS, debugDisk);
        } else if (!world.isRemote && player.isSneaking() && NBTStorage.getStoredFromNBT(stack.getTagCompound()) == 0 && stack.getMetadata() != TYPE_CREATIVE) {
            ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());

            if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
                InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
            }

            return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageItems.STORAGE_HOUSING));
        }

        return new ActionResult(EnumActionResult.PASS, stack);
    }

    @Override
    public void onCreated(ItemStack stack, World world, EntityPlayer player) {
        super.onCreated(stack, world, player);

        NBTStorage.createStackWithNBT(stack);
    }
}

@@ -577,63 +577,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.Iterator;%0A
 impo
@@ -1904,976 +1904,8 @@
  if 
-(!world.isRemote) %7B%0A            ItemStack debugDisk = new ItemStack(RefinedStorageItems.STORAGE_DISK, 1, ItemStorageDisk.TYPE_CREATIVE);%0A%0A            debugDisk.setTagCompound(NBTStorage.createNBT());%0A%0A            NBTStorage storage = new NBTStorage(debugDisk.getTagCompound(), -1, null) %7B%0A                @Override%0A                public int getPriority() %7B%0A                    return 0;%0A                %7D%0A            %7D;%0A%0A            Iterator%3CItem%3E it = Item.REGISTRY.iterator();%0A%0A            while (it.hasNext()) %7B%0A                Item item = it.next();%0A%0A                List%3CItemStack%3E stacks = new ArrayList%3CItemStack%3E();%0A%0A                item.getSubItems(item, CreativeTabs.BREWING, stacks);%0A%0A                for (ItemStack itemStack : stacks) %7B%0A                    storage.push(itemStack, 1000, false);%0A                %7D%0A            %7D%0A%0A            storage.writeToNBT();%0A%0A            return new ActionResult(EnumActionResult.SUCCESS, debugDisk);%0A        %7D else if 
 (!wo

Remove debugging disk