Make PULL mode actually, and exclusively, pull.

This commit is contained in:
Ben Spiers 2014-11-11 12:25:10 +00:00
parent 5b4f154040
commit 92f1579bba

View file

@ -3,7 +3,9 @@ package mekanism.common.multipart;
import java.util.List;
import java.util.Set;
import mekanism.api.energy.ICableOutputter;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.MekanismClient;
@ -27,6 +29,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import codechicken.lib.vec.Vector3;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import ic2.api.energy.tile.IEnergySource;
@InterfaceList({
@ -43,6 +46,8 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
public double cacheEnergy = 0;
public double lastWrite = 0;
public double drawAmount = 100;
public PartUniversalCable(Tier.CableTier cableTier)
{
tier = cableTier;
@ -77,8 +82,6 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
cacheEnergy = 0;
}
if(MekanismUtils.useIC2())
{
List<ForgeDirection> sides = getConnections(ConnectionType.PULL);
if(!sides.isEmpty())
{
@ -88,23 +91,47 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
{
if(connectedOutputters[side.ordinal()] != null)
{
TileEntity acceptor = connectedOutputters[side.ordinal()];
TileEntity outputter = connectedOutputters[side.ordinal()];
if(acceptor instanceof IEnergySource)
if(outputter instanceof ICableOutputter && outputter instanceof IStrictEnergyStorage)
{
double received = ((IEnergySource) acceptor).getOfferedEnergy() * Mekanism.FROM_IC2;
if(((ICableOutputter)outputter).canOutputTo(side.getOpposite()))
{
double received = Math.min(((IStrictEnergyStorage)outputter).getEnergy(), drawAmount);
double toDraw = received;
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
}
((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw);
}
}
else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider)
{
double received = ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)drawAmount, true) * Mekanism.FROM_TE;
double toDraw = received;
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
}
((IEnergySource) acceptor).drawEnergy(toDraw * Mekanism.TO_IC2);
((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)toDraw, false);
}
else if(MekanismUtils.useIC2() && outputter instanceof IEnergySource)
{
double received = Math.min(((IEnergySource)outputter).getOfferedEnergy() * Mekanism.FROM_IC2, drawAmount);
double toDraw = received;
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
}
((IEnergySource)outputter).drawEnergy(toDraw * Mekanism.TO_IC2);
}
}
}
}
}
}
super.update();
@ -301,7 +328,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return getConnectionType(side) == ConnectionType.NORMAL || getConnectionType(side) == ConnectionType.PULL;
return getConnectionType(side) == ConnectionType.NORMAL;
}
@Override