blob: 0dd510f2f157b640138fafc9ededaffb0a184de0 [file] [log] [blame] [raw]
package li.cil.oc.common.event
import net.minecraftforge.event.ForgeSubscribe
import li.cil.oc.api.event.RobotUsedTool
import li.cil.oc.util.mods.UniversalElectricity
object UniversalElectricityToolHandler {
@ForgeSubscribe
def onRobotApplyDamageRate(e: RobotUsedTool.ApplyDamageRate) {
if (UniversalElectricity.isEnergyItem(e.toolAfterUse)) {
val damage = UniversalElectricity.getEnergyInItem(e.toolBeforeUse) - UniversalElectricity.getEnergyInItem(e.toolAfterUse)
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage = if (e.robot.player.getRNG.nextDouble() > 0.5) damage - math.floor(actualDamage).toLong else damage - math.ceil(actualDamage).toLong
UniversalElectricity.chargeItem(e.toolAfterUse, repairedDamage)
}
}
}
}