Work on making interfaces optional

This commit is contained in:
MachineMuse 2014-04-08 04:43:13 -06:00
parent aaeee6dfd7
commit 2dfd3d00d7
4 changed files with 23 additions and 4 deletions

View file

@ -10,7 +10,8 @@ object ElectricAdapter {
def wrap(stack: ItemStack): ElectricAdapter = {
if (stack == null) return null
stack.getItem match {
case i: IEnergyContainerItem => new TEElectricAdapter(stack)
case i: MuseElectricItem => new MuseElectricAdapter(stack)
case i: IEnergyContainerItem => if (ModCompatability.isCoFHCoreLoaded) new TEElectricAdapter(stack) else null
case i: IElectricItem => if (ModCompatability.isIndustrialCraftLoaded) new IC2ElectricAdapter(stack) else null
case _ => null
}
@ -28,6 +29,18 @@ abstract class ElectricAdapter {
def giveEnergy(provided: Double): Double
}
class MuseElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
val item = stack.getItem.asInstanceOf[MuseElectricItem]
def getCurrentEnergy = item.getCurrentEnergy(stack)
def getMaxEnergy = item.getMaxEnergy(stack)
def drainEnergy(requested: Double) = item.drainEnergyFrom(stack, requested)
def giveEnergy(provided: Double) = item.giveEnergyTo(stack, provided)
}
class IC2ElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
val item = stack.getItem.asInstanceOf[IElectricItem]

View file

@ -4,18 +4,19 @@ import net.minecraft.item.ItemStack
import net.machinemuse.utils.{ElectricItemUtils, MuseItemUtils}
import ic2.api.item.ICustomElectricItem
import net.machinemuse.api.electricity.ElectricConversions._
import net.minecraft.entity.Entity
import net.machinemuse.api.ModuleManager
import cofh.api.energy.IEnergyContainerItem
import cpw.mods.fml.common.Optional
/**
* Author: MachineMuse (Claire Semple)
* Created: 10:12 PM, 4/20/13
*/
@Optional.Interface(iface = "ic2.api.item.ICustomElectricItem", modid = "IC2", striprefs = true)
@Optional.Interface(iface = "cofh.api.energy.IEnergyContainerItem", modid = "CoFHCore", striprefs = true)
trait MuseElectricItem
extends ICustomElectricItem // IC2
with IEnergyContainerItem // TE
{
with IEnergyContainerItem {
// ICBM
/**
* Call to get the energy of an item

View file

@ -43,6 +43,10 @@ public class ModCompatability {
return Loader.isModLoaded("GalacticraftCore");
}
public static boolean isCoFHCoreLoaded() {
return Loader.isModLoaded("CoFHCore");
}
public static boolean isForestryLoaded() {
return Loader.isModLoaded("Forestry");
}

View file

@ -17,6 +17,7 @@ import net.machinemuse.powersuits.client.render.item.ArmorModel
import net.machinemuse.api.{ModuleManager, ArmorTraits, IModularItem}
import net.machinemuse.numina.geometry.Colour
import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.common.Optional
/**
* Describes the 4 different modular armor pieces - head, torso, legs, feet.