<commit_before>package net.machinemuse.utils

import net.machinemuse.api.electricity.ElectricAdapter
import net.machinemuse.powersuits.item.ItemComponent
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import scala.collection.JavaConverters._

object ElectricItemUtils {
  final val MAXIMUM_ENERGY: String = "Maximum Energy"
  final val CURRENT_ENERGY: String = "Current Energy"

  def electricItemsEquipped(player: EntityPlayer): Seq[ElectricAdapter] = {
    val electrics = new java.util.LinkedList[ElectricAdapter]()
    for (i <- 0 until player.inventory.getSizeInventory) {
      val adapter: ElectricAdapter = ElectricAdapter.wrap(player.inventory.getStackInSlot(i))
      if (adapter != null) {
        electrics.add(adapter)
      }
    }
    electrics.asScala
  }

  def getPlayerEnergy(player: EntityPlayer): Double = {
    (0.0 /: electricItemsEquipped(player)) {
      case (avail, adapter) => avail + adapter.getCurrentEnergy
    }
  }

  def getMaxEnergy(player: EntityPlayer): Double = {
    (0.0 /: electricItemsEquipped(player)) {
      case (avail, adapter) => avail + adapter.getMaxEnergy
    }
  }

  def drainPlayerEnergy(player: EntityPlayer, drainAmount: Double) {
    (drainAmount /: electricItemsEquipped(player)) {
      case (drainleft, adapter) => drainleft - adapter.drainEnergy(drainleft)
    }
  }

  def givePlayerEnergy(player: EntityPlayer, joulesToGive: Double) {
    (joulesToGive /: electricItemsEquipped(player)) {
      case (joulesleft, adapter) => joulesleft - adapter.giveEnergy(joulesleft)
    }
  }

  def jouleValueOfComponent(stackInCost: ItemStack): Double = {
    stackInCost.getItem match {
      case i: ItemComponent => (stackInCost.getItemDamage - ItemComponent.lvcapacitor.getItemDamage) match {
        case 0 => 20000 * stackInCost.stackSize
        case 1 => 100000 * stackInCost.stackSize
        case 2 => 750000 * stackInCost.stackSize
        case _ => 0
      }
      case _ => 0
    }
  }
}<commit_msg>drain electricity from top of inventory instead of bottom<commit_after>package net.machinemuse.utils

import net.machinemuse.api.electricity.ElectricAdapter
import net.machinemuse.powersuits.item.ItemComponent
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer

object ElectricItemUtils {
  final val MAXIMUM_ENERGY: String = "Maximum Energy"
  final val CURRENT_ENERGY: String = "Current Energy"

  def electricItemsEquipped(player: EntityPlayer): Seq[ElectricAdapter] = {
    val electrics = new ListBuffer[ElectricAdapter]()
    for (i <- 0 until player.inventory.getSizeInventory) {
      val adapter: ElectricAdapter = ElectricAdapter.wrap(player.inventory.getStackInSlot(i))
      if (adapter != null) {
        electrics.prepend(adapter)
      }
    }
    electrics
  }

  def getPlayerEnergy(player: EntityPlayer): Double = {
    (0.0 /: electricItemsEquipped(player)) {
      case (avail, adapter) => avail + adapter.getCurrentEnergy
    }
  }

  def getMaxEnergy(player: EntityPlayer): Double = {
    (0.0 /: electricItemsEquipped(player)) {
      case (avail, adapter) => avail + adapter.getMaxEnergy
    }
  }

  def drainPlayerEnergy(player: EntityPlayer, drainAmount: Double) {
    (drainAmount /: electricItemsEquipped(player)) {
      case (drainleft, adapter) => drainleft - adapter.drainEnergy(drainleft)
    }
  }

  def givePlayerEnergy(player: EntityPlayer, joulesToGive: Double) {
    (joulesToGive /: electricItemsEquipped(player)) {
      case (joulesleft, adapter) => joulesleft - adapter.giveEnergy(joulesleft)
    }
  }

  def jouleValueOfComponent(stackInCost: ItemStack): Double = {
    stackInCost.getItem match {
      case i: ItemComponent => (stackInCost.getItemDamage - ItemComponent.lvcapacitor.getItemDamage) match {
        case 0 => 20000 * stackInCost.stackSize
        case 1 => 100000 * stackInCost.stackSize
        case 2 => 750000 * stackInCost.stackSize
        case _ => 0
      }
      case _ => 0
    }
  }
}
{'fraction_non_alphanumeric': 0.10164497913086178, 'fraction_numerical': 0.013258040756199362, 'mean_word_length': 3.7098265895953757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5904665', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1249, 'n_words': 254}