Better direct energy outputting

This commit is contained in:
Aidan Brady 2013-11-29 17:17:01 -05:00
parent 3d167922be
commit 2e86b2a471
9 changed files with 220 additions and 238 deletions

View file

@ -100,7 +100,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*/ */
public class BlockMachine extends BlockContainer implements ISpecialBounds public class BlockMachine extends BlockContainer implements ISpecialBounds
{ {
public Icon[][][] icons = new Icon[4096][16][16]; public Icon[][] icons = new Icon[16][16];
public Random machineRand = new Random(); public Random machineRand = new Random();
public BlockMachine(int id) public BlockMachine(int id)
@ -117,34 +117,34 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{ {
if(blockID == Mekanism.machineBlockID) if(blockID == Mekanism.machineBlockID)
{ {
icons[blockID][0][0] = register.registerIcon("mekanism:EnrichmentChamberFrontOff"); icons[0][0] = register.registerIcon("mekanism:EnrichmentChamberFrontOff");
icons[blockID][0][1] = register.registerIcon("mekanism:EnrichmentChamberFrontOn"); icons[0][1] = register.registerIcon("mekanism:EnrichmentChamberFrontOn");
icons[blockID][0][2] = register.registerIcon("mekanism:SteelCasing"); icons[0][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][1][0] = register.registerIcon("mekanism:OsmiumCompressorFrontOff"); icons[1][0] = register.registerIcon("mekanism:OsmiumCompressorFrontOff");
icons[blockID][1][1] = register.registerIcon("mekanism:OsmiumCompressorFrontOn"); icons[1][1] = register.registerIcon("mekanism:OsmiumCompressorFrontOn");
icons[blockID][1][2] = register.registerIcon("mekanism:SteelCasing"); icons[1][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][2][0] = register.registerIcon("mekanism:CombinerFrontOff"); icons[2][0] = register.registerIcon("mekanism:CombinerFrontOff");
icons[blockID][2][1] = register.registerIcon("mekanism:CombinerFrontOn"); icons[2][1] = register.registerIcon("mekanism:CombinerFrontOn");
icons[blockID][2][2] = register.registerIcon("mekanism:SteelCasing"); icons[2][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][3][0] = register.registerIcon("mekanism:CrusherFrontOff"); icons[3][0] = register.registerIcon("mekanism:CrusherFrontOff");
icons[blockID][3][1] = register.registerIcon("mekanism:CrusherFrontOn"); icons[3][1] = register.registerIcon("mekanism:CrusherFrontOn");
icons[blockID][3][2] = register.registerIcon("mekanism:SteelCasing"); icons[3][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][5][0] = register.registerIcon("mekanism:BasicFactoryFront"); icons[5][0] = register.registerIcon("mekanism:BasicFactoryFront");
icons[blockID][5][1] = register.registerIcon("mekanism:BasicFactorySide"); icons[5][1] = register.registerIcon("mekanism:BasicFactorySide");
icons[blockID][5][2] = register.registerIcon("mekanism:BasicFactoryTop"); icons[5][2] = register.registerIcon("mekanism:BasicFactoryTop");
icons[blockID][6][0] = register.registerIcon("mekanism:AdvancedFactoryFront"); icons[6][0] = register.registerIcon("mekanism:AdvancedFactoryFront");
icons[blockID][6][1] = register.registerIcon("mekanism:AdvancedFactorySide"); icons[6][1] = register.registerIcon("mekanism:AdvancedFactorySide");
icons[blockID][6][2] = register.registerIcon("mekanism:AdvancedFactoryTop"); icons[6][2] = register.registerIcon("mekanism:AdvancedFactoryTop");
icons[blockID][7][0] = register.registerIcon("mekanism:EliteFactoryFront"); icons[7][0] = register.registerIcon("mekanism:EliteFactoryFront");
icons[blockID][7][1] = register.registerIcon("mekanism:EliteFactorySide"); icons[7][1] = register.registerIcon("mekanism:EliteFactorySide");
icons[blockID][7][2] = register.registerIcon("mekanism:EliteFactoryTop"); icons[7][2] = register.registerIcon("mekanism:EliteFactoryTop");
icons[blockID][9][0] = register.registerIcon("mekanism:PurificationChamberFrontOff"); icons[9][0] = register.registerIcon("mekanism:PurificationChamberFrontOff");
icons[blockID][9][1] = register.registerIcon("mekanism:PurificationChamberFrontOn"); icons[9][1] = register.registerIcon("mekanism:PurificationChamberFrontOn");
icons[blockID][9][2] = register.registerIcon("mekanism:SteelCasing"); icons[9][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][10][0] = register.registerIcon("mekanism:EnergizedSmelterFrontOff"); icons[10][0] = register.registerIcon("mekanism:EnergizedSmelterFrontOff");
icons[blockID][10][1] = register.registerIcon("mekanism:EnergizedSmelterFrontOn"); icons[10][1] = register.registerIcon("mekanism:EnergizedSmelterFrontOn");
icons[blockID][10][2] = register.registerIcon("mekanism:SteelCasing"); icons[10][2] = register.registerIcon("mekanism:SteelCasing");
icons[blockID][11][0] = register.registerIcon("mekanism:Teleporter"); icons[11][0] = register.registerIcon("mekanism:Teleporter");
} }
} }
@ -289,107 +289,107 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][0][0]; return icons[0][0];
} }
else { else {
return icons[blockID][0][2]; return icons[0][2];
} }
} }
else if(meta == 1) else if(meta == 1)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][1][0]; return icons[1][0];
} }
else { else {
return icons[blockID][1][2]; return icons[1][2];
} }
} }
else if(meta == 2) else if(meta == 2)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][2][0]; return icons[2][0];
} }
else { else {
return icons[blockID][2][2]; return icons[2][2];
} }
} }
else if(meta == 3) else if(meta == 3)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][3][0]; return icons[3][0];
} }
else { else {
return icons[blockID][3][2]; return icons[3][2];
} }
} }
else if(meta == 5) else if(meta == 5)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][5][0]; return icons[5][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][5][2]; return icons[5][2];
} }
else { else {
return icons[blockID][5][1]; return icons[5][1];
} }
} }
else if(meta == 6) else if(meta == 6)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][6][0]; return icons[6][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][6][2]; return icons[6][2];
} }
else { else {
return icons[blockID][6][1]; return icons[6][1];
} }
} }
else if(meta == 7) else if(meta == 7)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][7][0]; return icons[7][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][7][2]; return icons[7][2];
} }
else { else {
return icons[blockID][7][1]; return icons[7][1];
} }
} }
else if(meta == 9) else if(meta == 9)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][9][0]; return icons[9][0];
} }
else { else {
return icons[blockID][9][2]; return icons[9][2];
} }
} }
else if(meta == 10) else if(meta == 10)
{ {
if(side == 3) if(side == 3)
{ {
return icons[blockID][10][0]; return icons[10][0];
} }
else { else {
return icons[blockID][10][2]; return icons[10][2];
} }
} }
else if(meta == 11) else if(meta == 11)
{ {
return icons[blockID][11][0]; return icons[11][0];
} }
} }
@ -409,107 +409,107 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][0][1] : icons[blockID][0][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[0][1] : icons[0][0];
} }
else { else {
return icons[blockID][0][2]; return icons[0][2];
} }
} }
else if(metadata == 1) else if(metadata == 1)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][1][1] : icons[blockID][1][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[1][1] : icons[1][0];
} }
else { else {
return icons[blockID][1][2]; return icons[1][2];
} }
} }
else if(metadata == 2) else if(metadata == 2)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][2][1] : icons[blockID][2][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[2][1] : icons[2][0];
} }
else { else {
return icons[blockID][2][2]; return icons[2][2];
} }
} }
else if(metadata == 3) else if(metadata == 3)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][3][1] : icons[blockID][3][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[3][1] : icons[3][0];
} }
else { else {
return icons[blockID][3][2]; return icons[3][2];
} }
} }
else if(metadata == 5) else if(metadata == 5)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return icons[blockID][5][0]; return icons[5][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][5][2]; return icons[5][2];
} }
else { else {
return icons[blockID][5][1]; return icons[5][1];
} }
} }
else if(metadata == 6) else if(metadata == 6)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return icons[blockID][6][0]; return icons[6][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][6][2]; return icons[6][2];
} }
else { else {
return icons[blockID][6][1]; return icons[6][1];
} }
} }
else if(metadata == 7) else if(metadata == 7)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return icons[blockID][7][0]; return icons[7][0];
} }
else if(side == 0 || side == 1) else if(side == 0 || side == 1)
{ {
return icons[blockID][7][2]; return icons[7][2];
} }
else { else {
return icons[blockID][7][1]; return icons[7][1];
} }
} }
else if(metadata == 9) else if(metadata == 9)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][9][1] : icons[blockID][9][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[9][1] : icons[9][0];
} }
else { else {
return icons[blockID][9][2]; return icons[9][2];
} }
} }
else if(metadata == 10) else if(metadata == 10)
{ {
if(side == tileEntity.facing) if(side == tileEntity.facing)
{ {
return MekanismUtils.isActive(world, x, y, z) ? icons[blockID][10][1] : icons[blockID][10][0]; return MekanismUtils.isActive(world, x, y, z) ? icons[10][1] : icons[10][0];
} }
else { else {
return icons[blockID][10][2]; return icons[10][2];
} }
} }
else if(metadata == 11) else if(metadata == 11)
{ {
return icons[blockID][11][0]; return icons[11][0];
} }
} }

