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();
}
}
Aggregations