blob: b032b87d36e7d5831f6689b8c64d0f2d9eab648d [file] [log] [blame] [raw]
package li.cil.oc.common.event
import cofh.api.energy.IEnergyContainerItem
import li.cil.oc.api.event.RobotUsedTool
import net.minecraftforge.event.ForgeSubscribe
object RedstoneFluxToolHandler {
@ForgeSubscribe
def onRobotApplyDamageRate(e: RobotUsedTool.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 _ =>
}
}
}