Search in sources :

Example 1 with GenericContainer

use of mcjty.lib.container.GenericContainer in project RFTools by McJty.

the class StorageTools method compact.

public static void compact(EntityPlayer player) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (heldItem.isEmpty()) {
        return;
    }
    NBTTagCompound tagCompound = heldItem.getTagCompound();
    if (tagCompound == null) {
        return;
    }
    if (!tagCompound.hasKey("childDamage")) {
        // Should not be possible. Just for safety.
        return;
    }
    int moduleDamage = tagCompound.getInteger("childDamage");
    if (moduleDamage == StorageModuleItem.STORAGE_REMOTE) {
        int id = tagCompound.getInteger("id");
        RemoteStorageTileEntity remoteStorage = RemoteStorageIdRegistry.getRemoteStorage(player.getEntityWorld(), id);
        if (remoteStorage != null) {
            remoteStorage.compact(id);
            remoteStorage.markDirty();
        } else {
            Logging.message(player, TextFormatting.YELLOW + "Remote storage it not available (out of power or out of reach)!");
        }
    } else {
        GenericContainer genericContainer = (GenericContainer) player.openContainer;
        IInventory inventory = genericContainer.getInventory(ModularStorageItemContainer.CONTAINER_INVENTORY);
        ModularStorageItemInventory modularStorageItemInventory = (ModularStorageItemInventory) inventory;
        InventoryHelper.compactStacks(modularStorageItemInventory.getStacks(), 0, inventory.getSizeInventory());
        modularStorageItemInventory.markDirty();
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) GenericContainer(mcjty.lib.container.GenericContainer)

Aggregations

GenericContainer (mcjty.lib.container.GenericContainer)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1