A few ejector fixes

This commit is contained in:
aidancbrady 2016-01-28 23:45:22 -07:00
parent a22b33a629
commit 06dc2227f2
5 changed files with 51 additions and 43 deletions

View file

@ -2,13 +2,13 @@ package mekanism.api.gas;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -20,16 +20,11 @@ import net.minecraftforge.common.util.ForgeDirection;
*/
public final class GasTransmission
{
/**
* Gets all the acceptors around a tile entity.
* @param tileEntity - center tile entity
* @return array of IGasAcceptors
*/
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity)
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity, Collection<ForgeDirection> sides)
{
IGasHandler[] acceptors = new IGasHandler[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
for(ForgeDirection orientation : sides)
{
TileEntity acceptor = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
@ -41,6 +36,16 @@ public final class GasTransmission
return acceptors;
}
/**
* Gets all the acceptors around a tile entity.
* @param tileEntity - center tile entity
* @return array of IGasAcceptors
*/
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity)
{
return getConnectedAcceptors(tileEntity, Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
}
/**
* Gets all the tube connections around a tile entity.
@ -125,12 +130,12 @@ public final class GasTransmission
/**
* Emits gas from a central block by splitting the received stack among the sides given.
* @param sides - the list of sides to output from
* @param stack - the stack to output
* @param from - the TileEntity to output from
* @param sides - the list of sides to output from
* @return the amount of gas emitted
*/
public static int emit(List<ForgeDirection> sides, GasStack stack, TileEntity from)
public static int emit(GasStack stack, TileEntity from, Collection<ForgeDirection> sides)
{
if(stack == null)
{
@ -138,7 +143,7 @@ public final class GasTransmission
}
List<IGasHandler> availableAcceptors = new ArrayList<IGasHandler>();
IGasHandler[] possibleAcceptors = getConnectedAcceptors(from);
IGasHandler[] possibleAcceptors = getConnectedAcceptors(from, sides);
for(int i = 0; i < possibleAcceptors.length; i++)
{

View file

@ -79,7 +79,7 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo
ChargeUtils.charge(0, this);
ChargeUtils.discharge(1, this);
if(MekanismUtils.canFunction(this))
if(MekanismUtils.canFunction(this) && configComponent.isEjecting(TransmissionType.ENERGY))
{
CableUtils.emit(this);
}

View file

@ -84,41 +84,45 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
@Override
public void onUpdate()
{
if(inventory[0] != null && gasTank.getGas() != null)
{
gasTank.draw(GasTransmission.addGas(inventory[0], gasTank.getGas()), true);
}
if(inventory[1] != null && (gasTank.getGas() == null || gasTank.getGas().amount < gasTank.getMaxGas()))
{
gasTank.receive(GasTransmission.removeGas(inventory[1], gasTank.getGasType(), gasTank.getNeeded()), true);
}
if(!worldObj.isRemote && gasTank.getGas() != null && MekanismUtils.canFunction(this) && dumping != GasMode.DUMPING)
{
GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getStored(), output));
gasTank.draw(GasTransmission.emit(new ArrayList(configComponent.getSidesForData(TransmissionType.GAS, facing, 2).clone()), toSend, this), true);
}
if(!worldObj.isRemote && dumping == GasMode.DUMPING)
{
gasTank.draw(8, true);
}
if(!worldObj.isRemote && dumping == GasMode.DUMPING_EXCESS && gasTank.getNeeded() < output)
{
gasTank.draw(output-gasTank.getNeeded(), true);
}
if(!worldObj.isRemote)
{
if(inventory[0] != null && gasTank.getGas() != null)
{
gasTank.draw(GasTransmission.addGas(inventory[0], gasTank.getGas()), true);
}
if(inventory[1] != null && (gasTank.getGas() == null || gasTank.getGas().amount < gasTank.getMaxGas()))
{
gasTank.receive(GasTransmission.removeGas(inventory[1], gasTank.getGasType(), gasTank.getNeeded()), true);
}
if(gasTank.getGas() != null && MekanismUtils.canFunction(this) && dumping != GasMode.DUMPING)
{
if(configComponent.isEjecting(TransmissionType.GAS))
{
GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getStored(), output));
gasTank.draw(GasTransmission.emit(toSend, this, configComponent.getSidesForData(TransmissionType.GAS, facing, 2)), true);
}
}
if(dumping == GasMode.DUMPING)
{
gasTank.draw(8, true);
}
if(dumping == GasMode.DUMPING_EXCESS && gasTank.getNeeded() < output)
{
gasTank.draw(output-gasTank.getNeeded(), true);
}
int newGasAmount = gasTank.getStored();
if(newGasAmount != currentGasAmount)
{
markDirty();
currentGasAmount = newGasAmount;
MekanismUtils.saveChunk(this);
}
currentGasAmount = newGasAmount;
}
}

View file

@ -115,6 +115,7 @@ public class TileEntityPortableTank extends TileEntityContainerBlock implements
if(fluidTank.getFluidAmount() != prevAmount)
{
MekanismUtils.saveChunk(this);
needsPacket = true;
}

View file

@ -15,7 +15,6 @@ import mekanism.api.gas.GasTransmission;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.SideData;
import mekanism.common.base.IEjector;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.base.ITankManager;
import mekanism.common.base.ITileComponent;
@ -121,7 +120,7 @@ public class TileComponentEjector implements ITileComponent, IEjector
if(tank.getStored() > 0)
{
GasStack toEmit = tank.getGas().copy().withAmount(Math.min(GAS_OUTPUT, tank.getStored()));
int emit = GasTransmission.emit(outputSides, toEmit, tileEntity);
int emit = GasTransmission.emit(toEmit, tileEntity, outputSides);
tank.draw(emit, true);
}
}
@ -146,7 +145,6 @@ public class TileComponentEjector implements ITileComponent, IEjector
public List<ForgeDirection> getOutputSides(TransmissionType type, SideData data)
{
List<ForgeDirection> outputSides = new ArrayList<ForgeDirection>();
ISideConfiguration configurable = (ISideConfiguration)tileEntity;
for(int i = 0; i < configurable.getConfig().getConfig(type).length; i++)