Reinstated RF support (#25)

This reverts commit ada04a64e1.
This commit is contained in:
bdew committed 2014-06-18 11:52:26 +03:00
1 parent cd83564428
commit 231be61c98
4 files changed
+66 -2

No files matched your search

@@ -11,4 +11,4 @@ package net.bdew.gendustry.power
import net.bdew.lib.power.ItemPoweredBase
trait ItemPowered extends ItemPoweredBase with ItemPoweredEU
trait ItemPowered extends ItemPoweredBase with ItemPoweredRF with ItemPoweredEU
@@ -0,0 +1,34 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.power
import cpw.mods.fml.common.Optional
import net.bdew.gendustry.compat.PowerProxy
import cofh.api.energy.IEnergyContainerItem
import net.minecraft.item.ItemStack
import net.bdew.lib.Misc
import net.bdew.gendustry.config.Tuning
import net.bdew.lib.power.ItemPoweredBase
@Optional.Interface(modid = PowerProxy.TE_MOD_ID, iface = "cofh.api.energy.IEnergyContainerItem")
trait ItemPoweredRF extends ItemPoweredBase with IEnergyContainerItem {
private lazy val ratio = Tuning.getSection("Power").getFloat("RF_MJ_Ratio")
def receiveEnergy(container: ItemStack, maxReceive: Int, simulate: Boolean): Int = {
val charge = getCharge(container)
val canCharge = Misc.clamp(maxCharge.toFloat - charge, 0F, maxReceive.toFloat / ratio).floor.toInt
if (!simulate) setCharge(container, charge + canCharge)
return (canCharge * ratio).round
}
def extractEnergy(container: ItemStack, maxExtract: Int, simulate: Boolean): Int = 0
def getEnergyStored(container: ItemStack): Int = (getCharge(container) * ratio).round
def getMaxEnergyStored(container: ItemStack): Int = (maxCharge * ratio).round
}
@@ -11,4 +11,4 @@ package net.bdew.gendustry.power
import net.bdew.lib.power.TilePoweredBase
trait TilePowered extends TilePoweredBase with TilePoweredMJ with TilePoweredEU
trait TilePowered extends TilePoweredBase with TilePoweredMJ with TilePoweredRF with TilePoweredEU
@@ -0,0 +1,30 @@
/*
* Copyright (c) bdew, 2013 - 2014
* https://github.com/bdew/gendustry
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
*/
package net.bdew.gendustry.power
import cofh.api.energy.IEnergyHandler
import net.bdew.gendustry.config.Tuning
import cpw.mods.fml.common.Optional
import net.bdew.gendustry.compat.PowerProxy
import net.bdew.lib.power.TilePoweredBase
import net.minecraftforge.common.util.ForgeDirection
@Optional.Interface(modid = PowerProxy.TE_MOD_ID, iface = "cofh.api.energy.IEnergyHandler")
trait TilePoweredRF extends TilePoweredBase with IEnergyHandler {
private lazy val ratio = Tuning.getSection("Power").getFloat("RF_MJ_Ratio")
override def receiveEnergy(from: ForgeDirection, maxReceive: Int, simulate: Boolean) =
(power.inject(maxReceive / ratio, simulate) * ratio).floor.toInt
override def extractEnergy(from: ForgeDirection, maxExtract: Int, simulate: Boolean) = 0
override def canConnectEnergy(from: ForgeDirection) = PowerProxy.RFEnabled
override def getEnergyStored(from: ForgeDirection) = (power.stored * ratio).floor.toInt
override def getMaxEnergyStored(from: ForgeDirection) = (power.capacity * ratio).floor.toInt
}