From 62659afadb09c7252a479d7e2c3a06dd6542ccef Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Wed, 16 Jul 2014 02:48:02 +0100 Subject: [PATCH] Reactor Multiblock work --- .../generators/common/FusionReactor.java | 53 +++++++++++-------- .../tile/reactor/TileEntityReactorBlock.java | 23 ++++++++ .../tile/reactor/TileEntityReactorPort.java | 8 +-- 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/main/java/mekanism/generators/common/FusionReactor.java b/src/main/java/mekanism/generators/common/FusionReactor.java index 3b5db9456..e7aa9fdaa 100644 --- a/src/main/java/mekanism/generators/common/FusionReactor.java +++ b/src/main/java/mekanism/generators/common/FusionReactor.java @@ -19,12 +19,12 @@ 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.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -import static java.lang.Math.exp; import static java.lang.Math.min; import static java.lang.Math.max; @@ -99,7 +99,8 @@ public class FusionReactor implements IFusionReactor public void vaporiseHohlraum() { - fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuel"), 1000), true); + fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuelDT"), 1000), true); + hasHohlraum = false; burning = true; } @@ -139,7 +140,10 @@ public class FusionReactor implements IFusionReactor public void boilWater() { - int waterToBoil = (int)min(waterTank.getFluidAmount(), temperature*temperature*waterRatio); + int waterToBoil = (int)min(waterTank.getFluidAmount(), temperature*1E-6); + int steamToGenerate = (int)(waterToBoil*temperature * 1E-6); + waterTank.drain(waterToBoil, true); + steamTank.fill(new FluidStack(FluidRegistry.getFluid("steam"), steamToGenerate), true); } public void ambientLoss() @@ -181,41 +185,46 @@ public class FusionReactor implements IFusionReactor return fuelTank; } + public void unformMultiblock() + { + for(IReactorBlock block: reactorBlocks) + { + block.setReactor(null); + } + reactorBlocks.clear(); + neutronCaptors.clear(); + formed = false; + } + + @Override public void formMultiblock() { Coord4D controllerPosition = Coord4D.get(controller); Coord4D centreOfReactor = controllerPosition.getFromSide(ForgeDirection.DOWN, 2); + unformMultiblock(); + + reactorBlocks.add(controller); + Mekanism.logger.info("Centre at " + centreOfReactor.toString()); if(!createFrame(centreOfReactor)) { - for(IReactorBlock block: reactorBlocks) - { - block.setReactor(null); - } - reactorBlocks.clear(); + unformMultiblock(); + Mekanism.logger.info("Reactor failed: Frame not complete."); return; } Mekanism.logger.info("Frame valid"); if(!addSides(centreOfReactor)) { - for(IReactorBlock block: reactorBlocks) - { - block.setReactor(null); - } - reactorBlocks.clear(); - neutronCaptors.clear(); + unformMultiblock(); + Mekanism.logger.info("Reactor failed: Sides not complete."); return; } Mekanism.logger.info("Side Blocks Valid"); if(!centreIsClear(centreOfReactor)) { - for(IReactorBlock block: reactorBlocks) - { - block.setReactor(null); - } - reactorBlocks.clear(); - neutronCaptors.clear(); + unformMultiblock(); + Mekanism.logger.info("Blocks in chamber."); return; } Mekanism.logger.info("Centre is clear"); @@ -257,7 +266,7 @@ public class FusionReactor implements IFusionReactor {+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 + {+0, +0, -2}, {+1, +0, -2}, {+0, +1, -2}, {-1, +0, -2}, {+0, -1, -2}, //NORTH }; for(int[] coords : positions) diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorBlock.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorBlock.java index dbf6dd55d..dd5411ec9 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorBlock.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorBlock.java @@ -8,10 +8,15 @@ import net.minecraft.tileentity.TileEntity; public abstract class TileEntityReactorBlock extends TileEntity implements IReactorBlock { public IFusionReactor fusionReactor; + public boolean changed; @Override public void setReactor(IFusionReactor reactor) { + if(reactor != fusionReactor) + { + changed = true; + } fusionReactor = reactor; } @@ -20,4 +25,22 @@ public abstract class TileEntityReactorBlock extends TileEntity implements IReac { return fusionReactor; } + + @Override + public void invalidate() + { + if(getReactor() != null) + { + getReactor().formMultiblock(); + } + } + + @Override + public void updateEntity() + { + if(changed) + { + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType()); + } + } } diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java index 1c1e4226e..2773d98d4 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java @@ -46,7 +46,7 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl { if(getReactor() != null) { - getReactor().getSteamTank().drain(maxDrain, doDrain); + return getReactor().getSteamTank().drain(maxDrain, doDrain); } return null; } @@ -86,7 +86,7 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl { return getReactor().getTritiumTank().receive(stack, true); } - else if(stack.getGas() == GasRegistry.getGas("fusionFuel")) + else if(stack.getGas() == GasRegistry.getGas("fusionFuelDT")) { return getReactor().getFuelTank().receive(stack, true); } @@ -111,7 +111,7 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl @Override public boolean canReceiveGas(ForgeDirection side, Gas type) { - return (type == GasRegistry.getGas("deuterium") || type == GasRegistry.getGas("tritium") || type == GasRegistry.getGas("fusionFuel")); + return (type == GasRegistry.getGas("deuterium") || type == GasRegistry.getGas("tritium") || type == GasRegistry.getGas("fusionFuelDT")); } @Override @@ -123,6 +123,6 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl @Override public boolean canTubeConnect(ForgeDirection side) { - return true; + return getReactor() != null; } } \ No newline at end of file