Fusion reactor NBT save/load, and a first attempt at plasma render. Fusion reactor is basically finished at this point.
This commit is contained in:
parent
d7c060d6fb
commit
a6ff4750e4
8 changed files with 217 additions and 12 deletions
|
@ -197,7 +197,7 @@ public class GasTank
|
|||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(stored != null)
|
||||
if(stored != null && stored.getGas() != null)
|
||||
{
|
||||
nbtTags.setTag("stored", stored.write(new NBTTagCompound()));
|
||||
}
|
||||
|
|
|
@ -41,4 +41,8 @@ public interface IFusionReactor
|
|||
public void setInjectionRate(int rate);
|
||||
|
||||
public int getInjectionRate();
|
||||
|
||||
public boolean isBurning();
|
||||
|
||||
public void setBurning(boolean burn);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import mekanism.generators.client.render.RenderAdvancedSolarGenerator;
|
|||
import mekanism.generators.client.render.RenderBioGenerator;
|
||||
import mekanism.generators.client.render.RenderHeatGenerator;
|
||||
import mekanism.generators.client.render.RenderGasGenerator;
|
||||
import mekanism.generators.client.render.RenderReactor;
|
||||
import mekanism.generators.client.render.RenderSolarGenerator;
|
||||
import mekanism.generators.client.render.RenderWindTurbine;
|
||||
import mekanism.generators.common.GeneratorsCommonProxy;
|
||||
|
@ -48,6 +49,7 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy
|
|||
ClientRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator", new RenderHeatGenerator());
|
||||
ClientRegistry.registerTileEntity(TileEntityGasGenerator.class, "GasGenerator", new RenderGasGenerator());
|
||||
ClientRegistry.registerTileEntity(TileEntityWindTurbine.class, "WindTurbine", new RenderWindTurbine());
|
||||
ClientRegistry.registerTileEntity(TileEntityReactorController.class, "ReactorController", new RenderReactor());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package mekanism.generators.client.render;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.client.MekanismClient;
|
||||
import mekanism.client.model.ModelEnergyCube.ModelEnergyCore;
|
||||
import mekanism.client.model.ModelLaser;
|
||||
import mekanism.client.render.MekanismRenderer;
|
||||
import mekanism.common.Tier.EnergyCubeTier;
|
||||
import mekanism.common.tile.TileEntityLaser;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.generators.common.tile.reactor.TileEntityReactorController;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class RenderReactor extends TileEntitySpecialRenderer
|
||||
{
|
||||
private ModelEnergyCore core = new ModelEnergyCore();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
||||
{
|
||||
renderAModelAt((TileEntityReactorController)tileEntity, x, y, z, partialTick);
|
||||
}
|
||||
|
||||
private void renderAModelAt(TileEntityReactorController tileEntity, double x, double y, double z, float partialTick)
|
||||
{
|
||||
if(tileEntity.isBurning())
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y - 1.5, z + 0.5);
|
||||
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "EnergyCore.png"));
|
||||
|
||||
MekanismRenderer.blendOn();
|
||||
MekanismRenderer.glowOn();
|
||||
|
||||
EnumColor c;
|
||||
double scale;
|
||||
long scaledTemp = Math.round(tileEntity.getPlasmaTemp() / 1E8);
|
||||
|
||||
c = EnumColor.AQUA;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
scale = 1 + 0.7 * Math.sin(Math.toRadians((MekanismClient.ticksPassed + partialTick) * 3.14 * scaledTemp + 135F));
|
||||
GL11.glScaled(scale, scale, scale);
|
||||
GL11.glColor4f(c.getColor(0), c.getColor(1), c.getColor(2), 1);
|
||||
GL11.glRotatef((MekanismClient.ticksPassed + partialTick) * -6 * scaledTemp, 0, 1, 0);
|
||||
GL11.glRotatef(36F + (MekanismClient.ticksPassed + partialTick) * -7 * scaledTemp, 0, 1, 1);
|
||||
core.render(0.0625F);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
c = EnumColor.RED;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
scale = 1 + 0.8 * Math.sin(Math.toRadians((MekanismClient.ticksPassed + partialTick) * 3 * scaledTemp));
|
||||
GL11.glScaled(scale, scale, scale);
|
||||
GL11.glColor4f(c.getColor(0), c.getColor(1), c.getColor(2), 1);
|
||||
GL11.glRotatef((MekanismClient.ticksPassed + partialTick) * 4 * scaledTemp, 0, 1, 0);
|
||||
GL11.glRotatef(36F + (MekanismClient.ticksPassed + partialTick) * 4 * scaledTemp, 0, 1, 1);
|
||||
core.render(0.0625F);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
c = EnumColor.ORANGE;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
scale = 1 - 0.9 * Math.sin(Math.toRadians((MekanismClient.ticksPassed + partialTick) * 4 * scaledTemp + 90F));
|
||||
GL11.glScaled(scale, scale, scale);
|
||||
GL11.glColor4f(c.getColor(0), c.getColor(1), c.getColor(2), 1);
|
||||
GL11.glRotatef((MekanismClient.ticksPassed + partialTick) * 5 * scaledTemp - 35F, 0, 1, 0);
|
||||
GL11.glRotatef(36F + (MekanismClient.ticksPassed + partialTick) * -3 * scaledTemp + 70F, 0, 1, 1);
|
||||
core.render(0.0625F);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
MekanismRenderer.glowOff();
|
||||
MekanismRenderer.blendOff();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -419,4 +419,15 @@ public class FusionReactor implements IFusionReactor
|
|||
return injectionRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBurning()
|
||||
{
|
||||
return burning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBurning(boolean burn)
|
||||
{
|
||||
burning = burn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ public class GeneratorsCommonProxy
|
|||
*/
|
||||
public void registerRegularTileEntities()
|
||||
{
|
||||
GameRegistry.registerTileEntity(TileEntityReactorController.class, "ReactorController");
|
||||
GameRegistry.registerTileEntity(TileEntityReactorFrame.class, "ReactorFrame");
|
||||
GameRegistry.registerTileEntity(TileEntityReactorGlass.class, "ReactorGlass");
|
||||
GameRegistry.registerTileEntity(TileEntityReactorLaserFocusMatrix.class, "ReactorLaserFocus");
|
||||
|
@ -59,6 +58,7 @@ public class GeneratorsCommonProxy
|
|||
GameRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator");
|
||||
GameRegistry.registerTileEntity(TileEntityGasGenerator.class, "GasGenerator");
|
||||
GameRegistry.registerTileEntity(TileEntityWindTurbine.class, "WindTurbine");
|
||||
GameRegistry.registerTileEntity(TileEntityReactorController.class, "ReactorController");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,13 +55,13 @@ public class BlockReactor extends BlockContainer
|
|||
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:ReactorLaserFocus");
|
||||
icons[3][0] = register.registerIcon("mekanism:ReactorNeutronCapture");
|
||||
icons[4][0] = register.registerIcon("mekanism:ReactorPort");
|
||||
icons[2][0] = register.registerIcon("mekanism:ReactorNeutronCapture");
|
||||
icons[3][0] = register.registerIcon("mekanism:ReactorPort");
|
||||
}
|
||||
else if(this == MekanismGenerators.ReactorGlass)
|
||||
{
|
||||
icons[0][0] = register.registerIcon("mekanism:ReactorGlass");
|
||||
icons[1][0] = register.registerIcon("mekanism:ReactorLaserFocus");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,6 @@ public class BlockReactor extends BlockContainer
|
|||
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)
|
||||
{
|
||||
|
@ -259,10 +258,10 @@ public class BlockReactor extends BlockContainer
|
|||
{
|
||||
CONTROLLER(MekanismGenerators.Reactor, 0, "ReactorController", 10, TileEntityReactorController.class),
|
||||
FRAME(MekanismGenerators.Reactor, 1, "ReactorFrame", -1, TileEntityReactorFrame.class),
|
||||
LASER_FOCUS_MATRIX(MekanismGenerators.Reactor, 2, "ReactorLaserFocusMatrix", -1, TileEntityReactorLaserFocusMatrix.class),
|
||||
NEUTRON_CAPTURE(MekanismGenerators.Reactor, 3, "ReactorNeutronCapturePlate", 13, TileEntityReactorNeutronCapture.class),
|
||||
PORT(MekanismGenerators.Reactor, 4, "ReactorInOutPort", -1, TileEntityReactorPort.class),
|
||||
GLASS(MekanismGenerators.ReactorGlass, 0, "ReactorGlass", -1, TileEntityReactorGlass.class);
|
||||
NEUTRON_CAPTURE(MekanismGenerators.Reactor, 2, "ReactorNeutronCapturePlate", 13, TileEntityReactorNeutronCapture.class),
|
||||
PORT(MekanismGenerators.Reactor, 3, "ReactorInOutPort", -1, TileEntityReactorPort.class),
|
||||
GLASS(MekanismGenerators.ReactorGlass, 0, "ReactorGlass", -1, TileEntityReactorGlass.class),
|
||||
LASER_FOCUS_MATRIX(MekanismGenerators.ReactorGlass, 1, "ReactorLaserFocusMatrix", -1, TileEntityReactorLaserFocusMatrix.class);
|
||||
|
||||
public Block typeBlock;
|
||||
public int meta;
|
||||
|
|
|
@ -2,20 +2,27 @@ package mekanism.generators.common.tile.reactor;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.common.IActiveState;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.generators.common.FusionReactor;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class TileEntityReactorController extends TileEntityReactorBlock implements IActiveState
|
||||
|
@ -32,6 +39,13 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
|
||||
public GasTank fuelTank = new GasTank(MAX_FUEL);
|
||||
|
||||
public AxisAlignedBB box;
|
||||
|
||||
public boolean tryForm = false;
|
||||
|
||||
public double clientTemp = 0;
|
||||
public boolean clientBurning = false;
|
||||
|
||||
public TileEntityReactorController()
|
||||
{
|
||||
super("ReactorController", 1000000000);
|
||||
|
@ -80,10 +94,75 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
{
|
||||
super.onUpdate();
|
||||
|
||||
if(getReactor() != null && getReactor().isFormed())
|
||||
if(isFormed())
|
||||
{
|
||||
getReactor().simulate();
|
||||
if(!worldObj.isRemote && (getReactor().isBurning() != clientBurning || Math.abs(getReactor().getPlasmaTemp() - clientTemp) > 1000000))
|
||||
{
|
||||
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
|
||||
clientBurning = getReactor().isBurning();
|
||||
clientTemp = getReactor().getPlasmaTemp();
|
||||
}
|
||||
}
|
||||
else if(tryForm && !worldObj.isRemote)
|
||||
{
|
||||
formMultiblock();
|
||||
tryForm = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setBoolean("formed", isFormed());
|
||||
|
||||
if(isFormed())
|
||||
{
|
||||
tag.setDouble("plasmaTemp", getReactor().getPlasmaTemp());
|
||||
tag.setDouble("caseTemp", getReactor().getCaseTemp());
|
||||
tag.setInteger("injectionRate", getReactor().getInjectionRate());
|
||||
tag.setBoolean("burning", getReactor().isBurning());
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.setDouble("plasmaTemp", 0);
|
||||
tag.setDouble("caseTemp", 0);
|
||||
tag.setInteger("injectionRate", 0);
|
||||
tag.setBoolean("burning", false);
|
||||
}
|
||||
|
||||
tag.setTag("fuelTank", fuelTank.write(new NBTTagCompound()));
|
||||
tag.setTag("deuteriumTank", deuteriumTank.write(new NBTTagCompound()));
|
||||
tag.setTag("tritiumTank", tritiumTank.write(new NBTTagCompound()));
|
||||
tag.setTag("waterTank", waterTank.writeToNBT(new NBTTagCompound()));
|
||||
tag.setTag("steamTank", steamTank.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT(tag);
|
||||
|
||||
boolean formed = tag.getBoolean("formed");
|
||||
|
||||
if(formed)
|
||||
{
|
||||
tryForm = true;
|
||||
setReactor(new FusionReactor(this));
|
||||
getReactor().setPlasmaTemp(tag.getDouble("plasmaTemp"));
|
||||
getReactor().setCaseTemp(tag.getDouble("caseTemp"));
|
||||
getReactor().setInjectionRate(tag.getInteger("injectionRate"));
|
||||
getReactor().setBurning(tag.getBoolean("burning"));
|
||||
}
|
||||
|
||||
fuelTank.read(tag.getCompoundTag("fuelTank"));
|
||||
deuteriumTank.read(tag.getCompoundTag("deuteriumTank"));
|
||||
tritiumTank.read(tag.getCompoundTag("tritiumTank"));
|
||||
waterTank.readFromNBT(tag.getCompoundTag("waterTank"));
|
||||
steamTank.readFromNBT(tag.getCompoundTag("steamTank"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,6 +176,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
data.add(getReactor().getPlasmaTemp());
|
||||
data.add(getReactor().getCaseTemp());
|
||||
data.add(getReactor().getInjectionRate());
|
||||
data.add(getReactor().isBurning());
|
||||
data.add(fuelTank.getStored());
|
||||
data.add(deuteriumTank.getStored());
|
||||
data.add(tritiumTank.getStored());
|
||||
|
@ -140,6 +220,7 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
getReactor().setPlasmaTemp(dataStream.readDouble());
|
||||
getReactor().setCaseTemp(dataStream.readDouble());
|
||||
getReactor().setInjectionRate(dataStream.readInt());
|
||||
getReactor().setBurning(dataStream.readBoolean());
|
||||
fuelTank.setGas(new GasStack(GasRegistry.getGas("fusionFuelDT"), dataStream.readInt()));
|
||||
deuteriumTank.setGas(new GasStack(GasRegistry.getGas("deuterium"), dataStream.readInt()));
|
||||
tritiumTank.setGas(new GasStack(GasRegistry.getGas("tritium"), dataStream.readInt()));
|
||||
|
@ -154,10 +235,20 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isFormed()
|
||||
{
|
||||
return getReactor() != null && getReactor().isFormed();
|
||||
}
|
||||
|
||||
public boolean isBurning()
|
||||
{
|
||||
return getActive() && getReactor().isBurning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive()
|
||||
{
|
||||
return getReactor() != null && getReactor().isFormed();
|
||||
return isFormed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,4 +271,15 @@ public class TileEntityReactorController extends TileEntityReactorBlock implemen
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
if(box == null)
|
||||
{
|
||||
box = AxisAlignedBB.getBoundingBox(xCoord-1, yCoord-3, zCoord-1, xCoord+2, yCoord, zCoord+2);
|
||||
}
|
||||
return box;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue