blob: 5009ca02008b8bb42b227f666e22c0c612279613 [file] [log] [blame] [raw]
package li.cil.oc.common.event
import cofh.api.energy.IEnergyContainerItem
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import li.cil.oc.api.event.RobotUsedToolEvent
object RedstoneFluxToolHandler {
@SubscribeEvent
def onRobotApplyDamageRate(e: RobotUsedToolEvent.ApplyDamageRate) {
(e.toolBeforeUse.getItem, e.toolAfterUse.getItem) match {
case (energyBefore: IEnergyContainerItem, energyAfter: IEnergyContainerItem) =>
val damage = energyBefore.getEnergyStored(e.toolBeforeUse) - energyAfter.getEnergyStored(e.toolAfterUse)
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage =
if (e.robot.player.getRNG.nextDouble() > 0.5)
damage - math.floor(actualDamage).toInt
else
damage - math.ceil(actualDamage).toInt
energyAfter.receiveEnergy(e.toolAfterUse, repairedDamage, false)
}
case _ =>
}
}
}