Restoring Industrial Craft 2 compatibility

This commit is contained in:
Sergey Popov 2015-03-28 14:04:11 +03:00
parent d7b9aba63c
commit f93be8a44a
3 changed files with 52 additions and 31 deletions

View file

@ -1,6 +1,8 @@
package net.machinemuse.api.electricity package net.machinemuse.api.electricity
import cofh.api.energy.IEnergyContainerItem import cofh.api.energy.IEnergyContainerItem
import ic2.api.item.ElectricItem
import ic2.api.item.IElectricItem
import net.machinemuse.powersuits.common.ModCompatability import net.machinemuse.powersuits.common.ModCompatability
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
@ -12,8 +14,8 @@ object ElectricAdapter {
new MuseElectricAdapter(stack) new MuseElectricAdapter(stack)
} else if (ModCompatability.isCoFHCoreLoaded && i.isInstanceOf[IEnergyContainerItem]) { } else if (ModCompatability.isCoFHCoreLoaded && i.isInstanceOf[IEnergyContainerItem]) {
new TEElectricAdapter(stack) new TEElectricAdapter(stack)
} else if (ModCompatability.isIndustrialCraftLoaded) { } else if (ModCompatability.isIndustrialCraftLoaded && i.isInstanceOf[IElectricItem]) {
null new IC2ElectricAdapter(stack)
} else { } else {
null null
} }
@ -43,20 +45,22 @@ class MuseElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
def giveEnergy(provided: Double) = item.giveEnergyTo(stack, provided) def giveEnergy(provided: Double) = item.giveEnergyTo(stack, provided)
} }
//
//class IC2ElectricAdapter(val stack: ItemStack) extends ElectricAdapter { class IC2ElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
// val item = stack.getItem.asInstanceOf[IElectricItem] val item = stack.getItem.asInstanceOf[IElectricItem]
//
// def getCurrentEnergy: Double = museEnergyFromEU(ElectricItem.discharge(stack, Integer.MAX_VALUE, getTier, true, true)) import net.machinemuse.api.electricity.ElectricConversions._
//
// def getMaxEnergy: Double = museEnergyFromEU(item.getMaxCharge(stack)) def getCurrentEnergy: Double = museEnergyFromEU(ElectricItem.manager.getCharge(stack))
//
// def drainEnergy(requested: Double) = museEnergyFromEU(ElectricItem.discharge(stack, museEnergyToEU(requested).toInt, getTier, true, false)) def getMaxEnergy: Double = museEnergyFromEU(item.getMaxCharge(stack))
//
// def giveEnergy(provided: Double): Double = museEnergyFromEU(ElectricItem.charge(stack, museEnergyToEU(provided).toInt, getTier, true, false)) def drainEnergy(requested: Double): Double = museEnergyFromEU(ElectricItem.manager.discharge(stack, museEnergyToEU(requested), getTier, true, false, false))
//
// def getTier = item.getTier(stack) def giveEnergy(provided: Double): Double = museEnergyFromEU(ElectricItem.manager.charge(stack, museEnergyToEU(provided), getTier, true, false))
//}
def getTier = item.getTier(stack)
}
class TEElectricAdapter(val stack: ItemStack) extends ElectricAdapter { class TEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
val item = stack.getItem.asInstanceOf[IEnergyContainerItem] val item = stack.getItem.asInstanceOf[IEnergyContainerItem]
@ -71,4 +75,4 @@ class TEElectricAdapter(val stack: ItemStack) extends ElectricAdapter {
def giveEnergy(provided: Double): Double = museEnergyFromRF(item.receiveEnergy(stack, museEnergyToRF(provided), false)) def giveEnergy(provided: Double): Double = museEnergyFromRF(item.receiveEnergy(stack, museEnergyToRF(provided), false))
} }

View file

