Implemented the other apis, now need to implement our own
This commit is contained in:
parent
c836e06678
commit
78faca7a19
2 changed files with 197 additions and 23 deletions
|
@ -41,6 +41,16 @@ public interface IEnergyInterfaceTile {
|
|||
*/
|
||||
public int addEnergy(int energy);
|
||||
|
||||
/**
|
||||
*
|
||||
* Will try add add the full amount of energy, if simulate is true it wont add the energy
|
||||
*
|
||||
* @param energy amount to add
|
||||
*
|
||||
* @return The amount of energy that was added.
|
||||
*/
|
||||
public int addEnergy(int energy, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns true if it can use the full amount of energy
|
||||
*
|
||||
|
@ -55,9 +65,19 @@ public interface IEnergyInterfaceTile {
|
|||
*
|
||||
* @param energy energy to use
|
||||
*
|
||||
* @return if the energy was used
|
||||
* @return the amount of energy used
|
||||
*/
|
||||
public boolean useEnergy(int energy);
|
||||
public int useEnergy(int energy);
|
||||
|
||||
|
||||
/**
|
||||
* Will try and use the full amount of energy, if simulate is true it wont add the energy
|
||||
*
|
||||
* @param energy energy to use
|
||||
*
|
||||
* @return the amount of energy used
|
||||
*/
|
||||
public int useEnergy(int energy, boolean simulate);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -1,51 +1,205 @@
|
|||
package techreborn.powerSystem;
|
||||
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
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 ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.info.Info;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import techreborn.api.power.IEnergyInterfaceTile;
|
||||
import techreborn.asm.Strippable;
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
|
||||
|
||||
@Optional.InterfaceList(value={
|
||||
@Optional.Interface(iface="ic2.api.energy.tile.IEnergyTile", modid="IC2", striprefs=true),
|
||||
@Optional.Interface(iface="ic2.api.energy.tile.IEnergySink", modid="IC2", striprefs=true)
|
||||
@Optional.InterfaceList(value = {
|
||||
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergyTile", modid = "IC2", striprefs = true),
|
||||
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2", striprefs = true),
|
||||
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "IC2", striprefs = true)
|
||||
})
|
||||
public abstract class TilePowerAcceptor extends TileMachineBase implements
|
||||
IEnergyReceiver, //Techreborn
|
||||
IEnergyInterfaceTile,//Cofh
|
||||
IEnergyTile, IEnergySink //Ic2
|
||||
IEnergyReceiver, IEnergyProvider, //Cofh
|
||||
IEnergyInterfaceTile,//TechReborn
|
||||
IEnergyTile, IEnergySink, IEnergySource //Ic2
|
||||
{
|
||||
public int tier;
|
||||
private int energy;
|
||||
public final TileEntity parent;
|
||||
|
||||
@Strippable("mod:ic2")
|
||||
BasicSink sink;
|
||||
public TilePowerAcceptor(int tier, TileEntity parent) {
|
||||
this.tier = tier;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Strippable("mod:ic2")
|
||||
//IC2
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
protected boolean addedToEnet;
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
sink.updateEntity();
|
||||
onLoaded();
|
||||
}
|
||||
|
||||
@Strippable("mod:ic2")
|
||||
@Strippable("mod:IC2")
|
||||
public void onLoaded() {
|
||||
if (PowerSystem.EUPOWENET && !addedToEnet &&
|
||||
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
|
||||
Info.isIc2Available()) {
|
||||
worldObj = parent.getWorldObj();
|
||||
xCoord = parent.xCoord;
|
||||
yCoord = parent.yCoord;
|
||||
zCoord = parent.zCoord;
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
|
||||
addedToEnet = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
sink.invalidate();
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
onChunkUnload();
|
||||
}
|
||||
|
||||
@Strippable("mod:ic2")
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
sink.onChunkUnload();
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
if (PowerSystem.EUPOWENET) {
|
||||
if (addedToEnet &&
|
||||
Info.isIc2Available()) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
|
||||
addedToEnet = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public double getDemandedEnergy() {
|
||||
if (!PowerSystem.EUPOWENET)
|
||||
return 0;
|
||||
return getMaxInput();
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
return tier;
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
|
||||
energy += amount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
|
||||
if (!PowerSystem.EUPOWENET)
|
||||
return false;
|
||||
return canAcceptEnergy(direction);
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
|
||||
if (!PowerSystem.EUPOWENET)
|
||||
return false;
|
||||
return canProvideEnergy(direction);
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public double getOfferedEnergy() {
|
||||
if (!PowerSystem.EUPOWENET)
|
||||
return 0;
|
||||
return getEnergy();
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public void drawEnergy(double amount) {
|
||||
useEnergy((int) amount);
|
||||
}
|
||||
|
||||
@Strippable("mod:IC2")
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
return tier;
|
||||
}
|
||||
//END IC2
|
||||
|
||||
//COFH
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
if (!PowerSystem.RFPOWENET)
|
||||
return false;
|
||||
return canAcceptEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if (!PowerSystem.RFPOWENET)
|
||||
return 0;
|
||||
if (!canAcceptEnergy(from)) {
|
||||
return 0;
|
||||
}
|
||||
return addEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
if (!PowerSystem.RFPOWENET)
|
||||
return 0;
|
||||
return getEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
if (!PowerSystem.RFPOWENET)
|
||||
return 0;
|
||||
return getMaxPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
if (!PowerSystem.RFPOWENET)
|
||||
return 0;
|
||||
if (!canAcceptEnergy(from)) {
|
||||
return 0;
|
||||
}
|
||||
return useEnergy(maxExtract, simulate);
|
||||
}
|
||||
//END COFH
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
NBTTagCompound data = tag.getCompoundTag("TilePowerAcceptor");
|
||||
energy = data.getInteger("energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("energy", energy);
|
||||
tag.setTag("TilePowerAcceptor", data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue