Fixed IC2/TE support.

This commit is contained in:
Aidan Brady 2013-11-21 16:50:40 -05:00
parent d01d444753
commit 796a5aa397
6 changed files with 168 additions and 19 deletions

View file

@ -1,5 +1,6 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -12,6 +13,8 @@ import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
/**
* BasicSink is a simple adapter to provide an ic2 energy sink.
@ -121,7 +124,9 @@ public class BasicSink extends TileEntity implements IEnergySink {
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.worldObj;
xCoord = parent.xCoord;
yCoord = parent.yCoord;
@ -150,7 +155,8 @@ public class BasicSink extends TileEntity implements IEnergySink {
*/
@Override
public void onChunkUnload() {
if (addedToEnet) {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnet = false;
@ -194,6 +200,42 @@ public class BasicSink extends TileEntity implements IEnergySink {
// << in-world te forwards
// methods for using this adapter >>
/**
* Get the maximum amount of energy this sink can hold in its buffer.
*
* @return Capacity in EU.
*/
public int getCapacity() {
return capacity;
}
/**
* Set the maximum amount of energy this sink can hold in its buffer.
*
* @param capacity Capacity in EU.
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
/**
* Get the IC2 energy tier for this sink.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Set the IC2 energy tier for this sink.
*
* @param tier IC2 Tier.
*/
public void setTier(int tier) {
this.tier = tier;
}
/**
* Determine the energy stored in the sink's input buffer.
*
@ -241,6 +283,28 @@ public class BasicSink extends TileEntity implements IEnergySink {
}
}
/**
* Discharge the supplied ItemStack into this sink's energy buffer.
*
* @param stack ItemStack to discharge (null is ignored)
* @param limit Transfer limit, values <= 0 will use the battery's limit
* @return true if energy was transferred
*/
public boolean discharge(ItemStack stack, int limit) {
if (stack == null || !Info.isIc2Available()) return false;
int amount = (int) Math.floor(capacity - energyStored);
if (amount <= 0) return false;
if (limit > 0 && limit < amount) amount = limit;
amount = ElectricItem.manager.discharge(stack, amount, tier, limit > 0, false);
energyStored += amount;
return amount > 0;
}
// << methods for using this adapter
// backwards compatibility (ignore these) >>
@ -304,9 +368,9 @@ public class BasicSink extends TileEntity implements IEnergySink {
public final TileEntity parent;
public final int capacity;
public final int tier;
protected int capacity;
protected int tier;
protected double energyStored;
protected boolean addedToEnet;
}

View file

@ -13,6 +13,7 @@ import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
/**
@ -123,7 +124,9 @@ public class BasicSource extends TileEntity implements IEnergySource {
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.worldObj;
xCoord = parent.xCoord;
yCoord = parent.yCoord;
@ -152,7 +155,8 @@ public class BasicSource extends TileEntity implements IEnergySource {
*/
@Override
public void onChunkUnload() {
if (addedToEnet) {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnet = false;
@ -196,6 +200,51 @@ public class BasicSource extends TileEntity implements IEnergySource {
// << in-world te forwards
// methods for using this adapter >>
/**
* Get the maximum amount of energy this source can hold in its buffer.
*
* @return Capacity in EU.
*/
public int getCapacity() {
return capacity;
}
/**
* Set the maximum amount of energy this source can hold in its buffer.
*
* @param capacity Capacity in EU.
*/
public void setCapacity(int capacity) {
int power = EnergyNet.instance.getPowerFromTier(tier);
if (capacity < power) capacity = power;
this.capacity = capacity;
}
/**
* Get the IC2 energy tier for this source.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Set the IC2 energy tier for this source.
*
* @param tier IC2 Tier.
*/
public void setTier(int tier) {
int power = EnergyNet.instance.getPowerFromTier(tier);
if (capacity < power) capacity = power;
this.tier = tier;
}
/**
* Determine the energy stored in the source's output buffer.
*
@ -248,7 +297,7 @@ public class BasicSource extends TileEntity implements IEnergySource {
* @return true if energy was transferred
*/
public boolean charge(ItemStack stack) {
if (stack == null) return false;
if (stack == null || !Info.isIc2Available()) return false;
int amount = ElectricItem.manager.charge(stack, (int) energyStored, tier, false, false);
@ -319,9 +368,9 @@ public class BasicSource extends TileEntity implements IEnergySource {
public final TileEntity parent;
public final int capacity;
public final int tier;
protected int capacity;
protected int tier;
protected double energyStored;
protected boolean addedToEnet;
}

View file

@ -2,6 +2,9 @@ package ic2.api.info;
import net.minecraft.util.DamageSource;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState;
public class Info {
public static IEnergyValueProvider itemEnergy;
public static IFuelValueProvider itemFuel;
@ -12,4 +15,18 @@ public class Info {
* Getting assigned in preload.
*/
public static DamageSource DMG_ELECTRIC, DMG_NUKE_EXPLOSION, DMG_RADIATION;
public static boolean isIc2Available() {
if (ic2Available != null) return ic2Available;
boolean loaded = Loader.isModLoaded("IC2");
if (Loader.instance().hasReachedState(LoaderState.CONSTRUCTING)) {
ic2Available = loaded;
}
return loaded;
}
private static Boolean ic2Available = null;
}

View file

@ -60,6 +60,16 @@ public interface IReactor {
*/
public void setMaxHeat(int newMaxHeat);
/**
* add Heat to a EmitHeat Buffer
* for use in Reactor operation.. need to be use
* for all Componetents with self-cooling
* no more magic heat disappear
*/
public void addEmitHeat(int heat);
/**
* Get's the reactor's HEM (Heat Effect Modifier)
* Basic value is 1.0F.

View file

@ -20,9 +20,10 @@ public interface IReactorComponent
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @param heatrun every Stack will cycle 2 time (true,false) first run for heat, sec for Eu calculation
*/
public void processChamber(IReactor reactor, ItemStack yourStack, int x, int y);
public void processChamber(IReactor reactor, ItemStack yourStack, int x, int y,boolean heatrun);
/**
* Can be called by Uranium-Components who attempt to generate energy by pulsing to other components.
* Uranium-Uranium interaction (f.e.) uses this method.
@ -33,10 +34,11 @@ public interface IReactorComponent
* @param youY Y-coordinate of your stack in the grid
* @param pulseX X-coordinate of pulsing stack in the grid
* @param pulseY Y-coordinate of pulsing stack in the grid
* @param heatrun true for only create heat not EU, false for only EU not heat
* @return true if this component reacts to the pulse (and pulse is therefore meant to produce heat)
*/
public boolean acceptUraniumPulse(IReactor reactor, ItemStack yourStack, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY);
public boolean acceptUraniumPulse(IReactor reactor, ItemStack yourStack, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY,boolean heatrun);
/**
* Called by components to determine whether your component can be heated.
* @param reactor Reference to the Reactor
@ -46,7 +48,7 @@ public interface IReactorComponent
* @return true if your component can take heat
*/
public boolean canStoreHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the maximum capacity of your heat-containing component here.
@ -57,7 +59,7 @@ public interface IReactorComponent
* @return Maximum heat
*/
public int getMaxHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the current amount of heat stored in this component
@ -68,7 +70,7 @@ public interface IReactorComponent
* @return Current Heat
*/
public int getCurrentHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by components to distribute heat to your component.
* Perform heating-calculations and increase your heat (dmg) level accordingly.
@ -82,7 +84,7 @@ public interface IReactorComponent
* @return 0 if the 'order' was accepted, return >0 to indicate the 'remaining' heat which couldn't be absorbed (and vice versa for <0)
*/
public int alterHeat(IReactor reactor, ItemStack yourStack, int x, int y, int heat);
/**
* Called upon reactor explosion
* Alter the explosion size.

View file

@ -76,23 +76,30 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
for(TileEntity acceptor : getAcceptors())
{
ForgeDirection side = acceptorDirections.get(acceptor).getOpposite();
if(!ignored.contains(acceptor))
{
if(acceptor instanceof IStrictEnergyAcceptor)
{
totalNeeded += (((IStrictEnergyAcceptor)acceptor).getMaxEnergy() - ((IStrictEnergyAcceptor)acceptor).getEnergy());
}
else if(acceptor instanceof IEnergyHandler)
{
IEnergyHandler handler = (IEnergyHandler)acceptor;
totalNeeded += handler.receiveEnergy(side, handler.getMaxEnergyStored(side) - handler.getEnergyStored(side), true)*Mekanism.FROM_TE;
}
else if(acceptor instanceof IEnergySink)
{
totalNeeded += Math.min((((IEnergySink)acceptor).demandedEnergyUnits()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
}
else if(acceptor instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
{
totalNeeded += (((IPowerReceptor)acceptor).getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()).powerRequest()*Mekanism.FROM_BC);
totalNeeded += (((IPowerReceptor)acceptor).getPowerReceiver(side).powerRequest()*Mekanism.FROM_BC);
}
else if(acceptor instanceof IElectrical)
{
totalNeeded += ((IElectrical)acceptor).getRequest(acceptorDirections.get(acceptor).getOpposite())*Mekanism.FROM_UE;
totalNeeded += ((IElectrical)acceptor).getRequest(side)*Mekanism.FROM_UE;
}
}
}