From d9aa7f5bd1479e0a8343810619767504fa0e3d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 25 Aug 2014 19:55:07 +0200 Subject: [PATCH] Potential fix for IC2 issues. --- .../scala/li/cil/oc/common/EventHandler.scala | 20 ------------------- .../power/IndustrialCraft2Classic.scala | 16 +++++++++++---- .../power/IndustrialCraft2Experimental.scala | 16 +++++++++++---- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/EventHandler.scala b/src/main/scala/li/cil/oc/common/EventHandler.scala index 848fe1ae1..92b1f88fb 100644 --- a/src/main/scala/li/cil/oc/common/EventHandler.scala +++ b/src/main/scala/li/cil/oc/common/EventHandler.scala @@ -55,16 +55,6 @@ object EventHandler extends ITickHandler with IConnectionHandler with ICraftingH } } - @Optional.Method(modid = Mods.IDs.IndustrialCraft2) - def scheduleIC2Remove(tileEntity: power.IndustrialCraft2Experimental) { - if (SideTracker.isServer) pending.synchronized { - pending += (() => if (tileEntity.addedToIC2PowerGrid) { - MinecraftForge.EVENT_BUS.post(new ic2.api.energy.event.EnergyTileUnloadEvent(tileEntity.asInstanceOf[ic2.api.energy.tile.IEnergyTile])) - tileEntity.addedToIC2PowerGrid = false - }) - } - } - @Optional.Method(modid = Mods.IDs.IndustrialCraft2Classic) def scheduleIC2Add(tileEntity: power.IndustrialCraft2Classic) { if (SideTracker.isServer) pending.synchronized { @@ -75,16 +65,6 @@ object EventHandler extends ITickHandler with IConnectionHandler with ICraftingH } } - @Optional.Method(modid = Mods.IDs.IndustrialCraft2Classic) - def scheduleIC2Remove(tileEntity: power.IndustrialCraft2Classic) { - if (SideTracker.isServer) pending.synchronized { - pending += (() => if (tileEntity.addedToIC2PowerGrid) { - MinecraftForge.EVENT_BUS.post(new ic2classic.api.energy.event.EnergyTileUnloadEvent(tileEntity.asInstanceOf[ic2classic.api.energy.tile.IEnergyTile])) - tileEntity.addedToIC2PowerGrid = false - }) - } - } - def scheduleWirelessRedstone(rs: server.component.RedstoneWireless) { if (SideTracker.isServer) pending.synchronized { pending += (() => if (!rs.owner.isInvalid) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Classic.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Classic.scala index b79edc3da..09eff6242 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Classic.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Classic.scala @@ -2,11 +2,12 @@ package li.cil.oc.common.tileentity.traits.power import cpw.mods.fml.common.Optional import ic2classic.api.Direction -import li.cil.oc.Settings import li.cil.oc.common.EventHandler import li.cil.oc.util.mods.Mods +import li.cil.oc.{OpenComputers, Settings} import net.minecraft.tileentity.TileEntity -import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.common.{ForgeDirection, MinecraftForge} +import net.minecraftforge.event.Event trait IndustrialCraft2Classic extends Common with IndustrialCraft2Common { private var lastInjectedAmount = 0.0 @@ -22,12 +23,19 @@ trait IndustrialCraft2Classic extends Common with IndustrialCraft2Common { override def invalidate() { super.invalidate() - if (useIndustrialCraft2ClassicPower && addedToIC2PowerGrid) EventHandler.scheduleIC2Remove(this) + if (useIndustrialCraft2ClassicPower && addedToIC2PowerGrid) removeFromIC2Grid() } override def onChunkUnload() { super.onChunkUnload() - if (useIndustrialCraft2ClassicPower && addedToIC2PowerGrid) EventHandler.scheduleIC2Remove(this) + if (useIndustrialCraft2ClassicPower && addedToIC2PowerGrid) removeFromIC2Grid() + } + + private def removeFromIC2Grid() { + try MinecraftForge.EVENT_BUS.post(Class.forName("ic2classic.api.energy.event.EnergyTileUnloadEvent").getConstructor(Class.forName("ic2classic.api.energy.tile.IEnergyTile")).newInstance(this).asInstanceOf[Event]) catch { + case t: Throwable => OpenComputers.log.warning("Error removing node from IC2 grid.", t) + } + addedToIC2PowerGrid = false } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala index aa0103d8a..6a25bed4e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/power/IndustrialCraft2Experimental.scala @@ -1,10 +1,11 @@ package li.cil.oc.common.tileentity.traits.power import cpw.mods.fml.common.Optional -import li.cil.oc.Settings import li.cil.oc.common.EventHandler import li.cil.oc.util.mods.Mods -import net.minecraftforge.common.ForgeDirection +import li.cil.oc.{OpenComputers, Settings} +import net.minecraftforge.common.{ForgeDirection, MinecraftForge} +import net.minecraftforge.event.Event trait IndustrialCraft2Experimental extends Common with IndustrialCraft2Common { private var lastInjectedAmount = 0.0 @@ -20,12 +21,19 @@ trait IndustrialCraft2Experimental extends Common with IndustrialCraft2Common { override def invalidate() { super.invalidate() - if (useIndustrialCraft2Power && addedToIC2PowerGrid) EventHandler.scheduleIC2Remove(this) + if (useIndustrialCraft2Power && addedToIC2PowerGrid) removeFromIC2Grid() } override def onChunkUnload() { super.onChunkUnload() - if (useIndustrialCraft2Power && addedToIC2PowerGrid) EventHandler.scheduleIC2Remove(this) + if (useIndustrialCraft2Power && addedToIC2PowerGrid) removeFromIC2Grid() + } + + private def removeFromIC2Grid() { + try MinecraftForge.EVENT_BUS.post(Class.forName("ic2.api.energy.event.EnergyTileUnloadEvent").getConstructor(Class.forName("ic2.api.energy.tile.IEnergyTile")).newInstance(this).asInstanceOf[Event]) catch { + case t: Throwable => OpenComputers.log.warning("Error removing node from IC2 grid.", t) + } + addedToIC2PowerGrid = false } // ----------------------------------------------------------------------- //