More Reactor work. Making way for persistent reactor state and guis and stuff.
This commit is contained in:
parent
2f4d545fb5
commit
be15bab0b7
5 changed files with 183 additions and 33 deletions
|
@ -20,5 +20,11 @@ public interface IFusionReactor
|
|||
|
||||
public GasTank getFuelTank();
|
||||
|
||||
public double getBufferedEnergy();
|
||||
|
||||
public void setBufferedEnergy(double energy);
|
||||
|
||||
public double getBufferSize();
|
||||
|
||||
public void formMultiblock();
|
||||
}
|
||||
|
|
|
@ -30,18 +30,6 @@ import static java.lang.Math.max;
|
|||
|
||||
public class FusionReactor implements IFusionReactor
|
||||
{
|
||||
public static final int MAX_WATER = 100 * FluidContainerRegistry.BUCKET_VOLUME;
|
||||
|
||||
public static final int MAX_FUEL = 100 * FluidContainerRegistry.BUCKET_VOLUME;
|
||||
|
||||
public FluidTank waterTank = new FluidTank(MAX_WATER);
|
||||
public FluidTank steamTank = new FluidTank(MAX_WATER*1000);
|
||||
|
||||
public GasTank deuteriumTank = new GasTank(MAX_FUEL);
|
||||
public GasTank tritiumTank = new GasTank(MAX_FUEL);
|
||||
|
||||
public GasTank fuelTank = new GasTank(MAX_FUEL);
|
||||
|
||||
public TileEntityReactorController controller;
|
||||
public Set<IReactorBlock> reactorBlocks = new HashSet<IReactorBlock>();
|
||||
public Set<INeutronCapture> neutronCaptors = new HashSet<INeutronCapture>();
|
||||
|
@ -49,7 +37,6 @@ public class FusionReactor implements IFusionReactor
|
|||
//Current stores of energy
|
||||
public double plasmaTemperature;
|
||||
public double caseTemperature;
|
||||
public double energyBuffer;
|
||||
|
||||
//Reaction characteristics
|
||||
public static double burnTemperature = 1E8;
|
||||
|
@ -120,26 +107,26 @@ public class FusionReactor implements IFusionReactor
|
|||
|
||||
public void vaporiseHohlraum()
|
||||
{
|
||||
fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuelDT"), 10), true);
|
||||
getFuelTank().receive(new GasStack(GasRegistry.getGas("fusionFuelDT"), 10), true);
|
||||
hasHohlraum = false;
|
||||
burning = true;
|
||||
}
|
||||
|
||||
public void injectFuel()
|
||||
{
|
||||
int amountNeeded = fuelTank.getNeeded();
|
||||
int amountAvailable = 2*min(deuteriumTank.getStored(), tritiumTank.getStored());
|
||||
int amountNeeded = getFuelTank().getNeeded();
|
||||
int amountAvailable = 2*min(getDeuteriumTank().getStored(), getTritiumTank().getStored());
|
||||
int amountToInject = min(amountNeeded, min(amountAvailable, injectionRate));
|
||||
amountToInject -= amountToInject % 2;
|
||||
deuteriumTank.draw(amountToInject/2, true);
|
||||
tritiumTank.draw(amountToInject/2, true);
|
||||
fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuel"), amountToInject), true);
|
||||
getDeuteriumTank().draw(amountToInject / 2, true);
|
||||
getTritiumTank().draw(amountToInject / 2, true);
|
||||
getFuelTank().receive(new GasStack(GasRegistry.getGas("fusionFuel"), amountToInject), true);
|
||||
}
|
||||
|
||||
public int burnFuel()
|
||||
{
|
||||
int fuelBurned = (int)min(fuelTank.getStored(), max(0, plasmaTemperature - burnTemperature)*burnRatio);
|
||||
fuelTank.draw(fuelBurned, true);
|
||||
int fuelBurned = (int)min(getFuelTank().getStored(), max(0, plasmaTemperature - burnTemperature)*burnRatio);
|
||||
getFuelTank().draw(fuelBurned, true);
|
||||
plasmaTemperature += tempPerFuel * fuelBurned;
|
||||
return fuelBurned;
|
||||
}
|
||||
|
@ -172,12 +159,12 @@ public class FusionReactor implements IFusionReactor
|
|||
double caseWaterHeat = caseWaterConductivity * caseTemperature;
|
||||
int waterToVaporize = (int)(caseWaterHeat / enthalpyOfVaporization);
|
||||
Mekanism.logger.info("Wanting to vaporise " + waterToVaporize + "mB of water");
|
||||
waterToVaporize = min(waterToVaporize, min(waterTank.getFluidAmount(), steamTank.getCapacity() - steamTank.getFluidAmount()));
|
||||
waterToVaporize = min(waterToVaporize, min(getWaterTank().getFluidAmount(), getSteamTank().getCapacity() - getSteamTank().getFluidAmount()));
|
||||
if(waterToVaporize > 0)
|
||||
{
|
||||
Mekanism.logger.info("Vaporising " + waterToVaporize + "mB of water");
|
||||
waterTank.drain(waterToVaporize, true);
|
||||
steamTank.fill(new FluidStack(FluidRegistry.getFluid("steam"), waterToVaporize), true);
|
||||
getWaterTank().drain(waterToVaporize, true);
|
||||
getSteamTank().fill(new FluidStack(FluidRegistry.getFluid("steam"), waterToVaporize), true);
|
||||
}
|
||||
caseWaterHeat = waterToVaporize * enthalpyOfVaporization;
|
||||
caseTemperature -= caseWaterHeat / caseHeatCapacity;
|
||||
|
@ -186,37 +173,55 @@ public class FusionReactor implements IFusionReactor
|
|||
//Transfer from casing to environment
|
||||
double caseAirHeat = caseAirConductivity * caseTemperature;
|
||||
caseTemperature -= caseAirHeat / caseHeatCapacity;
|
||||
energyBuffer += caseAirHeat * thermocoupleEfficiency;
|
||||
setBufferedEnergy(getBufferedEnergy() + caseAirHeat * thermocoupleEfficiency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank getWaterTank()
|
||||
{
|
||||
return waterTank;
|
||||
return controller != null ? controller.waterTank : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank getSteamTank()
|
||||
{
|
||||
return steamTank;
|
||||
return controller.steamTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasTank getDeuteriumTank()
|
||||
{
|
||||
return deuteriumTank;
|
||||
return controller.deuteriumTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasTank getTritiumTank()
|
||||
{
|
||||
return tritiumTank;
|
||||
return controller.tritiumTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasTank getFuelTank()
|
||||
{
|
||||
return fuelTank;
|
||||
return controller.fuelTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBufferedEnergy()
|
||||
{
|
||||
return controller.getEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBufferedEnergy(double energy)
|
||||
{
|
||||
controller.setEnergy(energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBufferSize()
|
||||
{
|
||||
return controller.getMaxEnergy();
|
||||
}
|
||||
|
||||
public void unformMultiblock()
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
package mekanism.generators.common.tile.reactor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import mekanism.api.reactor.IFusionReactor;
|
||||
import mekanism.api.reactor.IReactorBlock;
|
||||
import mekanism.common.tile.TileEntityElectricBlock;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class TileEntityReactorBlock extends TileEntity implements IReactorBlock
|
||||
public abstract class TileEntityReactorBlock extends TileEntityElectricBlock implements IReactorBlock
|
||||
{
|
||||
public IFusionReactor fusionReactor;
|
||||
public boolean changed;
|
||||
|
||||
public TileEntityReactorBlock()
|
||||
{
|
||||
super("ReactorBlock", 0);
|
||||
inventory = new ItemStack[0];
|
||||
}
|
||||
|
||||
public TileEntityReactorBlock(String name, double maxEnergy)
|
||||
{
|
||||
super(name, maxEnergy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReactor(IFusionReactor reactor)
|
||||
{
|
||||
|
@ -36,11 +52,33 @@ public abstract class TileEntityReactorBlock extends TileEntity implements IReac
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
public void onUpdate()
|
||||
{
|
||||
if(changed)
|
||||
{
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(ForgeDirection side, double energy)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveEnergy(ForgeDirection side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public EnumSet<ForgeDirection> getOutputtingSides()
|
||||
{
|
||||
return EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
|
||||
protected EnumSet<ForgeDirection> getConsumingSides()
|
||||
{
|
||||
return EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,31 @@
|
|||
package mekanism.generators.common.tile.reactor;
|
||||
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.generators.common.FusionReactor;
|
||||
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public class TileEntityReactorController extends TileEntityReactorBlock
|
||||
{
|
||||
public static final int MAX_WATER = 100 * FluidContainerRegistry.BUCKET_VOLUME;
|
||||
|
||||
public static final int MAX_FUEL = 1 * FluidContainerRegistry.BUCKET_VOLUME;
|
||||
|
||||
public FluidTank waterTank = new FluidTank(MAX_WATER);
|
||||
public FluidTank steamTank = new FluidTank(MAX_WATER*1000);
|
||||
|
||||
public GasTank deuteriumTank = new GasTank(MAX_FUEL);
|
||||
public GasTank tritiumTank = new GasTank(MAX_FUEL);
|
||||
|
||||
public GasTank fuelTank = new GasTank(MAX_FUEL);
|
||||
|
||||
public TileEntityReactorController()
|
||||
{
|
||||
super("ReactorController", 1000000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrame()
|
||||
{
|
||||
|
@ -25,8 +46,10 @@ public class TileEntityReactorController extends TileEntityReactorBlock
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
if(getReactor() != null && !worldObj.isRemote)
|
||||
{
|
||||
getReactor().simulate();
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package mekanism.generators.common.tile.reactor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import mekanism.api.energy.ICableOutputter;
|
||||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.api.gas.ITubeConnection;
|
||||
import mekanism.common.util.CableUtils;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
@ -15,12 +20,24 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
|
||||
public class TileEntityReactorPort extends TileEntityReactorBlock implements IFluidHandler, IGasHandler, ITubeConnection
|
||||
{
|
||||
public TileEntityReactorPort()
|
||||
{
|
||||
super("name", 1);
|
||||
}
|
||||
@Override
|
||||
public boolean isFrame()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
CableUtils.emit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
|
@ -125,4 +142,65 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl
|
|||
{
|
||||
return getReactor() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOutputTo(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy()
|
||||
{
|
||||
if(getReactor() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getReactor().getBufferedEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy)
|
||||
{
|
||||
if(getReactor() != null)
|
||||
{
|
||||
getReactor().setBufferedEnergy(energy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxEnergy()
|
||||
{
|
||||
if(getReactor() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getReactor().getBufferSize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getOutputtingSides()
|
||||
{
|
||||
EnumSet set = EnumSet.allOf(ForgeDirection.class);
|
||||
set.remove(ForgeDirection.UNKNOWN);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EnumSet<ForgeDirection> getConsumingSides()
|
||||
{
|
||||
return EnumSet.noneOf(ForgeDirection.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxOutput()
|
||||
{
|
||||
return 1000000000;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue