mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-23 21:39:40 +00:00
Fancy new eject algorithms, should fix issues with PRC
This commit is contained in:
1 parent
b4c2664c5e
commit
e4d624d8ab
11 files changed
+197
-38
No files matched your search
@@ -1,8 +1,12 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -138,4 +142,60 @@ public final class GasTransmission
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(List<ForgeDirection> sides, GasStack stack, TileEntity from)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IGasHandler> availableAcceptors = new ArrayList<IGasHandler>();
|
||||
IGasHandler[] possibleAcceptors = getConnectedAcceptors(from);
|
||||
|
||||
for(int i = 0; i < possibleAcceptors.length; i++)
|
||||
{
|
||||
IGasHandler handler = possibleAcceptors[i];
|
||||
|
||||
if(handler != null && handler.canReceiveGas(ForgeDirection.getOrientation(i).getOpposite(), stack.getGas()))
|
||||
{
|
||||
availableAcceptors.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend-remaining)/divider;
|
||||
|
||||
for(IGasHandler acceptor : availableAcceptors)
|
||||
{
|
||||
int currentSending = sending;
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.receiveGas(dir, new GasStack(stack.getGas(), currentSending), true);
|
||||
}
|
||||
}
|
||||
|
||||
return prevSending-toSend;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IEjector
|
||||
{
|
||||
public void onOutput();
|
||||
public void outputItems();
|
||||
|
||||
public EnumColor getOutputColor();
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
|
||||
recipe.operate(inventory, 0, 2, gasTank, secondaryEnergyThisTick);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -120,7 +120,7 @@ public abstract class TileEntityChanceMachine<RECIPE extends ChanceMachineRecipe
|
||||
recipe.operate(inventory);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -203,7 +203,7 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
|
||||
recipe.operate(inputTank, inventory);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -206,7 +206,7 @@ public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecip
|
||||
recipe.operate(inventory, 0, 2);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -645,7 +645,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
|
||||
}
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -274,7 +274,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i
|
||||
recipe.output(inventory, infuseStored);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
public boolean canOperate(MetallurgicInfuserRecipe recipe)
|
||||
|
||||
@@ -83,6 +83,7 @@ public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, Pres
|
||||
upgradeComponent = new TileComponentUpgrade(this, 3);
|
||||
ejectorComponent = new TileComponentEjector(this);
|
||||
ejectorComponent.setOutputData(TransmissionType.ITEM, configComponent.getOutputs(TransmissionType.ITEM).get(3));
|
||||
ejectorComponent.setOutputData(TransmissionType.GAS, configComponent.getOutputs(TransmissionType.GAS).get(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,21 +138,6 @@ public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, Pres
|
||||
}
|
||||
|
||||
prevEnergy = getEnergy();
|
||||
|
||||
if(outputGasTank.getGas() != null && configComponent.isEjecting(TransmissionType.GAS))
|
||||
{
|
||||
GasStack toSend = new GasStack(outputGasTank.getGas().getGas(), Math.min(outputGasTank.getStored(), 16));
|
||||
|
||||
TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);
|
||||
|
||||
if(tileEntity instanceof IGasHandler)
|
||||
{
|
||||
if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing), outputGasTank.getGas().getGas()))
|
||||
{
|
||||
outputGasTank.draw(((IGasHandler)tileEntity).receiveGas(MekanismUtils.getLeft(facing), toSend, true), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +185,7 @@ public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, Pres
|
||||
recipe.operate(inventory, inputFluidTank, inputGasTank, outputGasTank);
|
||||
|
||||
markDirty();
|
||||
ejectorComponent.onOutput();
|
||||
ejectorComponent.outputItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,22 +9,29 @@ import java.util.Map;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
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;
|
||||
import mekanism.common.content.transporter.TransporterManager;
|
||||
import mekanism.common.tile.TileEntityContainerBlock;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.PipeUtils;
|
||||
import mekanism.common.util.TransporterUtils;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public class TileComponentEjector implements ITileComponent, IEjector
|
||||
{
|
||||
@@ -41,6 +48,9 @@ public class TileComponentEjector implements ITileComponent, IEjector
|
||||
public Map<TransmissionType, SideData> sideData = new HashMap<TransmissionType, SideData>();
|
||||
|
||||
public Map<TransmissionType, int[]> trackers = new HashMap<TransmissionType, int[]>();
|
||||
|
||||
public static final int GAS_OUTPUT = 256;
|
||||
public static final int FLUID_OUTPUT = 256;
|
||||
|
||||
public TileComponentEjector(TileEntityContainerBlock tile)
|
||||
{
|
||||
@@ -89,32 +99,76 @@ public class TileComponentEjector implements ITileComponent, IEjector
|
||||
{
|
||||
if(tickDelay == 0)
|
||||
{
|
||||
onOutput();
|
||||
if(sideData.get(TransmissionType.ITEM) != null)
|
||||
{
|
||||
outputItems();
|
||||
}
|
||||
}
|
||||
else {
|
||||
tickDelay--;
|
||||
}
|
||||
|
||||
if(!tileEntity.getWorldObj().isRemote)
|
||||
{
|
||||
if(sideData.get(TransmissionType.GAS) != null && getEjecting(TransmissionType.GAS))
|
||||
{
|
||||
SideData data = sideData.get(TransmissionType.GAS);
|
||||
List<ForgeDirection> outputSides = getOutputSides(TransmissionType.GAS, data);
|
||||
|
||||
GasTank tank = (GasTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]];
|
||||
|
||||
if(tank.getStored() > 0)
|
||||
{
|
||||
GasStack toEmit = tank.getGas().copy().withAmount(Math.min(GAS_OUTPUT, tank.getStored()));
|
||||
int emit = GasTransmission.emit(outputSides, toEmit, tileEntity);
|
||||
tank.draw(emit, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(sideData.get(TransmissionType.FLUID) != null && getEjecting(TransmissionType.FLUID))
|
||||
{
|
||||
SideData data = sideData.get(TransmissionType.FLUID);
|
||||
List<ForgeDirection> outputSides = getOutputSides(TransmissionType.FLUID, data);
|
||||
|
||||
FluidTank tank = (FluidTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]];
|
||||
|
||||
if(tank.getFluidAmount() > 0)
|
||||
{
|
||||
FluidStack toEmit = new FluidStack(tank.getFluid().getFluid(), Math.min(FLUID_OUTPUT, tank.getFluidAmount()));
|
||||
int emit = PipeUtils.emit(outputSides, toEmit, tileEntity);
|
||||
tank.drain(emit, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
{
|
||||
if(configurable.getConfig().getConfig(type)[i] == configurable.getConfig().getOutputs(type).indexOf(data))
|
||||
{
|
||||
outputSides.add(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(i, tileEntity.facing)));
|
||||
}
|
||||
}
|
||||
|
||||
return outputSides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOutput()
|
||||
public void outputItems()
|
||||
{
|
||||
if(!getEjecting(TransmissionType.ITEM) || tileEntity.getWorldObj().isRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<ForgeDirection> outputSides = new ArrayList<ForgeDirection>();
|
||||
|
||||
ISideConfiguration configurable = (ISideConfiguration)tileEntity;
|
||||
|
||||
for(int i = 0; i < configurable.getConfig().getConfig(TransmissionType.ITEM).length; i++)
|
||||
{
|
||||
if(configurable.getConfig().getConfig(TransmissionType.ITEM)[i] == configurable.getConfig().getOutputs(TransmissionType.ITEM).indexOf(sideData))
|
||||
{
|
||||
outputSides.add(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(i, tileEntity.facing)));
|
||||
}
|
||||
}
|
||||
SideData data = sideData.get(TransmissionType.ITEM);
|
||||
List<ForgeDirection> outputSides = getOutputSides(TransmissionType.ITEM, data);
|
||||
|
||||
for(int index = 0; index < sideData.get(TransmissionType.ITEM).availableSlots.length; index++)
|
||||
{
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
@@ -144,4 +147,60 @@ public final class PipeUtils
|
||||
|
||||
return acceptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits fluid 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
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(List<ForgeDirection> sides, FluidStack stack, TileEntity from)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IFluidHandler> availableAcceptors = new ArrayList<IFluidHandler>();
|
||||
IFluidHandler[] possibleAcceptors = getConnectedAcceptors(from);
|
||||
|
||||
for(int i = 0; i < possibleAcceptors.length; i++)
|
||||
{
|
||||
IFluidHandler handler = possibleAcceptors[i];
|
||||
|
||||
if(handler != null && handler.canFill(ForgeDirection.getOrientation(i).getOpposite(), stack.getFluid()))
|
||||
{
|
||||
availableAcceptors.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend-remaining)/divider;
|
||||
|
||||
for(IFluidHandler acceptor : availableAcceptors)
|
||||
{
|
||||
int currentSending = sending;
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.fill(dir, new FluidStack(stack.getFluid(), currentSending), true);
|
||||
}
|
||||
}
|
||||
|
||||
return prevSending-toSend;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user