public void updateEnergyValueFromInventory() {
   float newEnergyValue = storedEnergyValue.getValue();
   for (int i = 0; i <= STONE_INDEX; i++) {
     if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i])) {
       newEnergyValue += EnergyValueRegistryProxy.getEnergyValueForStack(inventory[i]).getValue();
     }
   }
   this.availableEnergyValue = new EnergyValue(newEnergyValue);
 }
  public void consumeInventoryForEnergyValue(ItemStack outputItemStack) {
    EnergyValue outputEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputItemStack);

    /**
     * Algorithm:
     *
     * <p>1) Check the Stone slot, and attempt to take EMC out of the stone there (til 0) 2) Search
     * the inventory for items that will most make up the difference, decrement them and consume
     * their EMC 3) Repeat 2 until Stored EMC > outputItemStack EMC 4) Profit
     */
    if (this.storedEnergyValue.compareTo(outputEnergyValue) >= 0) {
      this.storedEnergyValue =
          new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
    } else {
      while (this.storedEnergyValue.compareTo(outputEnergyValue) < 0
          && this.availableEnergyValue.compareTo(outputEnergyValue) >= 0) {
        for (int i = 0; i < STONE_INDEX; i++) {
          ItemStack stackInSlot = getStackInSlot(i);
          if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot)) {
            this.storedEnergyValue =
                new EnergyValue(
                    this.storedEnergyValue.getValue()
                        + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
            decrStackSize(i, 1);
          }
        }
      }

      if (this.storedEnergyValue.getValue() >= outputEnergyValue.getValue()) {
        this.storedEnergyValue =
            new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
      }
    }

    updateEnergyValueFromInventory();
  }