From e64fe092fa09ef309149e5ba47d6f01e49fd5839 Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sat, 8 Aug 2015 14:59:33 +0200 Subject: [PATCH] Fixed RF and EU power dependency --- .../cr0s/warpdrive/machines/WarpEnergyTE.java | 82 +++++++++++++------ 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/machines/WarpEnergyTE.java b/src/main/java/cr0s/warpdrive/machines/WarpEnergyTE.java index 3fc5c0e9..0f81dfdf 100644 --- a/src/main/java/cr0s/warpdrive/machines/WarpEnergyTE.java +++ b/src/main/java/cr0s/warpdrive/machines/WarpEnergyTE.java @@ -1,11 +1,12 @@ package cr0s.warpdrive.machines; +import java.util.HashMap; + import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySource; - -import java.util.HashMap; +import cofh.api.energy.IEnergyHandler; import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Callback; @@ -14,9 +15,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; -import cofh.api.energy.IEnergyHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Optional; +import cr0s.warpdrive.WarpDriveConfig; import cr0s.warpdrive.api.IBlockUpdateDetector; import cr0s.warpdrive.data.EnumUpgradeTypes; @@ -32,9 +33,17 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa private static final double RF_PER_INTERNAL = 1800.0D / 437.5D; private int scanTickCount = -1; - private IEnergyHandler[] TE_energyHandlers = new IEnergyHandler[ForgeDirection.VALID_DIRECTIONS.length]; + + private Object[] cofhEnergyHandlers; + protected HashMap upgrades = new HashMap(); + public WarpEnergyTE() { + if (WarpDriveConfig.isThermalExpansionLoaded) { + this.RF_initialiseAPI(); + } + } + public Object[] getUpgrades() { Object[] retVal = new Object[EnumUpgradeTypes.values().length]; @@ -175,25 +184,25 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa } // IndustrialCraft2 - if (!addedToEnergyNet) { - MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); - addedToEnergyNet = true; + if (WarpDriveConfig.isICLoaded) { + IC2_addToEnergyNet(); } // Thermal Expansion - scanTickCount++; - if(scanTickCount >= 20) { - scanTickCount = 0; - scanForEnergyHandlers(); - } - outputEnergy(); + if (WarpDriveConfig.isThermalExpansionLoaded) { + scanTickCount++; + if(scanTickCount >= 20) { + scanTickCount = 0; + scanForEnergyHandlers(); + } + outputEnergy(); + } } @Override public void onChunkUnload() { - if (addedToEnergyNet) { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); - addedToEnergyNet = false; + if (WarpDriveConfig.isICLoaded) { + IC2_removeFromEnergyNet(); } super.onChunkUnload(); @@ -201,9 +210,8 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa @Override public void invalidate() { - if (addedToEnergyNet) { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); - addedToEnergyNet = false; + if (WarpDriveConfig.isICLoaded) { + IC2_removeFromEnergyNet(); } super.invalidate(); @@ -256,6 +264,23 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa return canOutputEnergy(to); } + @Optional.Method(modid = "IC2") + private void IC2_addToEnergyNet() { + if (!addedToEnergyNet) { + MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); + addedToEnergyNet = true; + } + } + + @Optional.Method(modid = "IC2") + private void IC2_removeFromEnergyNet() { + if (addedToEnergyNet) { + MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); + addedToEnergyNet = false; + } + } + + // ThermalExpansion IEnergyHandler interface @Override @@ -337,12 +362,17 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa @Optional.Method(modid = "CoFHCore") private void outputEnergy() { for(ForgeDirection from: ForgeDirection.VALID_DIRECTIONS) { - if (TE_energyHandlers[from.ordinal()] != null) { - outputEnergy(from, TE_energyHandlers[from.ordinal()]); + if (cofhEnergyHandlers[from.ordinal()] != null) { + outputEnergy(from, (IEnergyHandler) cofhEnergyHandlers[from.ordinal()]); } } } + @Optional.Method(modid = "CoFHCore") + private void RF_initialiseAPI() { + cofhEnergyHandlers = new IEnergyHandler[ForgeDirection.VALID_DIRECTIONS.length]; + } + // Forge overrides @Override @@ -383,11 +413,13 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa // WarpDrive overrides @Override public void updatedNeighbours() { - scanForEnergyHandlers(); + if (WarpDriveConfig.isThermalExpansionLoaded) { + scanForEnergyHandlers(); + } } @Optional.Method(modid = "CoFHCore") - public void scanForEnergyHandlers() { + private void scanForEnergyHandlers() { for(ForgeDirection from : ForgeDirection.VALID_DIRECTIONS) { boolean iehFound = false; if (canConnectEnergy(from)) { @@ -396,12 +428,12 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa IEnergyHandler ieh = (IEnergyHandler)te; if (ieh.canConnectEnergy(from.getOpposite())) { iehFound = true; - TE_energyHandlers[from.ordinal()] = ieh; + cofhEnergyHandlers[from.ordinal()] = ieh; } } } if (!iehFound) { - TE_energyHandlers[from.ordinal()] = null; + cofhEnergyHandlers[from.ordinal()] = null; } } }