blob: 906796aa2aff1601365dac37092ee985b49f9c6a [file] [log] [blame] [raw]
package li.cil.oc.common.event
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import li.cil.oc.api.event.RobotUsedToolEvent
object RobotCommonHandler {
@SubscribeEvent
def onRobotApplyDamageRate(e: RobotUsedToolEvent.ApplyDamageRate) {
if (e.toolAfterUse.isItemStackDamageable) {
val damage = e.toolAfterUse.getItemDamage - e.toolBeforeUse.getItemDamage
if (damage > 0) {
val actualDamage = damage * e.getDamageRate
val repairedDamage = if (e.agent.player.getRNG.nextDouble() > 0.5) damage - math.floor(actualDamage).toInt else damage - math.ceil(actualDamage).toInt
e.toolAfterUse.setItemDamage(e.toolAfterUse.getItemDamage - repairedDamage)
}
}
}
}