Fixed RF and EU power dependency

This commit is contained in:
LemADEC 2015-08-08 14:59:33 +02:00
parent c75bc76d62
commit e64fe092fa

View file

@ -1,11 +1,12 @@
package cr0s.warpdrive.machines; package cr0s.warpdrive.machines;
import java.util.HashMap;
import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource; import ic2.api.energy.tile.IEnergySource;
import cofh.api.energy.IEnergyHandler;
import java.util.HashMap;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
@ -14,9 +15,9 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyHandler;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDriveConfig;
import cr0s.warpdrive.api.IBlockUpdateDetector; import cr0s.warpdrive.api.IBlockUpdateDetector;
import cr0s.warpdrive.data.EnumUpgradeTypes; 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 static final double RF_PER_INTERNAL = 1800.0D / 437.5D;
private int scanTickCount = -1; private int scanTickCount = -1;
private IEnergyHandler[] TE_energyHandlers = new IEnergyHandler[ForgeDirection.VALID_DIRECTIONS.length];
private Object[] cofhEnergyHandlers;
protected HashMap<EnumUpgradeTypes,Integer> upgrades = new HashMap<EnumUpgradeTypes,Integer>(); protected HashMap<EnumUpgradeTypes,Integer> upgrades = new HashMap<EnumUpgradeTypes,Integer>();
public WarpEnergyTE() {
if (WarpDriveConfig.isThermalExpansionLoaded) {
this.RF_initialiseAPI();
}
}
public Object[] getUpgrades() public Object[] getUpgrades()
{ {
Object[] retVal = new Object[EnumUpgradeTypes.values().length]; Object[] retVal = new Object[EnumUpgradeTypes.values().length];
@ -175,12 +184,12 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
} }
// IndustrialCraft2 // IndustrialCraft2
if (!addedToEnergyNet) { if (WarpDriveConfig.isICLoaded) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); IC2_addToEnergyNet();
addedToEnergyNet = true;
} }
// Thermal Expansion // Thermal Expansion
if (WarpDriveConfig.isThermalExpansionLoaded) {
scanTickCount++; scanTickCount++;
if(scanTickCount >= 20) { if(scanTickCount >= 20) {
scanTickCount = 0; scanTickCount = 0;
@ -188,12 +197,12 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
} }
outputEnergy(); outputEnergy();
} }
}
@Override @Override
public void onChunkUnload() { public void onChunkUnload() {
if (addedToEnergyNet) { if (WarpDriveConfig.isICLoaded) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); IC2_removeFromEnergyNet();
addedToEnergyNet = false;
} }
super.onChunkUnload(); super.onChunkUnload();
@ -201,9 +210,8 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
@Override @Override
public void invalidate() { public void invalidate() {
if (addedToEnergyNet) { if (WarpDriveConfig.isICLoaded) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); IC2_removeFromEnergyNet();
addedToEnergyNet = false;
} }
super.invalidate(); super.invalidate();
@ -256,6 +264,23 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
return canOutputEnergy(to); 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 // ThermalExpansion IEnergyHandler interface
@Override @Override
@ -337,12 +362,17 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
@Optional.Method(modid = "CoFHCore") @Optional.Method(modid = "CoFHCore")
private void outputEnergy() { private void outputEnergy() {
for(ForgeDirection from: ForgeDirection.VALID_DIRECTIONS) { for(ForgeDirection from: ForgeDirection.VALID_DIRECTIONS) {
if (TE_energyHandlers[from.ordinal()] != null) { if (cofhEnergyHandlers[from.ordinal()] != null) {
outputEnergy(from, TE_energyHandlers[from.ordinal()]); outputEnergy(from, (IEnergyHandler) cofhEnergyHandlers[from.ordinal()]);
} }
} }
} }
@Optional.Method(modid = "CoFHCore")
private void RF_initialiseAPI() {
cofhEnergyHandlers = new IEnergyHandler[ForgeDirection.VALID_DIRECTIONS.length];
}
// Forge overrides // Forge overrides
@Override @Override
@ -383,11 +413,13 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
// WarpDrive overrides // WarpDrive overrides
@Override @Override
public void updatedNeighbours() { public void updatedNeighbours() {
if (WarpDriveConfig.isThermalExpansionLoaded) {
scanForEnergyHandlers(); scanForEnergyHandlers();
} }
}
@Optional.Method(modid = "CoFHCore") @Optional.Method(modid = "CoFHCore")
public void scanForEnergyHandlers() { private void scanForEnergyHandlers() {
for(ForgeDirection from : ForgeDirection.VALID_DIRECTIONS) { for(ForgeDirection from : ForgeDirection.VALID_DIRECTIONS) {
boolean iehFound = false; boolean iehFound = false;
if (canConnectEnergy(from)) { if (canConnectEnergy(from)) {
@ -396,12 +428,12 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
IEnergyHandler ieh = (IEnergyHandler)te; IEnergyHandler ieh = (IEnergyHandler)te;
if (ieh.canConnectEnergy(from.getOpposite())) { if (ieh.canConnectEnergy(from.getOpposite())) {
iehFound = true; iehFound = true;
TE_energyHandlers[from.ordinal()] = ieh; cofhEnergyHandlers[from.ordinal()] = ieh;
} }
} }
} }
if (!iehFound) { if (!iehFound) {
TE_energyHandlers[from.ordinal()] = null; cofhEnergyHandlers[from.ordinal()] = null;
} }
} }
} }