diff --git a/src/main/java/mekanism/api/lasers/LaserManager.java b/src/main/java/mekanism/api/lasers/LaserManager.java index e61db4776..1bfd1d134 100644 --- a/src/main/java/mekanism/api/lasers/LaserManager.java +++ b/src/main/java/mekanism/api/lasers/LaserManager.java @@ -15,8 +15,9 @@ public class LaserManager public static void fireLaser(Coord4D from, ForgeDirection direction, double energy, World world) { + Coord4D rangeFrom = from.getFromSide(direction, 1); Coord4D to = from.getFromSide(direction, range); - MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(from.xCoord, from.yCoord, from.zCoord), Vec3.createVectorHelper(to.xCoord, to.yCoord, to.zCoord)); + MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(rangeFrom.xCoord, rangeFrom.yCoord, rangeFrom.zCoord), Vec3.createVectorHelper(to.xCoord, to.yCoord, to.zCoord)); if(mop != null) { diff --git a/src/main/java/mekanism/api/reactor/IFusionReactor.java b/src/main/java/mekanism/api/reactor/IFusionReactor.java index 6172c6075..16d8125a3 100644 --- a/src/main/java/mekanism/api/reactor/IFusionReactor.java +++ b/src/main/java/mekanism/api/reactor/IFusionReactor.java @@ -6,7 +6,7 @@ import net.minecraftforge.fluids.FluidTank; public interface IFusionReactor { - public void addTemperature(double energyAdded); + public void addTemperatureFromEnergyInput(double energyAdded); public void simulate(); @@ -19,4 +19,6 @@ public interface IFusionReactor public GasTank getTritiumTank(); public GasTank getFuelTank(); + + public void formMultiblock(); } diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index c80848efa..987c4f0d3 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -120,6 +120,7 @@ import mekanism.common.tile.TileEntityEnrichmentChamber; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidicPlenisher; import mekanism.common.tile.TileEntityGasTank; +import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntityLogisticalSorter; import mekanism.common.tile.TileEntityMetallurgicInfuser; import mekanism.common.tile.TileEntityObsidianTNT; @@ -147,6 +148,7 @@ import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -303,6 +305,8 @@ public class ClientProxy extends CommonProxy ClientRegistry.registerTileEntity(TileEntityPRC.class, "PressurizedReactionChamber", new RenderPressurizedReactionChamber()); ClientRegistry.registerTileEntity(TileEntityPortableTank.class, "PortableTank", new RenderPortableTank()); ClientRegistry.registerTileEntity(TileEntityFluidicPlenisher.class, "FluidicPlenisher", new RenderFluidicPlenisher()); + //TODO needs a model, I think. + GameRegistry.registerTileEntity(TileEntityLaser.class, "Laser"); } @Override diff --git a/src/main/java/mekanism/client/render/MekanismRenderer.java b/src/main/java/mekanism/client/render/MekanismRenderer.java index e02bd410b..c82a99d1b 100644 --- a/src/main/java/mekanism/client/render/MekanismRenderer.java +++ b/src/main/java/mekanism/client/render/MekanismRenderer.java @@ -74,7 +74,7 @@ public class MekanismRenderer GasRegistry.getGas("hydrogen").setIcon(event.map.registerIcon("mekanism:LiquidHydrogen")); GasRegistry.getGas("oxygen").setIcon(event.map.registerIcon("mekanism:LiquidOxygen")); GasRegistry.getGas("water").setIcon(event.map.registerIcon("mekanism:WaterVapor")); - GasRegistry.getGas("chlorine").setIcon(event.map.registerIcon("mekanism:Chlorine")); + GasRegistry.getGas("chlorine").setIcon(event.map.registerIcon("mekanism:LiquidChlorine")); GasRegistry.getGas("sulfurDioxideGas").setIcon(event.map.registerIcon("mekanism:LiquidSulfurDioxide")); GasRegistry.getGas("sulfurTrioxideGas").setIcon(event.map.registerIcon("mekanism:LiquidSulfurTrioxide")); GasRegistry.getGas("sulfuricAcid").setIcon(event.map.registerIcon("mekanism:LiquidSulfuricAcid")); @@ -84,7 +84,12 @@ public class MekanismRenderer GasRegistry.getGas("ethene").setIcon(event.map.registerIcon("mekanism:Ethene")); GasRegistry.getGas("brine").setIcon(event.map.registerIcon("mekanism:LiquidBrine")); GasRegistry.getGas("sodium").setIcon(event.map.registerIcon("mekanism:LiquidSodium")); - + GasRegistry.getGas("deuterium").setIcon(event.map.registerIcon("mekanism:LiquidDeuterium")); + GasRegistry.getGas("tritium").setIcon(event.map.registerIcon("mekanism:LiquidTritium")); + GasRegistry.getGas("fusionFuelDD").setIcon(event.map.registerIcon("mekanism:LiquidDD")); + GasRegistry.getGas("fusionFuelDT").setIcon(event.map.registerIcon("mekanism:liquidDT")); + GasRegistry.getGas("steam").setIcon(event.map.registerIcon("mekanism:LiquidSteam")); + for(Gas gas : GasRegistry.getRegisteredGasses()) { if(gas instanceof OreGas) diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java index d740ce3ac..731062624 100644 --- a/src/main/java/mekanism/common/CommonProxy.java +++ b/src/main/java/mekanism/common/CommonProxy.java @@ -64,6 +64,7 @@ import mekanism.common.tile.TileEntityEnrichmentChamber; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidicPlenisher; import mekanism.common.tile.TileEntityGasTank; +import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntityLogisticalSorter; import mekanism.common.tile.TileEntityMetallurgicInfuser; import mekanism.common.tile.TileEntityObsidianTNT; @@ -136,6 +137,7 @@ public class CommonProxy GameRegistry.registerTileEntity(TileEntityPRC.class, "PressurizedReactionChamber"); GameRegistry.registerTileEntity(TileEntityPortableTank.class, "PortableTank"); GameRegistry.registerTileEntity(TileEntityFluidicPlenisher.class, "FluidicPlenisher"); + GameRegistry.registerTileEntity(TileEntityLaser.class, "Laser"); } /** diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 958dd3bd3..52232833b 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -105,6 +105,7 @@ import mekanism.common.tile.TileEntityBoundingBlock; import mekanism.common.tile.TileEntityCardboardBox; import mekanism.common.tile.TileEntityElectricBlock; import mekanism.common.tile.TileEntityEnergizedSmelter; +import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntitySalinationTank; import mekanism.common.tile.TileEntitySalinationValve; import mekanism.common.transporter.TransporterManager; @@ -1335,6 +1336,11 @@ public class Mekanism GasRegistry.register(new Gas("ethene").registerFluid()); GasRegistry.register(new Gas("sodium").registerFluid()); GasRegistry.register(new Gas("brine").registerFluid()); + GasRegistry.register(new Gas("deuterium")).registerFluid(); + GasRegistry.register(new Gas("tritium")).registerFluid(); + GasRegistry.register(new Gas("fusionFuelDD")).registerFluid(); + GasRegistry.register(new Gas("fusionFuelDT")).registerFluid(); + GasRegistry.register(new Gas("steam")).registerFluid(); for(Resource resource : Resource.values()) { diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index 550d18e3a..b18ae4fc5 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -180,18 +180,14 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer } else if(this == Mekanism.MachineBlock2) { - icons[2][0] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOff"); - icons[2][1] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOn"); - icons[2][2] = register.registerIcon("mekanism:SteelCasing"); icons[3][0] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOff"); icons[3][1] = register.registerIcon("mekanism:ChemicalInjectionChamberFrontOn"); icons[3][2] = register.registerIcon("mekanism:SteelCasing"); icons[5][0] = register.registerIcon("mekanism:PrecisionSawmillFrontOff"); icons[5][1] = register.registerIcon("mekanism:PrecisionSawmillFrontOn"); icons[5][2] = register.registerIcon("mekanism:SteelCasing"); - icons[9][0] = register.registerIcon("mekanism:SteelBlock"); - icons[9][1] = register.registerIcon("mekanism:SeismicVibrator"); - icons[13][0] = register.registerIcon("Mekanism:Laser"); + icons[13][0] = register.registerIcon("mekanism:SteelCasing"); + icons[13][1] = register.registerIcon("mekanism:Laser"); } } @@ -467,6 +463,16 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer return icons[meta][0]; } } + else if(meta == 13) + { + if(side == 3) + { + return icons[meta][0]; + } + else { + return icons[meta][1]; + } + } } return null; @@ -600,7 +606,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer return icons[metadata][2]; } } - else if(metadata == 9) + else if(metadata == 9 || metadata == 13) { if(side == tileEntity.facing) { @@ -834,7 +840,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer } @Override - public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) + public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z))) { diff --git a/src/main/java/mekanism/common/tile/TileEntityLaser.java b/src/main/java/mekanism/common/tile/TileEntityLaser.java index ca209fed6..e4981dca2 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaser.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaser.java @@ -3,6 +3,7 @@ package mekanism.common.tile; import mekanism.api.Coord4D; import mekanism.api.lasers.LaserManager; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityLaser extends TileEntityElectricBlock @@ -12,14 +13,18 @@ public class TileEntityLaser extends TileEntityElectricBlock public TileEntityLaser() { super("Laser", 100000); + inventory = new ItemStack[0]; } @Override public void onUpdate() { + super.onUpdate(); + if(getEnergy() >= LASER_ENERGY) { LaserManager.fireLaser(Coord4D.get(this), ForgeDirection.getOrientation(facing), LASER_ENERGY, worldObj); + setEnergy(getEnergy()-LASER_ENERGY); } } } diff --git a/src/main/java/mekanism/generators/common/FusionReactor.java b/src/main/java/mekanism/generators/common/FusionReactor.java index 7af256891..31429f93f 100644 --- a/src/main/java/mekanism/generators/common/FusionReactor.java +++ b/src/main/java/mekanism/generators/common/FusionReactor.java @@ -6,15 +6,23 @@ 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.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.min; @@ -38,51 +46,82 @@ public class FusionReactor implements IFusionReactor public Set reactorBlocks = new HashSet(); public Set neutronCaptors = new HashSet(); - public double temperature; - public static double burnTemperature = 10^8; + //Current stores of energy + public double plasmaTemperature; + public double caseTemperature; + public double energyBuffer; + //Reaction characteristics + public static double burnTemperature = 1E8; public static double burnRatio = 1; - public static double tempPerFuel = 5*10^6; - public int injectionRate; - - public static double coolingCoefficient = 0.2; - - public static double waterRatio = 10^-14; - public static double inverseHeatCapacity = 1; + public static double tempPerFuel = 5E6; + public int injectionRate = 0; + + //Thermal characteristics + public static double plasmaHeatCapacity = 1; + public static double caseHeatCapacity = 1; + public static double enthalpyOfVaporization = 10; + public static double thermocoupleEfficiency = 0.01; + + //Heat transfer metrics + public static double plasmaCaseConductivity = 0.2; + public static double caseWaterConductivity = 0.3; + public static double caseAirConductivity = 0.1; public boolean burning = false; public boolean hasHohlraum = false; + public boolean activelyCooled = true; + + public boolean formed = false; + + public FusionReactor(TileEntityReactorController c) + { + controller = c; + } @Override - public void addTemperature(double energyAdded) + public void addTemperatureFromEnergyInput(double energyAdded) { - temperature += energyAdded * inverseHeatCapacity; + plasmaTemperature += energyAdded / plasmaHeatCapacity; } @Override public void simulate() { - if(temperature >= burnTemperature) + //Only thermal transfer happens unless we're hot enough to burn. + if(plasmaTemperature >= burnTemperature) { + //If we're not burning yet we need a hohlraum to ignite if(!burning && hasHohlraum) { vaporiseHohlraum(); } - injectFuel(); + //Only inject fuel if we're burning + if(burning) + { + injectFuel(); - int fuelBurned = burnFuel(); - neutronFlux(fuelBurned); + int fuelBurned = burnFuel(); + neutronFlux(fuelBurned); + } } else { burning = false; } - boilWater(); - ambientLoss(); + + //Perform the heat transfer calculations + transferHeat(); + + if(plasmaTemperature > 1E-6 || caseTemperature > 1E-6) + { + Mekanism.logger.info("Reactor temperatures: Plasma: " + (int) plasmaTemperature + ", Casing: " + (int) caseTemperature); + } } public void vaporiseHohlraum() { - fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuel"), 1000), true); + fuelTank.receive(new GasStack(GasRegistry.getGas("fusionFuelDT"), 10), true); + hasHohlraum = false; burning = true; } @@ -99,9 +138,9 @@ public class FusionReactor implements IFusionReactor public int burnFuel() { - int fuelBurned = (int)min(fuelTank.getStored(), max(0, temperature-burnTemperature)*burnRatio); + int fuelBurned = (int)min(fuelTank.getStored(), max(0, plasmaTemperature - burnTemperature)*burnRatio); fuelTank.draw(fuelBurned, true); - temperature += tempPerFuel * fuelBurned; + plasmaTemperature += tempPerFuel * fuelBurned; return fuelBurned; } @@ -120,14 +159,34 @@ public class FusionReactor implements IFusionReactor controller.radiateNeutrons(neutronsRemaining); } - public void boilWater() + public void transferHeat() { - int waterToBoil = (int)min(waterTank.getFluidAmount(), temperature*temperature*waterRatio); - } + //Transfer from plasma to casing + double plasmaCaseHeat = plasmaCaseConductivity * (plasmaTemperature - caseTemperature); + plasmaTemperature -= plasmaCaseHeat / plasmaHeatCapacity; + caseTemperature += plasmaCaseHeat / caseHeatCapacity; - public void ambientLoss() - { - temperature -= coolingCoefficient*temperature; + //Transfer from casing to water if necessary + if(activelyCooled) + { + 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())); + if(waterToVaporize > 0) + { + Mekanism.logger.info("Vaporising " + waterToVaporize + "mB of water"); + waterTank.drain(waterToVaporize, true); + steamTank.fill(new FluidStack(FluidRegistry.getFluid("steam"), waterToVaporize), true); + } + caseWaterHeat = waterToVaporize * enthalpyOfVaporization; + caseTemperature -= caseWaterHeat / caseHeatCapacity; + } + + //Transfer from casing to environment + double caseAirHeat = caseAirConductivity * caseTemperature; + caseTemperature -= caseAirHeat / caseHeatCapacity; + energyBuffer += caseAirHeat * thermocoupleEfficiency; } @Override @@ -159,4 +218,139 @@ public class FusionReactor implements IFusionReactor { return fuelTank; } + + public void unformMultiblock() + { + for(IReactorBlock block: reactorBlocks) + { + block.setReactor(null); + } + //Don't remove from controller + controller.setReactor(this); + reactorBlocks.clear(); + neutronCaptors.clear(); + formed = false; + } + + @Override + public void formMultiblock() + { + Mekanism.logger.trace("Attempting to form multiblock"); + + Coord4D controllerPosition = Coord4D.get(controller); + Coord4D centreOfReactor = controllerPosition.getFromSide(ForgeDirection.DOWN, 2); + + unformMultiblock(); + + reactorBlocks.add(controller); + + Mekanism.logger.trace("Centre at " + centreOfReactor.toString()); + if(!createFrame(centreOfReactor)) + { + unformMultiblock(); + Mekanism.logger.trace("Reactor failed: Frame not complete."); + return; + } + Mekanism.logger.trace("Frame valid"); + if(!addSides(centreOfReactor)) + { + unformMultiblock(); + Mekanism.logger.trace("Reactor failed: Sides not complete."); + return; + } + Mekanism.logger.trace("Side Blocks Valid"); + if(!centreIsClear(centreOfReactor)) + { + unformMultiblock(); + Mekanism.logger.trace("Blocks in chamber."); + return; + } + Mekanism.logger.trace("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; + } } diff --git a/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java b/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java index cb833cfb9..26c63f7c9 100644 --- a/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java +++ b/src/main/java/mekanism/generators/common/GeneratorsCommonProxy.java @@ -12,6 +12,13 @@ import mekanism.generators.common.tile.TileEntityHeatGenerator; import mekanism.generators.common.tile.TileEntityGasGenerator; import mekanism.generators.common.tile.TileEntitySolarGenerator; import mekanism.generators.common.tile.TileEntityWindTurbine; +import mekanism.generators.common.tile.reactor.TileEntityReactorController; +import mekanism.generators.common.tile.reactor.TileEntityReactorFrame; +import mekanism.generators.common.tile.reactor.TileEntityReactorGlass; +import mekanism.generators.common.tile.reactor.TileEntityReactorLaserFocusMatrix; +import mekanism.generators.common.tile.reactor.TileEntityReactorNeutronCapture; +import mekanism.generators.common.tile.reactor.TileEntityReactorPort; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.tileentity.TileEntity; @@ -25,6 +32,19 @@ import cpw.mods.fml.common.registry.GameRegistry; */ public class GeneratorsCommonProxy { + /** + * Register normal tile entities + */ + public void registerRegularTileEntities() + { + GameRegistry.registerTileEntity(TileEntityReactorController.class, "ReactorController"); + GameRegistry.registerTileEntity(TileEntityReactorFrame.class, "ReactorFrame"); + GameRegistry.registerTileEntity(TileEntityReactorGlass.class, "ReactorGlass"); + GameRegistry.registerTileEntity(TileEntityReactorLaserFocusMatrix.class, "ReactorLaserFocus"); + GameRegistry.registerTileEntity(TileEntityReactorNeutronCapture.class, "ReactorNeutronCapture"); + GameRegistry.registerTileEntity(TileEntityReactorPort.class, "ReactorPort"); + } + /** * Register tile entities that have special models. Overwritten in client to register TESRs. */ diff --git a/src/main/java/mekanism/generators/common/MekanismGenerators.java b/src/main/java/mekanism/generators/common/MekanismGenerators.java index 4df497504..496f9ca7b 100644 --- a/src/main/java/mekanism/generators/common/MekanismGenerators.java +++ b/src/main/java/mekanism/generators/common/MekanismGenerators.java @@ -15,6 +15,8 @@ import mekanism.common.recipe.MekanismRecipe; import mekanism.generators.common.block.BlockGenerator; import mekanism.generators.common.block.BlockReactor; import mekanism.generators.common.item.ItemBlockGenerator; +import mekanism.generators.common.item.ItemBlockReactor; + import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -96,6 +98,7 @@ public class MekanismGenerators implements IModule //Load the proxy proxy.loadConfiguration(); + proxy.registerRegularTileEntities(); proxy.registerSpecialTileEntities(); proxy.registerRenderInformation(); @@ -143,7 +146,7 @@ public class MekanismGenerators implements IModule Reactor = new BlockReactor().setBlockName("Reactor"); GameRegistry.registerBlock(Generator, ItemBlockGenerator.class, "Generator"); - GameRegistry.registerBlock(Reactor, "Reactor"); + GameRegistry.registerBlock(Reactor, ItemBlockReactor.class, "Reactor"); } public void addItems() diff --git a/src/main/java/mekanism/generators/common/block/BlockReactor.java b/src/main/java/mekanism/generators/common/block/BlockReactor.java index ddd522711..c8c768f65 100644 --- a/src/main/java/mekanism/generators/common/block/BlockReactor.java +++ b/src/main/java/mekanism/generators/common/block/BlockReactor.java @@ -16,6 +16,7 @@ import mekanism.common.util.MekanismUtils; import mekanism.generators.client.GeneratorsClientProxy; import mekanism.generators.common.MekanismGenerators; import mekanism.generators.common.tile.TileEntitySolarGenerator; +import mekanism.generators.common.tile.reactor.TileEntityReactorBlock; import mekanism.generators.common.tile.reactor.TileEntityReactorController; import mekanism.generators.common.tile.reactor.TileEntityReactorFrame; import mekanism.generators.common.tile.reactor.TileEntityReactorGlass; @@ -34,6 +35,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; @@ -47,6 +49,8 @@ import buildcraft.api.tools.IToolWrench; public class BlockReactor extends BlockContainer { + public IIcon[][] icons = new IIcon[16][16]; + public BlockReactor() { super(Material.iron); @@ -55,12 +59,87 @@ public class BlockReactor extends BlockContainer setCreativeTab(Mekanism.tabMekanism); } + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) + { + if(this == MekanismGenerators.Reactor) + { + icons[0][0] = register.registerIcon("mekanism:ReactorControllerOff"); + icons[0][1] = register.registerIcon("mekanism:ReactorControllerOn"); + icons[0][2] = register.registerIcon("mekanism:ReactorFrame"); + icons[1][0] = register.registerIcon("mekanism:ReactorFrame"); + icons[2][0] = register.registerIcon("mekanism:ReactorGlass"); + icons[3][0] = register.registerIcon("mekanism:ReactorLaserFocus"); + icons[4][0] = register.registerIcon("mekanism:ReactorNeutronCapture"); + icons[5][0] = register.registerIcon("mekanism:ReactorPort"); + } + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) + { + if(this == MekanismGenerators.Reactor) + { + if(meta == 0) + { + return icons[0][side == 6 ? 0 : 2]; + } + else + { + return icons[meta][0]; + } + } + + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) + { + int metadata = world.getBlockMetadata(x, y, z); + TileEntityReactorBlock tileEntity = (TileEntityReactorBlock)world.getTileEntity(x, y, z); + + if(this == MekanismGenerators.Reactor) + { + if(metadata == 0) + { + if(side == 1) + { + return MekanismUtils.isActive(world, x, y, z) ? icons[0][1] : icons[0][0]; + } + else { + return icons[0][2]; + } + } + else + { + return icons[metadata][0]; + } + } + + return null; + } + @Override public int damageDropped(int i) { return i; } + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ) + { + TileEntity tile = world.getTileEntity(x, y, z); + if(tile instanceof TileEntityReactorController) + { + ((TileEntityReactorController)tile).formMultiblock(); + } + return true; + } + @Override @SideOnly(Side.CLIENT) public void getSubBlocks(Item i, CreativeTabs creativetabs, List list) diff --git a/src/main/java/mekanism/generators/common/item/ItemBlockReactor.java b/src/main/java/mekanism/generators/common/item/ItemBlockReactor.java new file mode 100644 index 000000000..af0fd857e --- /dev/null +++ b/src/main/java/mekanism/generators/common/item/ItemBlockReactor.java @@ -0,0 +1,61 @@ +package mekanism.generators.common.item; + +import java.util.List; + +import mekanism.api.EnumColor; +import mekanism.common.util.MekanismUtils; +import mekanism.generators.common.block.BlockReactor.ReactorBlockType; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; + +public class ItemBlockReactor extends ItemBlock +{ + public Block metaBlock; + + public ItemBlockReactor(Block block) + { + super(block); + metaBlock = block; + setHasSubtypes(true); + } + + @Override + public int getMetadata(int i) + { + return i; + } + + @Override + public IIcon getIconFromDamage(int i) + { + return metaBlock.getIcon(2, i); + } + + @Override + public String getUnlocalizedName(ItemStack itemstack) + { + return getUnlocalizedName() + "." + ReactorBlockType.getFromMetadata(itemstack.getItemDamage()).name; + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) + { + ReactorBlockType type = ReactorBlockType.getFromMetadata(itemstack.getItemDamage()); + + if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + { + list.add(MekanismUtils.localize("tooltip.hold") + " " + EnumColor.INDIGO + "shift" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.forDetails") + "."); + } + else { + list.addAll(MekanismUtils.splitLines(type.getDescription())); + } + } +} diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java index 92af05136..174e653f2 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; +import mekanism.api.lasers.ILaserReceptor; import mekanism.common.Mekanism; import mekanism.common.util.ChargeUtils; import mekanism.common.util.FluidContainerUtils; @@ -27,7 +28,7 @@ import cpw.mods.fml.common.Optional.Method; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.peripheral.IComputerAccess; -public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler +public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler, ILaserReceptor { /** The FluidTank for this generator. */ public FluidTank lavaTank = new FluidTank(24000); @@ -335,4 +336,22 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu { return new FluidTankInfo[] {lavaTank.getInfo()}; } + + @Override + public void receiveLaserEnergy(double energy, ForgeDirection side) + { + setEnergy(getEnergy()+energy); + } + + @Override + public boolean canLasersDig() + { + return false; + } + + @Override + public double energyToDig() + { + return 0; + } } 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/TileEntityReactorController.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java index 32a98236a..1c98189e4 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorController.java @@ -1,5 +1,8 @@ package mekanism.generators.common.tile.reactor; +import mekanism.common.Mekanism; +import mekanism.generators.common.FusionReactor; + public class TileEntityReactorController extends TileEntityReactorBlock { @Override @@ -11,4 +14,22 @@ public class TileEntityReactorController extends TileEntityReactorBlock public void radiateNeutrons(int neutrons) { } + + public void formMultiblock() + { + if(getReactor() == null) + { + setReactor(new FusionReactor(this)); + } + getReactor().formMultiblock(); + } + + @Override + public void updateEntity() + { + if(getReactor() != null && !worldObj.isRemote) + { + getReactor().simulate(); + } + } } diff --git a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLaserFocusMatrix.java b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLaserFocusMatrix.java index 61404a41c..8fd162d35 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLaserFocusMatrix.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorLaserFocusMatrix.java @@ -7,8 +7,6 @@ import net.minecraftforge.common.util.ForgeDirection; public class TileEntityReactorLaserFocusMatrix extends TileEntityReactorBlock implements ILaserReceptor { - public IFusionReactor fusionReactor; - @Override public boolean isFrame() { @@ -18,7 +16,8 @@ public class TileEntityReactorLaserFocusMatrix extends TileEntityReactorBlock im @Override public void receiveLaserEnergy(double energy, ForgeDirection side) { - fusionReactor.addTemperature(energy); + if(getReactor() != null) + getReactor().addTemperatureFromEnergyInput(energy); } @Override 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 cc6d3ed32..2773d98d4 100644 --- a/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java +++ b/src/main/java/mekanism/generators/common/tile/reactor/TileEntityReactorPort.java @@ -4,6 +4,7 @@ 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 net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -12,7 +13,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -public class TileEntityReactorPort extends TileEntityReactorBlock implements IFluidHandler, IGasHandler +public class TileEntityReactorPort extends TileEntityReactorBlock implements IFluidHandler, IGasHandler, ITubeConnection { @Override public boolean isFrame() @@ -45,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; } @@ -85,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); } @@ -110,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 @@ -118,4 +119,10 @@ public class TileEntityReactorPort extends TileEntityReactorBlock implements IFl { return (type == GasRegistry.getGas("steam")); } + + @Override + public boolean canTubeConnect(ForgeDirection side) + { + return getReactor() != null; + } } \ No newline at end of file diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOff.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOff.png new file mode 100644 index 000000000..e2f20767e Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOff.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOn.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOn.png new file mode 100644 index 000000000..0de13b514 Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorControllerOn.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorFrame.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorFrame.png new file mode 100644 index 000000000..dd31e613d Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorFrame.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorGlass.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorGlass.png new file mode 100644 index 000000000..8a7b4dcde Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorGlass.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorLaserFocus.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorLaserFocus.png new file mode 100644 index 000000000..464779cb9 Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorLaserFocus.png differ diff --git a/src/main/resources/assets/mekanism/textures/blocks/ReactorPort.png b/src/main/resources/assets/mekanism/textures/blocks/ReactorPort.png new file mode 100644 index 000000000..bafa1a584 Binary files /dev/null and b/src/main/resources/assets/mekanism/textures/blocks/ReactorPort.png differ