more minor electric item tidying

This commit is contained in:
MachineMuse 2013-07-02 13:32:26 -06:00
parent 9495b52797
commit d6c1786656
2 changed files with 12 additions and 51 deletions

View file

@ -12,54 +12,22 @@ object ElectricAdapter {
def wrap(stack: ItemStack): ElectricAdapter = {
if (stack == null) return null
stack.getItem match {
case i: IChargeableItem => return new TEElectricAdapter(stack)
case i: IItemElectric => return new UEElectricAdapter(stack)
case i: IElectricItem => if (ModCompatability.isIndustrialCraftLoaded) return new IC2ElectricAdapter(stack) else return null
case _ => return null
case i: IChargeableItem => new TEElectricAdapter(stack)
case i: IItemElectric => new UEElectricAdapter(stack)
case i: IElectricItem => if (ModCompatability.isIndustrialCraftLoaded) new IC2ElectricAdapter(stack) else null
case _ => null
}
}
}
abstract class ElectricAdapter {
/**
* Call to get the energy of an item
*
* @param stack
* IC2ItemTest to set
* @return Current energy level
*/
def getCurrentEnergy: Double
/**
* Call to set the energy of an item
*
* @param stack
* IC2ItemTest to set
* @return Maximum energy level
*/
def getMaxEnergy: Double
/**
* Call to drain energy from an item
*
* @param stack
* IC2ItemTest being requested for energy
* @param requested
* Amount of energy to drain
* @return Amount of energy successfully drained
*/
def drainEnergy(requested: Double): Double
/**
* Call to give energy to an item
*
* @param stack
* IC2ItemTest being requested for energy
* @param provided
* Amount of energy to drain
* @return Amount of energy used
*/
def giveEnergy(provided: Double): Double
}
@ -94,28 +62,21 @@ class TEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
class UEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
val item = stack.getItem.asInstanceOf[IItemElectric]
def getCurrentEnergy: Double = museEnergyFromJoules(item.getJoules(stack))
def getCurrentEnergy: Double = {
val currentEnergy: Double = museEnergyFromJoules(item.getJoules(stack))
return currentEnergy
}
def getMaxEnergy: Double = {
val maxEnergy: Double = museEnergyFromJoules(item.getMaxJoules(stack))
return maxEnergy
}
def getMaxEnergy: Double = museEnergyFromJoules(item.getMaxJoules(stack))
def drainEnergy(requested: Double): Double = {
val voltage: Double = item.getVoltage(stack)
val requestedPack: ElectricityPack = museEnergyToElectricityPack(requested, voltage)
val receivedPack: ElectricityPack = item.onProvide(requestedPack, stack)
return museEnergyFromElectricityPack(receivedPack)
museEnergyFromElectricityPack(receivedPack)
}
def giveEnergy(provided: Double): Double = {
val voltage: Double = item.getVoltage(stack)
val packToProvide: ElectricityPack = museEnergyToElectricityPack(provided, voltage)
val eatenPack: ElectricityPack = item.onReceive(packToProvide, stack)
return museEnergyFromElectricityPack(eatenPack)
museEnergyFromElectricityPack(eatenPack)
}
}

View file

@ -16,10 +16,10 @@ import net.machinemuse.api.ModuleManager
* Created: 10:12 PM, 4/20/13
*/
trait MuseElectricItem
extends ICustomElectricItem
with IItemElectric
with IChargeableItem
with IEMPItem {
extends ICustomElectricItem // IC2
with IItemElectric // UE
with IChargeableItem // TE
with IEMPItem { // ICBM
/**
* Call to get the energy of an item
*