@ -1,22 +1,28 @@
package net.machinemuse.api.electricity package net.machinemuse.api.electricity
import cofh.api.energy.IEnergyContainerItem import cofh.api.energy.IEnergyContainerItem
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
import cpw.mods.fml.common.Optional import cpw.mods.fml.common.Optional
import net.machinemuse.api.ModuleManager import net.machinemuse.api.ModuleManager
import net.machinemuse.api.electricity.ElectricConversions._ import net.machinemuse.api.electricity.ElectricConversions._
import net.machinemuse.utils.{ElectricItemUtils, MuseItemUtils} import net.machinemuse.utils.{ElectricItemUtils, MuseItemUtils}
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
/** /**
* Author: MachineMuse (Claire Semple) * Author: MachineMuse (Claire Semple)
* Created: 10:12 PM, 4/20/13 * Created: 10:12 PM, 4/20/13
*/ */
@Optional.Interface(iface = "ic2.api.item.ICustomElectricItem", modid = "IC2", striprefs = true) @Optional.Interface(iface = "ic2.api.item.IElectricItemManager", modid = "IC2", striprefs = true)
@Optional.Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = "IC2", striprefs = true)
@Optional.Interface(iface = "cofh.api.energy.IEnergyContainerItem", modid = "CoFHCore", striprefs = true) @Optional.Interface(iface = "cofh.api.energy.IEnergyContainerItem", modid = "CoFHCore", striprefs = true)
trait MuseElectricItem trait MuseElectricItem
extends IEnergyContainerItem { extends IEnergyContainerItem
with ISpecialElectricItem
// with ICustomElectricItem // IC2 with IElectricItemManager {
// ICBM // ICBM
/** /**
* Call to get the energy of an item * Call to get the energy of an item
@ -83,15 +89,23 @@ trait MuseElectricItem
} }
// IC2 // IC2
def getManager(itemStack: ItemStack) = this
def chargeFromArmor(itemStack: ItemStack, entity: EntityLivingBase) = ElectricItem.rawManager.chargeFromArmor(itemStack,entity)
def use(itemStack: ItemStack, amount: Double, entity: EntityLivingBase) = ElectricItem.rawManager.use(itemStack,museEnergyToEU(amount),entity)
def canProvideEnergy(itemStack: ItemStack): Boolean = true def canProvideEnergy(itemStack: ItemStack): Boolean = true
def getMaxCharge(itemStack: ItemStack): Int = museEnergyToEU(getCurrentEnergy(itemStack)).asInstanceOf[Int] def getCharge(itemStack: ItemStack): Double = museEnergyToEU(getCurrentEnergy(itemStack))
def getMaxCharge(itemStack: ItemStack): Double = museEnergyToEU(getMaxEnergy(itemStack))
def getTier(itemStack: ItemStack): Int = ElectricConversions.getTier(itemStack) def getTier(itemStack: ItemStack): Int = ElectricConversions.getTier(itemStack)
def getTransferLimit(itemStack: ItemStack): Int = museEnergyToEU(Math.sqrt(getMaxEnergy(itemStack))).asInstanceOf[Int] def getTransferLimit(itemStack: ItemStack): Double = museEnergyToEU(Math.sqrt(getMaxEnergy(itemStack)))
def charge(itemStack: ItemStack, amount: Int, tier: Int, ignoreTransferLimit: Boolean, simulate: Boolean): Int = { def charge(itemStack: ItemStack, amount: Double, tier: Int, ignoreTransferLimit: Boolean, simulate: Boolean): Double = {
val current: Double = getCurrentEnergy(itemStack) val current: Double = getCurrentEnergy(itemStack)
val transfer = { val transfer = {
if (ignoreTransferLimit || amount < getTransferLimit(itemStack)) if (ignoreTransferLimit || amount < getTransferLimit(itemStack))
@ -103,10 +117,10 @@ trait MuseElectricItem
if (simulate) { if (simulate) {
setCurrentEnergy(itemStack, current) setCurrentEnergy(itemStack, current)
} }
museEnergyToEU(given).toInt museEnergyToEU(given)
} }
def discharge(itemStack: ItemStack, amount: Int, tier: Int, ignoreTransferLimit: Boolean, simulate: Boolean): Int = { def discharge(itemStack: ItemStack, amount: Double, tier: Int, ignoreTransferLimit: Boolean, externally: Boolean, simulate: Boolean): Double = {
val current: Double = getCurrentEnergy(itemStack) val current: Double = getCurrentEnergy(itemStack)
val transfer = { val transfer = {
if (ignoreTransferLimit || amount < getTransferLimit(itemStack)) if (ignoreTransferLimit || amount < getTransferLimit(itemStack))
@ -118,13 +132,12 @@ trait MuseElectricItem
if (simulate) { if (simulate) {
setCurrentEnergy(itemStack, current) setCurrentEnergy(itemStack, current)
} }
museEnergyToEU(taken).toInt museEnergyToEU(taken)
} }
def canUse(itemStack: ItemStack, amount: Int): Boolean = museEnergyFromEU(amount) < getCurrentEnergy(itemStack) def canUse(itemStack: ItemStack, amount: Double): Boolean = museEnergyFromEU(amount) < getCurrentEnergy(itemStack)
def getToolTip(itemStack: ItemStack): String = ElectricItem.rawManager.getToolTip(itemStack)
def canShowChargeToolTip(itemStack: ItemStack): Boolean = false
// TE // TE
def receiveEnergy(stack: ItemStack, energy: Int, simulate: Boolean): Int = { def receiveEnergy(stack: ItemStack, energy: Int, simulate: Boolean): Int = {
@ -151,4 +164,4 @@ trait MuseElectricItem
def getMaxEnergyStored(theItem: ItemStack) = museEnergyToRF(getMaxEnergy(theItem)).toInt def getMaxEnergyStored(theItem: ItemStack) = museEnergyToRF(getMaxEnergy(theItem)).toInt
} }

View file

@ -81,4 +81,8 @@ trait ModularItemBase extends Item with IModularItem with MuseElectricItem {
def drainPlayerEnergy(player: EntityPlayer, drainEnergy: Double) = ElectricItemUtils.drainPlayerEnergy(player, drainEnergy) def drainPlayerEnergy(player: EntityPlayer, drainEnergy: Double) = ElectricItemUtils.drainPlayerEnergy(player, drainEnergy)
def givePlayerEnergy(player: EntityPlayer, joulesToGive: Double) = ElectricItemUtils.givePlayerEnergy(player, joulesToGive) def givePlayerEnergy(player: EntityPlayer, joulesToGive: Double) = ElectricItemUtils.givePlayerEnergy(player, joulesToGive)
// Industrial Craft 2 methods
def getChargedItem(itemStack: ItemStack) : Item = this
def getEmptyItem(itemStack: ItemStack) : Item = this
} }