From c03b712ed2421a1cd49563fa82060246d3d41fb6 Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Fri, 4 Mar 2016 12:07:34 -0500 Subject: [PATCH] More work. I'm gonna let the configuration component determine send/receive instead of cluttering the GUI more --- .../client/gui/element/GuiFluidGauge.java | 2 +- .../client/gui/element/GuiGasGauge.java | 2 +- src/main/java/mekanism/common/SideData.java | 7 +- .../common/item/ItemConfigurator.java | 3 + .../tile/TileEntityQuantumEntangloporter.java | 329 +++++++++++++++++- .../tile/component/TileComponentEjector.java | 30 +- 6 files changed, 347 insertions(+), 26 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/GuiFluidGauge.java b/src/main/java/mekanism/client/gui/element/GuiFluidGauge.java index 1f491648d..51ef948eb 100644 --- a/src/main/java/mekanism/client/gui/element/GuiFluidGauge.java +++ b/src/main/java/mekanism/client/gui/element/GuiFluidGauge.java @@ -56,7 +56,7 @@ public class GuiFluidGauge extends GuiGauge { 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()); diff --git a/src/main/java/mekanism/client/gui/element/GuiGasGauge.java b/src/main/java/mekanism/client/gui/element/GuiGasGauge.java index 97069a2e1..939edaaa1 100644 --- a/src/main/java/mekanism/client/gui/element/GuiGasGauge.java +++ b/src/main/java/mekanism/client/gui/element/GuiGasGauge.java @@ -56,7 +56,7 @@ public class GuiGasGauge extends GuiGauge { 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()); diff --git a/src/main/java/mekanism/common/SideData.java b/src/main/java/mekanism/common/SideData.java index 7a82f00f9..68a174dcc 100644 --- a/src/main/java/mekanism/common/SideData.java +++ b/src/main/java/mekanism/common/SideData.java @@ -64,6 +64,11 @@ public class SideData Object[] tanks = manager.getTanks(); List infos = new ArrayList(); + 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; } diff --git a/src/main/java/mekanism/common/item/ItemConfigurator.java b/src/main/java/mekanism/common/item/ItemConfigurator.java index 4d3a9edfe..a56c4bb16 100644 --- a/src/main/java/mekanism/common/item/ItemConfigurator.java +++ b/src/main/java/mekanism/common/item/ItemConfigurator.java @@ -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; } diff --git a/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java b/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java index fd197137f..b632ba822 100644 --- a/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java +++ b/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java @@ -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 publicCache = new ArrayList(); + public List privateCache = new ArrayList(); public static final EnumSet 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,7 +88,56 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp { super.onUpdate(); - CableUtils.emit(this); + 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 @@ -105,6 +198,41 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp MekanismUtils.saveChunk(this); 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 getOutputtingSides() { - return frequency == null ? nothing : EnumSet.of(ForgeDirection.UP); + return frequency == null ? nothing : configComponent.getSidesForData(TransmissionType.ENERGY, facing, 2); } @Override public EnumSet 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; + } } diff --git a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java index ff1f1a146..d4feaea49 100644 --- a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java +++ b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java @@ -115,13 +115,16 @@ public class TileComponentEjector implements ITileComponent, IEjector SideData data = sideData.get(TransmissionType.GAS); List outputSides = getOutputSides(TransmissionType.GAS, data); - GasTank tank = (GasTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]]; - - if(tank.getStored() > 0) + if(((ITankManager)tileEntity).getTanks() != null) { - GasStack toEmit = tank.getGas().copy().withAmount(Math.min(GAS_OUTPUT, tank.getStored())); - int emit = GasTransmission.emit(toEmit, tileEntity, outputSides); - tank.draw(emit, true); + 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(toEmit, tileEntity, outputSides); + tank.draw(emit, true); + } } } @@ -130,13 +133,16 @@ public class TileComponentEjector implements ITileComponent, IEjector SideData data = sideData.get(TransmissionType.FLUID); List outputSides = getOutputSides(TransmissionType.FLUID, data); - FluidTank tank = (FluidTank)((ITankManager)tileEntity).getTanks()[data.availableSlots[0]]; - - if(tank.getFluidAmount() > 0) + if(((ITankManager)tileEntity).getTanks() != null) { - FluidStack toEmit = new FluidStack(tank.getFluid().getFluid(), Math.min(FLUID_OUTPUT, tank.getFluidAmount())); - int emit = PipeUtils.emit(outputSides, toEmit, tileEntity); - tank.drain(emit, true); + 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); + } } } }