View file

@ -77,7 +77,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
reconfigure(); reconfigure();
} }
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return null; return null;
} }
@ -95,7 +95,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public boolean canConnect(ForgeDirection direction) public boolean canConnect(ForgeDirection direction)
{ {
return getConsumingSides().contains(direction) || getOutputtingSide() == direction; return getConsumingSides().contains(direction) || getOutputtingSides().contains(direction);
} }
@Override @Override
@ -224,7 +224,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{ {
if(getOutputtingSide() == from) if(getOutputtingSides().contains(from))
{ {
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), request.getWatts()*Mekanism.FROM_UE)); double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), request.getWatts()*Mekanism.FROM_UE));
@ -253,7 +253,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public float getProvide(ForgeDirection direction) public float getProvide(ForgeDirection direction)
{ {
return getOutputtingSide() == direction ? Math.min(getEnergyStored(), (float)(getMaxOutput()*Mekanism.TO_UE)) : 0; return getOutputtingSides().contains(direction) ? Math.min(getEnergyStored(), (float)(getMaxOutput()*Mekanism.TO_UE)) : 0;
} }
@Override @Override
@ -305,7 +305,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
{ {
if(getOutputtingSide() == from) if(getOutputtingSides().contains(from))
{ {
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract*Mekanism.FROM_TE)); double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract*Mekanism.FROM_TE));
@ -360,19 +360,19 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public boolean isTeleporterCompatible(ForgeDirection side) public boolean isTeleporterCompatible(ForgeDirection side)
{ {
return side == getOutputtingSide(); return getOutputtingSides().contains(side);
} }
@Override @Override
public boolean canOutputTo(ForgeDirection side) public boolean canOutputTo(ForgeDirection side)
{ {
return side == getOutputtingSide(); return getOutputtingSides().contains(side);
} }
@Override @Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{ {
return direction != getOutputtingSide(); return !getOutputtingSides().contains(direction);
} }
@Override @Override
@ -402,7 +402,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Override @Override
public boolean canReceiveEnergy(ForgeDirection side) public boolean canReceiveEnergy(ForgeDirection side)
{ {
return side != getOutputtingSide(); return !getOutputtingSides().contains(side);
} }
@Override @Override

