More work on Fusion Reactor

This commit is contained in:
Ben Spiers committed 2014-07-16 02:54:13 +01:00
1 parent cb2188580e
commit bdde617489
10 files changed
+209 -16

No files matched your search

@@ -6,17 +6,25 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.lasers.ILaserReceptor;
import mekanism.api.reactor.IFusionReactor;
import mekanism.api.reactor.INeutronCapture;
import mekanism.api.reactor.IReactorBlock;
import mekanism.common.Mekanism;
import mekanism.generators.common.tile.reactor.TileEntityReactorController;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidTank;
import static java.lang.Math.exp;
import static java.lang.Math.min;
import static java.lang.Math.max;
@@ -43,9 +51,9 @@ public class FusionReactor implements IFusionReactor
public static double burnRatio = 1;
public static double tempPerFuel = 5*10^6;
public int injectionRate;
public int injectionRate = 0;
public static double coolingCoefficient = 0.2;
public static double coolingCoefficient = 0.1;
public static double waterRatio = 10^-14;
public static double inverseHeatCapacity = 1;
@@ -53,8 +61,15 @@ public class FusionReactor implements IFusionReactor
public boolean burning = false;
public boolean hasHohlraum = false;
public boolean formed = false;
public FusionReactor(TileEntityReactorController c)
{
controller = c;
}
@Override
public void addTemperature(double energyAdded)
public void addTemperatureFromEnergyInput(double energyAdded)
{
temperature += energyAdded * inverseHeatCapacity;
}
@@ -78,6 +93,8 @@ public class FusionReactor implements IFusionReactor
}
boilWater();
ambientLoss();
if(temperature > 0)
Mekanism.logger.info("Reactor temperature: " + (int)temperature);
}
public void vaporiseHohlraum()
@@ -128,6 +145,10 @@ public class FusionReactor implements IFusionReactor
public void ambientLoss()
{
temperature -= coolingCoefficient*temperature;
if(temperature < 1E-6)
{
temperature = 0;
}
}
@Override
@@ -159,4 +180,130 @@ public class FusionReactor implements IFusionReactor
{
return fuelTank;
}
public void formMultiblock()
{
Coord4D controllerPosition = Coord4D.get(controller);
Coord4D centreOfReactor = controllerPosition.getFromSide(ForgeDirection.DOWN, 2);
Mekanism.logger.info("Centre at " + centreOfReactor.toString());
if(!createFrame(centreOfReactor))
{
for(IReactorBlock block: reactorBlocks)
{
block.setReactor(null);
}
reactorBlocks.clear();
return;
}
Mekanism.logger.info("Frame valid");
if(!addSides(centreOfReactor))
{
for(IReactorBlock block: reactorBlocks)
{
block.setReactor(null);
}
reactorBlocks.clear();
neutronCaptors.clear();
return;
}
Mekanism.logger.info("Side Blocks Valid");
if(!centreIsClear(centreOfReactor))
{
for(IReactorBlock block: reactorBlocks)
{
block.setReactor(null);
}
reactorBlocks.clear();
neutronCaptors.clear();
return;
}
Mekanism.logger.info("Centre is clear");
formed = true;
}
public boolean createFrame(Coord4D centre)
{
int[][] positions = new int[][] {
{+2, +2, +0}, {+2, +1, +1}, {+2, +0, +2}, {+2, -1, +1}, {+2, -2, +0}, {+2, -1, -1}, {+2, +0, -2}, {+2, +1, -1},
{+1, +2, +1}, {+1, +1, +2}, {+1, -1, +2}, {+1, -2, +1}, {+1, -2, -1}, {+1, -1, -2}, {+1, +1, -2}, {+1, +2, -1},
{+0, +2, +2}, {+0, -2, +2}, {+0, -2, -2}, {+0, +2, -2},
{-1, +2, +1}, {-1, +1, +2}, {-1, -1, +2}, {-1, -2, +1}, {-1, -2, -1}, {-1, -1, -2}, {-1, +1, -2}, {-1, +2, -1},
{-2, +2, +0}, {-2, +1, +1}, {-2, +0, +2}, {-2, -1, +1}, {-2, -2, +0}, {-2, -1, -1}, {-2, +0, -2}, {-2, +1, -1},
};
for(int[] coords : positions)
{
TileEntity tile = centre.clone().translate(coords[0], coords[1], coords[2]).getTileEntity(controller.getWorldObj());
if(tile instanceof IReactorBlock && ((IReactorBlock)tile).isFrame())
{
reactorBlocks.add((IReactorBlock)tile);
((IReactorBlock)tile).setReactor(this);
}
else {
return false;
}
}
return true;
}
public boolean addSides(Coord4D centre)
{
int[][] positions = new int[][] {
{+2, +0, +0}, {+2, +1, +0}, {+2, +0, +1}, {+2, -1, +0}, {+2, +0, -1}, //EAST
{-2, +0, +0}, {-2, +1, +0}, {-2, +0, +1}, {-2, -1, +0}, {-2, +0, -1}, //WEST
{+0, +2, +0}, {+1, +2, +0}, {+0, +2, +1}, {-1, +2, +0}, {+0, +2, -1}, //TOP
{+0, -2, +0}, {+1, -2, +0}, {+0, -2, +1}, {-1, -2, +0}, {+0, -2, -1}, //BOTTOM
{+0, +0, +2}, {+1, +0, +2}, {+0, +1, +2}, {-1, +0, +2}, {+0, -1, +2}, //SOUTH
{+0, +0, +2}, {+1, +0, +2}, {+0, +1, +2}, {-1, +0, +2}, {+0, -1, +2}, //NORTH
};
for(int[] coords : positions)
{
TileEntity tile = centre.clone().translate(coords[0], coords[1], coords[2]).getTileEntity(controller.getWorldObj());
if(tile instanceof ILaserReceptor && !(coords[1] == 0 && (coords[0] == 0 || coords[2] == 0)))
{
return false;
}
if(tile instanceof IReactorBlock)
{
reactorBlocks.add((IReactorBlock)tile);
((IReactorBlock)tile).setReactor(this);
if(tile instanceof INeutronCapture)
{
neutronCaptors.add((INeutronCapture)tile);
}
}
else {
return false;
}
}
return true;
}
public boolean centreIsClear(Coord4D centre)
{
for(int x = -1; x <= 1; x++)
{
for(int y = -1; x <= 1; x++)
{
for(int z = -1; x <= 1; x++)
{
Block tile = centre.clone().translate(x, y, z).getBlock(controller.getWorldObj());
if(!tile.isAir(controller.getWorldObj(), x, y, z))
{
return false;
}
}
}
}
return true;
}
}