Official Redstone Flux support complete!
(As far as I know at least)
This commit is contained in:
parent
ec98b19ffb
commit
3193f786cd
4 changed files with 179 additions and 31 deletions
|
@ -30,6 +30,7 @@ import universalelectricity.core.electricity.ElectricityPack;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||||
import buildcraft.api.power.PowerHandler.Type;
|
import buildcraft.api.power.PowerHandler.Type;
|
||||||
|
import cofh.api.energy.IEnergyHandler;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
|
@ -128,6 +129,12 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
{
|
{
|
||||||
energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending));
|
energyToSend -= (currentSending - ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(currentSending));
|
||||||
}
|
}
|
||||||
|
else if(acceptor instanceof IEnergyHandler)
|
||||||
|
{
|
||||||
|
IEnergyHandler handler = (IEnergyHandler)acceptor;
|
||||||
|
int used = handler.receiveEnergy(side.getOpposite(), (int)(currentSending*Mekanism.TO_TE), false);
|
||||||
|
energyToSend -= used*Mekanism.FROM_TE;
|
||||||
|
}
|
||||||
else if(acceptor instanceof IEnergySink)
|
else if(acceptor instanceof IEnergySink)
|
||||||
{
|
{
|
||||||
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||||
|
@ -170,9 +177,23 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
{
|
{
|
||||||
if(acceptor instanceof IStrictEnergyAcceptor)
|
if(acceptor instanceof IStrictEnergyAcceptor)
|
||||||
{
|
{
|
||||||
if(((IStrictEnergyAcceptor)acceptor).canReceiveEnergy(acceptorDirections.get(acceptor).getOpposite()))
|
IStrictEnergyAcceptor handler = (IStrictEnergyAcceptor)acceptor;
|
||||||
|
|
||||||
|
if(handler.canReceiveEnergy(acceptorDirections.get(acceptor).getOpposite()))
|
||||||
{
|
{
|
||||||
if((((IStrictEnergyAcceptor)acceptor).getMaxEnergy() - ((IStrictEnergyAcceptor)acceptor).getEnergy()) > 0)
|
if(handler.getMaxEnergy() - handler.getEnergy() > 0)
|
||||||
|
{
|
||||||
|
toReturn.add(acceptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(acceptor instanceof IEnergyHandler)
|
||||||
|
{
|
||||||
|
IEnergyHandler handler = (IEnergyHandler)acceptor;
|
||||||
|
|
||||||
|
if(handler.canInterface(acceptorDirections.get(acceptor).getOpposite()))
|
||||||
|
{
|
||||||
|
if(handler.getMaxEnergyStored(acceptorDirections.get(acceptor).getOpposite()) - handler.getEnergyStored(acceptorDirections.get(acceptor).getOpposite()) > 0)
|
||||||
{
|
{
|
||||||
toReturn.add(acceptor);
|
toReturn.add(acceptor);
|
||||||
}
|
}
|
||||||
|
@ -180,9 +201,23 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
}
|
}
|
||||||
else if(acceptor instanceof IEnergySink)
|
else if(acceptor instanceof IEnergySink)
|
||||||
{
|
{
|
||||||
if(((IEnergySink)acceptor).acceptsEnergyFrom(null, acceptorDirections.get(acceptor).getOpposite()))
|
IEnergySink handler = (IEnergySink)acceptor;
|
||||||
|
|
||||||
|
if(handler.acceptsEnergyFrom(null, acceptorDirections.get(acceptor).getOpposite()))
|
||||||
{
|
{
|
||||||
if(Math.min((((IEnergySink)acceptor).demandedEnergyUnits()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2)) > 0)
|
if(Math.min((handler.demandedEnergyUnits()*Mekanism.FROM_IC2), (handler.getMaxSafeInput()*Mekanism.FROM_IC2)) > 0)
|
||||||
|
{
|
||||||
|
toReturn.add(acceptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(acceptor instanceof IElectrical)
|
||||||
|
{
|
||||||
|
IElectrical handler = (IElectrical)acceptor;
|
||||||
|
|
||||||
|
if(handler.canConnect(acceptorDirections.get(acceptor).getOpposite()))
|
||||||
|
{
|
||||||
|
if(handler.getRequest(acceptorDirections.get(acceptor).getOpposite()) > 0)
|
||||||
{
|
{
|
||||||
toReturn.add(acceptor);
|
toReturn.add(acceptor);
|
||||||
}
|
}
|
||||||
|
@ -190,9 +225,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
}
|
}
|
||||||
else if(acceptor instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
|
else if(acceptor instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
|
||||||
{
|
{
|
||||||
if(((IPowerReceptor)acceptor).getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()) != null)
|
IPowerReceptor handler = (IPowerReceptor)acceptor;
|
||||||
|
|
||||||
|
if(handler.getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()) != null)
|
||||||
{
|
{
|
||||||
if((((IPowerReceptor)acceptor).getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()).powerRequest()*Mekanism.FROM_BC) > 0)
|
if((handler.getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()).powerRequest()*Mekanism.FROM_BC) > 0)
|
||||||
{
|
{
|
||||||
TileEntityUniversalCable cable = (TileEntityUniversalCable)Object3D.get(acceptor).getFromSide(acceptorDirections.get(acceptor).getOpposite()).getTileEntity(acceptor.worldObj);
|
TileEntityUniversalCable cable = (TileEntityUniversalCable)Object3D.get(acceptor).getFromSide(acceptorDirections.get(acceptor).getOpposite()).getTileEntity(acceptor.worldObj);
|
||||||
|
|
||||||
|
@ -203,16 +240,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(acceptor instanceof IElectrical)
|
|
||||||
{
|
|
||||||
if(((IElectrical)acceptor).canConnect(acceptorDirections.get(acceptor).getOpposite()))
|
|
||||||
{
|
|
||||||
if(((IElectrical)acceptor).getRequest(acceptorDirections.get(acceptor).getOpposite()) > 0)
|
|
||||||
{
|
|
||||||
toReturn.add(acceptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
|
@ -24,10 +24,11 @@ import universalelectricity.core.electricity.ElectricityPack;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerHandler;
|
import buildcraft.api.power.PowerHandler;
|
||||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||||
|
import cofh.api.energy.IEnergyHandler;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IWrenchable, ITileNetwork, IPowerReceptor, IEnergyTile, IElectrical, IElectricalStorage, IConnector, IStrictEnergyStorage
|
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IWrenchable, ITileNetwork, IPowerReceptor, IEnergyTile, IElectrical, IElectricalStorage, IConnector, IStrictEnergyStorage, IEnergyHandler
|
||||||
{
|
{
|
||||||
/** How much energy is stored in this block. */
|
/** How much energy is stored in this block. */
|
||||||
public double electricityStored;
|
public double electricityStored;
|
||||||
|
@ -278,4 +279,58 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||||
{
|
{
|
||||||
return (int)(getEnergy()*i / getMaxEnergy());
|
return (int)(getEnergy()*i / getMaxEnergy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||||
|
{
|
||||||
|
if(getConsumingSides().contains(from))
|
||||||
|
{
|
||||||
|
double toAdd = (int)Math.min(getMaxEnergy()-getEnergy(), maxReceive*Mekanism.FROM_TE);
|
||||||
|
|
||||||
|
if(!simulate)
|
||||||
|
{
|
||||||
|
setEnergy(getEnergy() + toAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)(toAdd*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||||
|
{
|
||||||
|
if(getOutputtingSide() == from)
|
||||||
|
{
|
||||||
|
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract*Mekanism.FROM_TE));
|
||||||
|
|
||||||
|
if(!simulate)
|
||||||
|
{
|
||||||
|
setEnergy(getEnergy() - toSend);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)(toSend*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInterface(ForgeDirection from)
|
||||||
|
{
|
||||||
|
return canConnect(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
|
return (int)(getEnergy()*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
|
return (int)(getMaxEnergy()*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
|
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
import mekanism.api.transmitters.TransmissionType;
|
||||||
|
@ -33,8 +31,11 @@ import buildcraft.api.power.IPowerEmitter;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerHandler;
|
import buildcraft.api.power.PowerHandler;
|
||||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||||
|
import cofh.api.energy.IEnergyHandler;
|
||||||
|
|
||||||
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IConductor, ITileNetwork
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IConductor, ITileNetwork, IEnergyHandler
|
||||||
{
|
{
|
||||||
/** A fake power handler used to initiate energy transfer calculations. */
|
/** A fake power handler used to initiate energy transfer calculations. */
|
||||||
public PowerHandler powerHandler;
|
public PowerHandler powerHandler;
|
||||||
|
@ -340,6 +341,54 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handlePacketData(ByteArrayDataInput dataStream) throws Exception {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList getNetworkedData(ArrayList data)
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||||
|
{
|
||||||
|
if(!simulate)
|
||||||
|
{
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
list.add(Object3D.get(this).getFromSide(from).getTileEntity(worldObj));
|
||||||
|
return (int)(getTransmitterNetwork().emit(maxReceive*Mekanism.FROM_TE, list)*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInterface(ForgeDirection from)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
list.add(Object3D.get(this).getFromSide(from).getTileEntity(worldObj));
|
||||||
|
return (int)(getTransmitterNetwork().getEnergyNeeded(list)*Mekanism.TO_TE);
|
||||||
|
}
|
||||||
|
|
||||||
public class FakeUENetwork implements IElectricityNetwork
|
public class FakeUENetwork implements IElectricityNetwork
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -396,13 +445,4 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handlePacketData(ByteArrayDataInput dataStream) throws Exception {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList getNetworkedData(ArrayList data)
|
|
||||||
{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -27,6 +27,7 @@ import universalelectricity.core.grid.IElectricityNetwork;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||||
import buildcraft.api.power.PowerHandler.Type;
|
import buildcraft.api.power.PowerHandler.Type;
|
||||||
|
import cofh.api.energy.IEnergyHandler;
|
||||||
|
|
||||||
public final class CableUtils
|
public final class CableUtils
|
||||||
{
|
{
|
||||||
|
@ -46,7 +47,7 @@ public final class CableUtils
|
||||||
if(acceptor instanceof IStrictEnergyAcceptor ||
|
if(acceptor instanceof IStrictEnergyAcceptor ||
|
||||||
acceptor instanceof IEnergySink ||
|
acceptor instanceof IEnergySink ||
|
||||||
(acceptor instanceof IPowerReceptor && !(acceptor instanceof ITransmitter) && MekanismUtils.useBuildcraft()) ||
|
(acceptor instanceof IPowerReceptor && !(acceptor instanceof ITransmitter) && MekanismUtils.useBuildcraft()) ||
|
||||||
acceptor instanceof IElectrical)
|
acceptor instanceof IElectrical || acceptor instanceof IEnergyHandler)
|
||||||
{
|
{
|
||||||
acceptors[orientation.ordinal()] = acceptor;
|
acceptors[orientation.ordinal()] = acceptor;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +139,8 @@ public final class CableUtils
|
||||||
|
|
||||||
if((outputter instanceof ICableOutputter && ((ICableOutputter)outputter).canOutputTo(orientation.getOpposite())) ||
|
if((outputter instanceof ICableOutputter && ((ICableOutputter)outputter).canOutputTo(orientation.getOpposite())) ||
|
||||||
(outputter instanceof IEnergySource && ((IEnergySource)outputter).emitsEnergyTo(tileEntity, orientation.getOpposite())) ||
|
(outputter instanceof IEnergySource && ((IEnergySource)outputter).emitsEnergyTo(tileEntity, orientation.getOpposite())) ||
|
||||||
(outputter instanceof IElectrical && ((IElectrical)outputter).canConnect(orientation.getOpposite())))
|
(outputter instanceof IElectrical && ((IElectrical)outputter).canConnect(orientation.getOpposite())) ||
|
||||||
|
(outputter instanceof IEnergyHandler && ((IEnergyHandler)outputter).canInterface(orientation.getOpposite())))
|
||||||
{
|
{
|
||||||
outputters[orientation.ordinal()] = outputter;
|
outputters[orientation.ordinal()] = outputter;
|
||||||
}
|
}
|
||||||
|
@ -177,6 +179,11 @@ public final class CableUtils
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tileEntity instanceof IEnergyHandler && ((IEnergyHandler)tileEntity).canInterface(side.getOpposite()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if(tileEntity instanceof IPowerReceptor && !(tileEntity instanceof ITransmitter) && MekanismUtils.useBuildcraft())
|
if(tileEntity instanceof IPowerReceptor && !(tileEntity instanceof ITransmitter) && MekanismUtils.useBuildcraft())
|
||||||
{
|
{
|
||||||
if(!(tileEntity instanceof IEnergyAcceptor) || ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(null, side.getOpposite()))
|
if(!(tileEntity instanceof IEnergyAcceptor) || ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(null, side.getOpposite()))
|
||||||
|
@ -281,6 +288,25 @@ public final class CableUtils
|
||||||
double toSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
|
double toSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
|
||||||
emitter.setEnergy(emitter.getEnergy() - (toSend - acceptor.transferEnergyToAcceptor(toSend)));
|
emitter.setEnergy(emitter.getEnergy() - (toSend - acceptor.transferEnergyToAcceptor(toSend)));
|
||||||
}
|
}
|
||||||
|
else if(tileEntity instanceof IEnergyHandler)
|
||||||
|
{
|
||||||
|
IEnergyHandler handler = (IEnergyHandler)tileEntity;
|
||||||
|
double toSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
|
||||||
|
int used = handler.receiveEnergy(emitter.getOutputtingSide().getOpposite(), (int)(toSend*Mekanism.TO_TE), false);
|
||||||
|
emitter.setEnergy(emitter.getEnergy() - used*Mekanism.FROM_TE);
|
||||||
|
}
|
||||||
|
else if(tileEntity instanceof IEnergySink)
|
||||||
|
{
|
||||||
|
double toSend = Math.min(emitter.getEnergy(), (((IEnergySink)tileEntity).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||||
|
double rejects = ((IEnergySink)tileEntity).injectEnergyUnits(emitter.getOutputtingSide().getOpposite(), toSend*Mekanism.TO_IC2)*Mekanism.FROM_IC2;
|
||||||
|
emitter.setEnergy(emitter.getEnergy() - (toSend - rejects));
|
||||||
|
}
|
||||||
|
else if(tileEntity instanceof IElectrical)
|
||||||
|
{
|
||||||
|
double toSend = Math.min(emitter.getEnergy(), ((IElectrical)tileEntity).getRequest(emitter.getOutputtingSide().getOpposite())*Mekanism.FROM_UE);
|
||||||
|
ElectricityPack pack = ElectricityPack.getFromWatts((float)(toSend*Mekanism.TO_UE), ((IElectrical)tileEntity).getVoltage());
|
||||||
|
emitter.setEnergy(emitter.getEnergy() - (((IElectrical)tileEntity).receiveElectricity(emitter.getOutputtingSide().getOpposite(), pack, true)*Mekanism.FROM_UE));
|
||||||
|
}
|
||||||
else if(tileEntity instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
|
else if(tileEntity instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
|
||||||
{
|
{
|
||||||
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(emitter.getOutputtingSide().getOpposite());
|
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(emitter.getOutputtingSide().getOpposite());
|
||||||
|
|
Loading…
Reference in a new issue