Merge pull request #9 from repo-alt/master-MC1.7.10

null check & a bit cleanup
This commit is contained in:
repo-alt 2020-04-15 00:42:04 +03:00 committed by GitHub
commit 8006f33b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,25 +16,26 @@ object EventHandlerIndustrialCraft2 {
@SubscribeEvent
def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) {
val world = e.host.world
val tile = world.getTileEntity(e.x, e.y, e.z) match {
case crop : ICropTile => {
world.getTileEntity(e.x, e.y, e.z) match {
case crop : ICropTile =>
crop.setScanLevel(4)
val cc = crop.getCrop
e.data += "crop:name" -> cc.name()
e.data += "crop:tier" -> Int.box(cc.tier)
e.data += "crop:size" -> Int.box(crop.getSize)
e.data += "crop:maxSize" -> Int.box(cc.maxSize)
e.data += "crop:growth" -> Int.box(crop.getGrowth)
e.data += "crop:gain" -> Int.box(crop.getGain)
e.data += "crop:resistance" -> Int.box(crop.getResistance)
e.data += "crop:fertilizer" -> Int.box(crop.getNutrientStorage)
e.data += "crop:hydration" -> Int.box(crop.getHydrationStorage)
e.data += "crop:weedex" -> Int.box(crop.getWeedExStorage)
e.data += "crop:humidity" -> Int.box(crop.getHumidity)
e.data += "crop:nutrients" -> Int.box(crop.getNutrients)
e.data += "crop:air" -> Int.box(crop.getAirQuality)
e.data += "crop:roots" -> Int.box(cc.getrootslength(crop))
}
if (cc != null) {
e.data += "crop:name" -> cc.name()
e.data += "crop:tier" -> Int.box(cc.tier)
e.data += "crop:size" -> Int.box(crop.getSize)
e.data += "crop:maxSize" -> Int.box(cc.maxSize)
e.data += "crop:growth" -> Int.box(crop.getGrowth)
e.data += "crop:gain" -> Int.box(crop.getGain)
e.data += "crop:resistance" -> Int.box(crop.getResistance)
e.data += "crop:fertilizer" -> Int.box(crop.getNutrientStorage)
e.data += "crop:hydration" -> Int.box(crop.getHydrationStorage)
e.data += "crop:weedex" -> Int.box(crop.getWeedExStorage)
e.data += "crop:humidity" -> Int.box(crop.getHumidity)
e.data += "crop:nutrients" -> Int.box(crop.getNutrients)
e.data += "crop:air" -> Int.box(crop.getAirQuality)
e.data += "crop:roots" -> Int.box(cc.getrootslength(crop))
}
case _ => None
}
}
@ -42,12 +43,12 @@ object EventHandlerIndustrialCraft2 {
def onRobotApplyDamageRate(e: RobotUsedToolEvent.ApplyDamageRate) {
val optManagerBefore = e.toolBeforeUse.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(e.toolBeforeUse))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}
val optManagerAfter = e.toolAfterUse.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(e.toolAfterUse))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}
(optManagerBefore, optManagerAfter) match {
@ -96,7 +97,7 @@ object EventHandlerIndustrialCraft2 {
def charge(stack: ItemStack, amount: Double, simulate: Boolean): Double = {
(stack.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(stack))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}) match {
case Some(manager) => amount - Power.fromEU(manager.charge(stack, Power.toEU(amount), Int.MaxValue, true, false))