More work. I'm gonna let the configuration component determine send/receive instead of cluttering the GUI more

This commit is contained in:
aidancbrady 2016-03-04 12:07:34 -05:00
parent 8bd6b6e367
commit c03b712ed2
6 changed files with 347 additions and 26 deletions

View file

@ -56,7 +56,7 @@ public class GuiFluidGauge extends GuiGauge<Fluid>
{
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
if(tile instanceof ITankManager)
if(tile instanceof ITankManager && ((ITankManager)tile).getTanks() != null)
{
int index = Arrays.asList(((ITankManager)tile).getTanks()).indexOf(infoHandler.getTank());

View file

@ -56,7 +56,7 @@ public class GuiGasGauge extends GuiGauge<Gas>
{
TileEntity tile = ((GuiMekanism)guiObj).getTileEntity();
if(tile instanceof ITankManager)
if(tile instanceof ITankManager && ((ITankManager)tile).getTanks() != null)
{
int index = Arrays.asList(((ITankManager)tile).getTanks()).indexOf(infoHandler.getTank());

View file

@ -64,6 +64,11 @@ public class SideData
Object[] tanks = manager.getTanks();
List<FluidTankInfo> infos = new ArrayList<FluidTankInfo>();
if(tanks == null)
{
return infos.toArray(new FluidTankInfo[] {});
}
for(int slot : availableSlots)
{
if(slot <= tanks.length-1 && tanks[slot] instanceof IFluidTank)
@ -79,7 +84,7 @@ public class SideData
{
Object[] tanks = manager.getTanks();
if(tanks.length < 1 || !(tanks[0] instanceof GasTank))
if(tanks == null || tanks.length < 1 || !(tanks[0] instanceof GasTank))
{
return null;
}

View file

@ -287,6 +287,7 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool
CONFIGURATE_FLUIDS("configurate", "(" + TransmissionType.FLUID.localize() + ")", EnumColor.BRIGHT_GREEN, true),
CONFIGURATE_GASES("configurate", "(" + TransmissionType.GAS.localize() + ")", EnumColor.BRIGHT_GREEN, true),
CONFIGURATE_ENERGY("configurate", "(" + TransmissionType.ENERGY.localize() + ")", EnumColor.BRIGHT_GREEN, true),
CONFIGURATE_HEAT("configurate", "(" + TransmissionType.HEAT.localize() + ")", EnumColor.BRIGHT_GREEN, true),
EMPTY("empty", "", EnumColor.DARK_RED, false),
ROTATE("rotate", "", EnumColor.YELLOW, false),
WRENCH("wrench", "", EnumColor.PINK, false);
@ -331,6 +332,8 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool
return TransmissionType.GAS;
case CONFIGURATE_ENERGY:
return TransmissionType.ENERGY;
case CONFIGURATE_HEAT:
return TransmissionType.HEAT;
default:
return null;
}

View file

@ -4,39 +4,83 @@ import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.IHeatTransfer;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasHandler;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.SideData;
import mekanism.common.SideData.IOState;
import mekanism.common.base.IEjector;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.base.ITankManager;
import mekanism.common.content.entangloporter.InventoryFrequency;
import mekanism.common.frequency.Frequency;
import mekanism.common.frequency.FrequencyManager;
import mekanism.common.frequency.IFrequencyHandler;
import mekanism.common.tile.component.TileComponentConfig;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.util.CableUtils;
import mekanism.common.util.HeatUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
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.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock implements IFluidHandler, IFrequencyHandler, IGasHandler
public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock implements ISideConfiguration, ITankManager, IFluidHandler, IFrequencyHandler, IGasHandler, IHeatTransfer
{
public String owner;
public InventoryFrequency frequency;
public double heatToAbsorb = 0;
public double lastTransferLoss;
public double lastEnvironmentLoss;
public List<Frequency> publicCache = new ArrayList<Frequency>();
public List<Frequency> privateCache = new ArrayList<Frequency>();
public static final EnumSet<ForgeDirection> nothing = EnumSet.noneOf(ForgeDirection.class);
public TileComponentEjector ejectorComponent;
public TileComponentConfig configComponent;
public TileEntityQuantumEntangloporter()
{
super("QuantumEntangloporter", 0);
configComponent = new TileComponentConfig(this, TransmissionType.ITEM, TransmissionType.ENERGY);
for(TransmissionType type : TransmissionType.values())
{
if(type != TransmissionType.HEAT)
{
configComponent.setIOConfig(type);
}
else {
configComponent.setInputConfig(type);
}
}
inventory = new ItemStack[0];
ejectorComponent = new TileComponentEjector(this);
ejectorComponent.setOutputData(TransmissionType.ITEM, new SideData("dummy", EnumColor.GREY, new int[] {0}));
ejectorComponent.setOutputData(TransmissionType.FLUID, new SideData("dummy", EnumColor.GREY, new int[] {0}));
ejectorComponent.setOutputData(TransmissionType.GAS, new SideData("dummy", EnumColor.GREY, new int[] {1}));
}
@Override
@ -44,9 +88,58 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
{
super.onUpdate();
if(!worldObj.isRemote)
{
if(configComponent.isEjecting(TransmissionType.ENERGY))
{
CableUtils.emit(this);
}
double[] loss = simulateHeat();
applyTemperatureChange();
lastTransferLoss = loss[0];
lastEnvironmentLoss = loss[1];
FrequencyManager manager = getManager(frequency);
if(manager != null)
{
if(frequency != null && !frequency.valid)
{
frequency = (InventoryFrequency)manager.validateFrequency(owner, Coord4D.get(this), frequency);
}
if(frequency != null)
{
frequency = (InventoryFrequency)manager.update(owner, Coord4D.get(this), frequency);
}
}
else {
frequency = null;
}
}
}
@Override
public void invalidate()
{
super.invalidate();
if(!worldObj.isRemote)
{
if(frequency != null)
{
FrequencyManager manager = getManager(frequency);
if(manager != null)
{
manager.deactivate(Coord4D.get(this));
}
}
}
}
@Override
public Frequency getFrequency()
{
@ -106,6 +199,41 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
markDirty();
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
if(nbtTags.hasKey("owner"))
{
owner = nbtTags.getString("owner");
}
if(nbtTags.hasKey("frequency"))
{
frequency = new InventoryFrequency(nbtTags.getCompoundTag("frequency"));
frequency.valid = false;
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTags)
{
super.writeToNBT(nbtTags);
if(owner != null)
{
nbtTags.setString("owner", owner);
}
if(frequency != null)
{
NBTTagCompound frequencyTag = new NBTTagCompound();
frequency.write(frequencyTag);
nbtTags.setTag("frequency", frequencyTag);
}
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
@ -138,27 +266,104 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
super.handlePacketData(dataStream);
setEnergy(dataStream.readDouble());
lastTransferLoss = dataStream.readDouble();
lastEnvironmentLoss = dataStream.readDouble();
if(dataStream.readBoolean())
{
owner = PacketHandler.readString(dataStream);
}
else {
owner = null;
}
if(dataStream.readBoolean())
{
frequency = new InventoryFrequency(dataStream);
}
else {
frequency = null;
}
publicCache.clear();
privateCache.clear();
int amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{
publicCache.add(new Frequency(dataStream));
}
amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{
privateCache.add(new Frequency(dataStream));
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(getEnergy());
data.add(lastTransferLoss);
data.add(lastEnvironmentLoss);
if(owner != null)
{
data.add(true);
data.add(owner);
}
else {
data.add(false);
}
if(frequency != null)
{
data.add(true);
frequency.write(data);
}
else {
data.add(false);
}
data.add(Mekanism.publicEntangloporters.getFrequencies().size());
for(Frequency freq : Mekanism.publicEntangloporters.getFrequencies())
{
freq.write(data);
}
FrequencyManager manager = getManager(new Frequency(null, null).setPublic(false));
if(manager != null)
{
data.add(manager.getFrequencies().size());
for(Frequency freq : manager.getFrequencies())
{
freq.write(data);
}
}
else {
data.add(0);
}
return data;
}
@Override
public EnumSet<ForgeDirection> getOutputtingSides()
{
return frequency == null ? nothing : EnumSet.of(ForgeDirection.UP);
return frequency == null ? nothing : configComponent.getSidesForData(TransmissionType.ENERGY, facing, 2);
}
@Override
public EnumSet<ForgeDirection> getConsumingSides()
{
return frequency == null ? nothing : EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN, ForgeDirection.UP));
return frequency == null ? nothing : configComponent.getSidesForData(TransmissionType.ENERGY, facing, 1);
}
@Override
@ -219,7 +424,7 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
if(frequency != null)
if(frequency != null && configComponent.getOutput(TransmissionType.FLUID, from.ordinal(), facing).ioState == IOState.INPUT)
{
return frequency.storedFluid.getFluid() == null || fluid == frequency.storedFluid.getFluid().getFluid();
}
@ -230,7 +435,7 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
if(frequency != null)
if(frequency != null && configComponent.getOutput(TransmissionType.FLUID, from.ordinal(), facing).ioState == IOState.OUTPUT)
{
return frequency.storedFluid.getFluid() == null || fluid == frequency.storedFluid.getFluid().getFluid();
}
@ -241,7 +446,15 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return frequency == null ? PipeUtils.EMPTY : new FluidTankInfo[] {frequency.storedFluid.getInfo()};
if(frequency != null)
{
if(configComponent.getOutput(TransmissionType.FLUID, from.ordinal(), facing).ioState != IOState.OFF)
{
return new FluidTankInfo[] {frequency.storedFluid.getInfo()};
}
}
return PipeUtils.EMPTY;
}
@Override
@ -271,7 +484,7 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public boolean canReceiveGas(ForgeDirection side, Gas type)
{
if(frequency != null)
if(frequency != null && configComponent.getOutput(TransmissionType.GAS, side.ordinal(), facing).ioState == IOState.INPUT)
{
return frequency.storedGas.getGasType() == null || type == frequency.storedGas.getGasType();
}
@ -282,7 +495,7 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
if(frequency != null)
if(frequency != null && configComponent.getOutput(TransmissionType.GAS, side.ordinal(), facing).ioState == IOState.OUTPUT)
{
return frequency.storedGas.getGasType() == null || type == frequency.storedGas.getGasType();
}
@ -321,4 +534,98 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
}
}
}
@Override
public double getTemp()
{
return frequency != null ? frequency.temperature : 0;
}
@Override
public double getInverseConductionCoefficient()
{
return 1;
}
@Override
public double getInsulationCoefficient(ForgeDirection side)
{
return 1000;
}
@Override
public void transferHeatTo(double heat)
{
heatToAbsorb += heat;
}
@Override
public double[] simulateHeat()
{
return HeatUtils.simulate(this);
}
@Override
public double applyTemperatureChange()
{
if(frequency != null)
{
frequency.temperature += heatToAbsorb;
}
heatToAbsorb = 0;
return frequency != null ? frequency.temperature : 0;
}
@Override
public boolean canConnectHeat(ForgeDirection side)
{
return frequency != null && configComponent.getOutput(TransmissionType.HEAT, side.ordinal(), facing).ioState != IOState.OFF;
}
@Override
public IHeatTransfer getAdjacent(ForgeDirection side)
{
TileEntity adj = Coord4D.get(this).getFromSide(side).getTileEntity(worldObj);
if(configComponent.getOutput(TransmissionType.HEAT, side.ordinal(), facing).ioState == IOState.INPUT)
{
if(adj instanceof IHeatTransfer)
{
return (IHeatTransfer)adj;
}
}
return null;
}
@Override
public Object[] getTanks()
{
if(frequency == null)
{
return null;
}
return new Object[] {frequency.storedFluid, frequency.storedGas};
}
@Override
public TileComponentConfig getConfig()
{
return configComponent;
}
@Override
public int getOrientation()
{
return facing;
}
@Override
public IEjector getEjector()
{
return ejectorComponent;
}
}

View file

@ -115,6 +115,8 @@ public class TileComponentEjector implements ITileComponent, IEjector
SideData data = sideData.get(TransmissionType.GAS);
List<ForgeDirection> outputSides = getOutputSides(TransmissionType.GAS, data);
if(((ITankManager)tileEntity).getTanks() != null)
{
GasTank tank = (GasTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]];
if(tank.getStored() > 0)
@ -124,12 +126,15 @@ public class TileComponentEjector implements ITileComponent, IEjector
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);
if(((ITankManager)tileEntity).getTanks() != null)
{
FluidTank tank = (FluidTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]];
if(tank.getFluidAmount() > 0)
@ -141,6 +146,7 @@ public class TileComponentEjector implements ITileComponent, IEjector
}
}
}
}
public List<ForgeDirection> getOutputSides(TransmissionType type, SideData data)
{