View file

@ -91,15 +91,15 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IPo
protected EnumSet<ForgeDirection> getConsumingSides() protected EnumSet<ForgeDirection> getConsumingSides()
{ {
EnumSet set = EnumSet.allOf(ForgeDirection.class); EnumSet set = EnumSet.allOf(ForgeDirection.class);
set.remove(getOutputtingSide()); set.remove(getOutputtingSides());
return set; return set;
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.getOrientation(facing); return EnumSet.of(ForgeDirection.getOrientation(facing));
} }
@Override @Override

View file

@ -6,8 +6,8 @@ import ic2.api.energy.tile.IEnergySource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set; import java.util.List;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import mekanism.api.energy.ICableOutputter; import mekanism.api.energy.ICableOutputter;
@ -17,7 +17,6 @@ import mekanism.api.transmitters.TransmissionType;
import mekanism.common.EnergyNetwork; import mekanism.common.EnergyNetwork;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityElectricBlock;
import mekanism.induction.common.tileentity.TileEntityTesla;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor; import universalelectricity.core.block.IConductor;
@ -225,78 +224,130 @@ public final class CableUtils
public static void emit(TileEntityElectricBlock emitter) public static void emit(TileEntityElectricBlock emitter)
{ {
if(!emitter.worldObj.isRemote && MekanismUtils.canFunction(emitter)) if(!emitter.worldObj.isRemote && MekanismUtils.canFunction(emitter))
{ {
TileEntity tileEntity = Object3D.get(emitter).getFromSide(emitter.getOutputtingSide()).getTileEntity(emitter.worldObj); double sendingEnergy = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
if(emitter.getEnergy() > 0) if(sendingEnergy > 0)
{ {
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY)) List<ForgeDirection> outputtingSides = new ArrayList<ForgeDirection>();
{ boolean[] connectable = getConnections(emitter);
double energyToSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
emitter.setEnergy(emitter.getEnergy() - (energyToSend - emitEnergyToNetwork(energyToSend, emitter, emitter.getOutputtingSide()))); for(ForgeDirection side : emitter.getOutputtingSides())
return; {
} if(connectable[side.ordinal()])
else if(tileEntity instanceof IStrictEnergyAcceptor) {
{ outputtingSides.add(side);
IStrictEnergyAcceptor acceptor = (IStrictEnergyAcceptor)tileEntity; }
double toSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput()); }
emitter.setEnergy(emitter.getEnergy() - (toSend - acceptor.transferEnergyToAcceptor(emitter.getOutputtingSide().getOpposite(), toSend)));
} if(outputtingSides.size() > 0)
else if(tileEntity instanceof IEnergyHandler) {
{ double totalToSend = sendingEnergy;
IEnergyHandler handler = (IEnergyHandler)tileEntity;
double toSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput()); boolean cont = false;
int used = handler.receiveEnergy(emitter.getOutputtingSide().getOpposite(), (int)Math.round(toSend*Mekanism.TO_TE), false);
emitter.setEnergy(emitter.getEnergy() - used*Mekanism.FROM_TE); do {
} cont = false;
else if(tileEntity instanceof IEnergySink) double prev = totalToSend;
{ totalToSend -= (totalToSend - emit_do(emitter, outputtingSides, totalToSend));
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; if(prev-totalToSend > 0 && totalToSend > 0)
emitter.setEnergy(emitter.getEnergy() - (toSend - rejects)); {
} cont = true;
else if(tileEntity instanceof IElectrical) }
{ } while(cont);
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() - (sendingEnergy - totalToSend));
emitter.setEnergy(emitter.getEnergy() - (((IElectrical)tileEntity).receiveElectricity(emitter.getOutputtingSide().getOpposite(), pack, true)*Mekanism.FROM_UE)); }
}
else if(tileEntity instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
{
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(emitter.getOutputtingSide().getOpposite());
if(receiver != null)
{
double transferEnergy = Math.min(emitter.getEnergy(), Math.min(receiver.powerRequest()*Mekanism.FROM_BC, emitter.getMaxOutput()));
float sent = receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), emitter.getOutputtingSide().getOpposite());
emitter.setEnergy(emitter.getEnergy() - sent);
}
}
} }
}
if(tileEntity instanceof IConductor) }
{
ForgeDirection outputDirection = emitter.getOutputtingSide(); private static double emit_do(TileEntityElectricBlock emitter, List<ForgeDirection> outputtingSides, double totalToSend)
float provide = emitter.getProvide(outputDirection); {
double remains = totalToSend%outputtingSides.size();
if(provide > 0) double splitSend = (totalToSend-remains)/outputtingSides.size();
{
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection);
if(outputNetwork != null) for(ForgeDirection side : outputtingSides)
{
TileEntity tileEntity = Object3D.get(emitter).getFromSide(side).getTileEntity(emitter.worldObj);
double toSend = splitSend+remains;
remains = 0;
totalToSend -= (toSend - emit_do_do(emitter, tileEntity, side, toSend));
}
return totalToSend;
}
/**
* @return rejects
*/
private static double emit_do_do(TileEntityElectricBlock from, TileEntity tileEntity, ForgeDirection side, double sendingEnergy)
{
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY))
{
sendingEnergy -= (sendingEnergy - emitEnergyToNetwork(sendingEnergy, from, side));
}
else if(tileEntity instanceof IStrictEnergyAcceptor)
{
IStrictEnergyAcceptor acceptor = (IStrictEnergyAcceptor)tileEntity;
sendingEnergy -= (sendingEnergy - acceptor.transferEnergyToAcceptor(side.getOpposite(), sendingEnergy));
}
else if(tileEntity instanceof IEnergyHandler)
{
IEnergyHandler handler = (IEnergyHandler)tileEntity;
int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(sendingEnergy*Mekanism.TO_TE), false);
sendingEnergy -= used*Mekanism.FROM_TE;
}
else if(tileEntity instanceof IEnergySink)
{
double toSend = Math.min(sendingEnergy, Math.min(((IEnergySink)tileEntity).getMaxSafeInput(), ((IEnergySink)tileEntity).demandedEnergyUnits())*Mekanism.FROM_IC2);
double rejects = ((IEnergySink)tileEntity).injectEnergyUnits(side.getOpposite(), toSend*Mekanism.TO_IC2)*Mekanism.FROM_IC2;
sendingEnergy -= (toSend - rejects);
}
else if(tileEntity instanceof IElectrical)
{
double toSend = Math.min(sendingEnergy, ((IElectrical)tileEntity).getRequest(side.getOpposite())*Mekanism.FROM_UE);
ElectricityPack pack = ElectricityPack.getFromWatts((float)(toSend*Mekanism.TO_UE), ((IElectrical)tileEntity).getVoltage());
sendingEnergy -= (((IElectrical)tileEntity).receiveElectricity(side.getOpposite(), pack, true)*Mekanism.FROM_UE);
}
else if(tileEntity instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
{
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(side.getOpposite());
if(receiver != null)
{
double transferEnergy = Math.min(sendingEnergy, receiver.powerRequest()*Mekanism.FROM_BC);
float sent = receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), side.getOpposite());
sendingEnergy -= sent;
}
}
else if(tileEntity instanceof IConductor)
{
ForgeDirection outputDirection = side;
float provide = from.getProvide(outputDirection);
if(provide > 0)
{
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection);
if(outputNetwork != null)
{
ElectricityPack request = outputNetwork.getRequest(from);
if(request.getWatts() > 0)
{ {
ElectricityPack request = outputNetwork.getRequest(emitter); float ueSend = (float)(sendingEnergy*Mekanism.TO_UE);
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(ueSend, from.getVoltage()), ElectricityPack.getFromWatts(provide, from.getVoltage()));
if(request.getWatts() > 0) float rejectedPower = outputNetwork.produce(sendPack, from);
{ sendingEnergy -= (sendPack.getWatts() - rejectedPower)*Mekanism.FROM_UE;
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(emitter.getEnergyStored(), emitter.getVoltage()), ElectricityPack.getFromWatts(provide, emitter.getVoltage()));
float rejectedPower = outputNetwork.produce(sendPack, emitter);
emitter.setEnergyStored(emitter.getEnergyStored() - (sendPack.getWatts() - rejectedPower));
}
} }
} }
} }
} }
return sendingEnergy;
} }
} }

