Improve Heat mechanic, and get it rendering nicely.

Colour temperature algorithm adapted from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/ - thanks to Tanner Hellan for the useful post.
This commit is contained in:
Ben Spiers 2014-12-20 02:09:14 +00:00
parent 2bd2e94c7b
commit 4a404dfc78
9 changed files with 216 additions and 6 deletions

View file

@ -0,0 +1,97 @@
package mekanism.client.render;
import java.util.HashMap;
import codechicken.lib.colour.ColourRGBA;
public class ColourTemperature extends ColourRGBA
{
public static HashMap<Integer, ColourTemperature> cache = new HashMap<Integer, ColourTemperature>();
public double temp;
public ColourTemperature(double r, double g, double b, double a, double t)
{
super(r, g, b, a);
temp = t;
}
public static ColourTemperature fromTemperature(double temperature)
{
temperature += 300;
temperature = temperature / 100;
if(cache.containsKey((int)temperature))
{
return cache.get((int)temperature);
}
double tmpCalc;
double red, green, blue, alpha;
if(temperature < 10)
temperature = 10;
if(temperature > 400)
temperature = 400;
if(temperature <= 66)
{
red = 1;
}
else
{
tmpCalc = temperature - 60;
tmpCalc = 329.698727446 * Math.pow(tmpCalc,-0.1332047592);
red = tmpCalc/255D;
}
if(temperature <= 66)
{
tmpCalc = temperature;
tmpCalc = 99.4708025861 * Math.log(tmpCalc) - 161.1195681661;
green = tmpCalc/255D;
}
else
{
tmpCalc = temperature - 60;
tmpCalc = 288.1221695283 * Math.pow(tmpCalc, -0.0755148492);
green = tmpCalc/255D;
}
if(temperature >= 66)
{
blue = 1;
}
else if(temperature <= 19)
{
blue = 0;
}
else
{
tmpCalc = temperature - 10;
tmpCalc = 138.5177312231 * Math.log(tmpCalc) - 305.0447927307;
blue = tmpCalc / 255D;
}
alpha = (temperature - 3)/10;
if(red < 0) red = 0;
if(red > 1) red = 1;
if(green < 0) green = 0;
if(green > 1) green = 1;
if(blue < 0) blue = 0;
if(blue > 1) blue = 1;
if(alpha < 0) alpha = 0;
if(alpha > 1) alpha = 1;
ColourTemperature colourTemperature = new ColourTemperature(red, green, blue, alpha, temperature*100-300);
cache.put((int)(temperature), colourTemperature);
return colourTemperature;
}
}

View file

@ -50,6 +50,7 @@ public class MekanismRenderer
public static IIcon[] colors = new IIcon[256];
public static IIcon energyIcon;
public static IIcon heatIcon;
private static float lightmapLastX;
private static float lightmapLastY;
@ -73,6 +74,7 @@ public class MekanismRenderer
}
energyIcon = event.map.registerIcon("mekanism:LiquidEnergy");
heatIcon = event.map.registerIcon("mekanism:LiquidHeat");
GasRegistry.getGas("hydrogen").setIcon(event.map.registerIcon("mekanism:LiquidHydrogen"));
GasRegistry.getGas("oxygen").setIcon(event.map.registerIcon("mekanism:LiquidOxygen"));

View file

@ -260,6 +260,30 @@ public class RenderPartTransmitter implements IIconSelfRegister
pop();
}
public void renderContents(PartHeatTransmitter transmitter, Vector3 pos)
{
push();
CCRenderState.reset();
CCRenderState.useNormals = true;
CCRenderState.startDrawing();
GL11.glTranslated(pos.x, pos.y, pos.z);
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
renderHeatSide(side, transmitter);
}
MekanismRenderer.glowOn();
MekanismRenderer.cullFrontFace();
CCRenderState.draw();
MekanismRenderer.disableCullFace();
MekanismRenderer.glowOff();
pop();
}
public void renderContents(PartMechanicalPipe pipe, Vector3 pos)
{
float targetScale = pipe.getTransmitterNetwork().fluidScale;
@ -529,6 +553,12 @@ public class RenderPartTransmitter implements IIconSelfRegister
renderTransparency(MekanismRenderer.energyIcon, cable.getModelForSide(side, true), new ColourRGBA(1.0, 1.0, 1.0, cable.currentPower));
}
public void renderHeatSide(ForgeDirection side, PartHeatTransmitter cable)
{
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());
renderTransparency(MekanismRenderer.heatIcon, cable.getModelForSide(side, true), ColourTemperature.fromTemperature(cable.temperature));
}
public void renderFluidInOut(ForgeDirection side, PartMechanicalPipe pipe)
{
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());

View file

@ -55,6 +55,14 @@ public class ItemNetworkReader extends ItemEnergized
return true;
}
else if(tileEntity instanceof IHeatTransfer)
{
player.addChatMessage(new ChatComponentText(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------"));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Temperature: " + EnumColor.DARK_GREY + ((IHeatTransfer)tileEntity).getTemp() + "K above ambient"));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------"));
return true;
}
else if(tileEntity != null)
{
setEnergy(stack, getEnergy(stack)-ENERGY_PER_USE);

View file

@ -6,19 +6,28 @@ import mekanism.api.Coord4D;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HeatNetwork;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.vec.Vector3;
public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements IHeatTransfer
{
public double temperature = 0;
public double clientTemperature = 0;
public double inversek = 10;
public double inversek = 5;
public double inverseHeatCapacity = 1;
@ -121,6 +130,11 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
{
temperature += inverseHeatCapacity * heatToAbsorb;
heatToAbsorb = 0;
if(Math.abs(temperature - clientTemperature) > (temperature / 100))
{
clientTemperature = temperature;
sendTemp();
}
return temperature;
}
@ -132,7 +146,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
public static void registerIcons(IIconRegister register)
{
heatIcons.registerCenterIcons(register, new String[] {"UniversalCableBasic"});
heatIcons.registerCenterIcons(register, new String[] {"HeatTransmitter"});
heatIcons.registerSideIcons(register, new String[] {"SmallTransmitterVertical", "SmallTransmitterHorizontal"});
}
@ -181,7 +195,61 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
@Override
protected boolean onConfigure(EntityPlayer player, int part, int side)
{
temperature += 100;
temperature += 10000;
return true;
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float f, int pass)
{
if(pass == 0)
{
RenderPartTransmitter.getInstance().renderContents(this, pos);
}
}
@Override
public void load(NBTTagCompound nbtTags)
{
super.load(nbtTags);
temperature = nbtTags.getDouble("temperature");
}
@Override
public void save(NBTTagCompound nbtTags)
{
super.save(nbtTags);
nbtTags.setDouble("temperature", temperature);
}
public void sendTemp()
{
MCDataOutput packet = getWriteStream();
packet.writeBoolean(true);
packet.writeDouble(temperature);
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeBoolean(false);
super.writeDesc(packet);
}
@Override
public void readDesc(MCDataInput packet)
{
if(packet.readBoolean())
{
temperature = packet.readDouble();
}
else
{
super.readDesc(packet);
}
}
}

View file

@ -386,7 +386,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
@Override
public double getInverseConductionCoefficient()
{
return 10;
return 1;
}
@Override
@ -403,7 +403,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = pos.getFromSide(side).getTileEntity(getWorldObj());
if(tileEntity instanceof IHeatTransfer)
if(tileEntity instanceof IHeatTransfer && !isInsulated(side))
{
IHeatTransfer sink = (IHeatTransfer)tileEntity;
double invConduction = sink.getInverseConductionCoefficient() + getInverseConductionCoefficient();

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB