/**
   * Attempts to add the essentia to the cell
   *
   * @param aspect
   * @param Amount
   * @return Amount not stored
   */
  private long addEssentiaToCell(final Aspect aspect, final long amount, final Actionable mode) {
    // Calculate amount to store
    long amountToStore = Math.min(amount, this.totalEssentiaStorage - this.usedEssentiaStorage);

    // Ensure we can store any
    if (amountToStore == 0) {
      // Cell is full
      return amount;
    }

    // Get the slot for this aspect
    int slotIndex = this.getSlotFor(aspect);

    // Ensure there is somewhere to put the essentia
    if (slotIndex == -1) {
      return amount;
    }

    // Are we modulating?
    if (mode == Actionable.MODULATE) {
      // Get the slot
      AspectStack stackToAddTo = this.storedEssentia[slotIndex];

      // Is the slot null?
      if (stackToAddTo == null) {
        // Create the stack
        stackToAddTo = new AspectStack(aspect, 0);

        // Store it
        this.storedEssentia[slotIndex] = stackToAddTo;
      }

      // Add to the stack
      stackToAddTo.stackSize += amountToStore;

      // Adjust the used amount
      this.usedEssentiaStorage += amountToStore;

      // Write the changes to the data tag
      this.writeStorageChanges(slotIndex, stackToAddTo);
    }

    // Return the amount we could not store
    return (amount - amountToStore);
  }
  /**
   * Attempts to extract essentia from the cell.
   *
   * @param aspect
   * @param amount
   * @param mode
   * @return Amount extracted.
   */
  private long extractEssentiaFromCell(
      final Aspect aspect, final long amount, final Actionable mode) {
    // Do we have this essentia stored?
    int slotIndex = this.getSlotFor(aspect);
    if ((slotIndex == -1) || (this.storedEssentia[slotIndex] == null)) {
      // Not stored.
      return 0;
    }

    // Get the slot
    AspectStack slotToExtractFrom = this.storedEssentia[slotIndex];

    // Calculate the amount to extract
    long amountToExtract = Math.min(slotToExtractFrom.stackSize, amount);

    // Are we modulating?
    if (mode == Actionable.MODULATE) {
      // Extract from the slot
      slotToExtractFrom.stackSize -= amountToExtract;

      // Is the slot now empty?
      if (slotToExtractFrom.stackSize == 0) {
        // Null it
        slotToExtractFrom = null;

        // Update the storage
        this.storedEssentia[slotIndex] = null;
      }

      // Adjust the used amount
      this.usedEssentiaStorage -= amountToExtract;

      // Sync the data tag
      this.writeStorageChanges(slotIndex, slotToExtractFrom);
    }

    return amountToExtract;
  }