View file

@ -1,10 +1,12 @@
package mekanism.generators.common.tileentity; package mekanism.generators.common.tileentity;
import net.minecraftforge.common.ForgeDirection; import java.util.EnumSet;
import mekanism.api.Object3D; import mekanism.api.Object3D;
import mekanism.common.IBoundingBlock; import mekanism.common.IBoundingBlock;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.MekanismGenerators;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator implements IBoundingBlock public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator implements IBoundingBlock
{ {
@ -14,9 +16,9 @@ public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator i
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.getOrientation(facing); return EnumSet.of(ForgeDirection.getOrientation(facing));
} }
@Override @Override

View file

@ -1,13 +1,13 @@
package mekanism.generators.common.tileentity; package mekanism.generators.common.tileentity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import mekanism.client.sound.Sound; import mekanism.client.sound.Sound;
import mekanism.common.FluidSlot; import mekanism.common.FluidSlot;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.MekanismGenerators;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -220,9 +220,9 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.getOrientation(facing).getOpposite(); return EnumSet.of(ForgeDirection.getOrientation(facing).getOpposite());
} }
@Override @Override

View file

@ -33,7 +33,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess; import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral; import dan200.computer.api.IPeripheral;
public abstract class TileEntityGenerator extends TileEntityElectricBlock implements IEnergySource, IEnergyStorage, IPowerReceptor, IPeripheral, IActiveState, IHasSound, ICableOutputter, IRedstoneControl, IPowerEmitter public abstract class TileEntityGenerator extends TileEntityElectricBlock implements IPowerReceptor, IPeripheral, IActiveState, IHasSound, IRedstoneControl, IPowerEmitter
{ {
/** Output per tick this generator can transfer. */ /** Output per tick this generator can transfer. */
public double output; public double output;
@ -121,15 +121,9 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.getOrientation(facing); return EnumSet.of(ForgeDirection.getOrientation(facing));
}
@Override
public float getRequest(ForgeDirection direction)
{
return 0;
} }
@Override @Override
@ -187,72 +181,12 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
@Override @Override
public void detach(IComputerAccess computer) {} public void detach(IComputerAccess computer) {}
@Override
public double getOutputEnergyUnitsPerTick()
{
return output*Mekanism.TO_IC2;
}
@Override @Override
public boolean canSetFacing(int side) public boolean canSetFacing(int side)
{ {
return side != 0 && side != 1; return side != 0 && side != 1;
} }
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
{
return direction == getOutputtingSide() && !(receiver instanceof TileEntityUniversalCable);
}
@Override
public int getStored()
{
return (int)(getEnergy()*Mekanism.TO_IC2);
}
@Override
public int getCapacity()
{
return (int)(getMaxEnergy()*Mekanism.TO_IC2);
}
@Override
public int getOutput()
{
return (int)(output*Mekanism.TO_IC2);
}
@Override
public boolean isTeleporterCompatible(ForgeDirection side)
{
return getOutputtingSide() == side;
}
@Override
public int addEnergy(int amount)
{
return (int)(getEnergy()*Mekanism.TO_IC2);
}
@Override
public void setStored(int energy)
{
setEnergy(energy*Mekanism.FROM_IC2);
}
@Override
public double getOfferedEnergy()
{
return Math.min(getEnergy()*Mekanism.TO_IC2, getOutput());
}
@Override
public void drawEnergy(double amount)
{
setEnergy(getEnergy()-amount*Mekanism.FROM_IC2);
}
@Override @Override
public void handlePacketData(ByteArrayDataInput dataStream) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
@ -305,12 +239,6 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
return INFINITE_EXTENT_AABB; return INFINITE_EXTENT_AABB;
} }
@Override
public boolean canOutputTo(ForgeDirection side)
{
return getOutputtingSide() == side;
}
@Override @Override
public String getSoundPath() public String getSoundPath()
{ {
@ -351,7 +279,7 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
@Override @Override
public boolean canEmitPowerFrom(ForgeDirection side) public boolean canEmitPowerFrom(ForgeDirection side)
{ {
return getOutputtingSide() == side; return getOutputtingSides().contains(side);
} }
@Override @Override

View file

@ -178,9 +178,9 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.getOrientation(0); return EnumSet.of(ForgeDirection.getOrientation(0));
} }
@Override @Override

View file

@ -3,6 +3,7 @@ package mekanism.induction.common.tileentity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -590,8 +591,8 @@ public class TileEntityTesla extends TileEntityElectricBlock implements ITesla
} }
@Override @Override
public ForgeDirection getOutputtingSide() public EnumSet<ForgeDirection> getOutputtingSides()
{ {
return ForgeDirection.DOWN; return EnumSet.of(ForgeDirection.DOWN);
} }
} }