Improve temperature colours to allow for different base colours.
Make a start on insulation. Code the characteristics of air into static IHeatTransfer variables.
This commit is contained in:
parent
7214a88a7a
commit
ab2a7cb6c7
6 changed files with 92 additions and 32 deletions
|
@ -4,15 +4,23 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
public interface IHeatTransfer
|
||||
{
|
||||
/**The value of the zero point of our temperature scale in kelvin*/
|
||||
public static final double AMBIENT_TEMP = 300;
|
||||
|
||||
/**The heat transfer coefficient for air*/
|
||||
public static final double AIR_INVERSE_COEFFICIENT = 10000;
|
||||
|
||||
public double getTemp();
|
||||
|
||||
public double getInverseConductionCoefficient();
|
||||
|
||||
public double getInsulationCoefficient(ForgeDirection side);
|
||||
|
||||
public void transferHeatTo(double heat);
|
||||
|
||||
public double[] simulateHeat();
|
||||
|
||||
public double applyTemperatureChange();
|
||||
|
||||
public boolean isInsulated(ForgeDirection side);
|
||||
public boolean canConnectHeat(ForgeDirection side);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package mekanism.client.render;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import mekanism.api.IHeatTransfer;
|
||||
|
||||
import codechicken.lib.colour.ColourRGBA;
|
||||
|
||||
public class ColourTemperature extends ColourRGBA
|
||||
|
@ -16,65 +18,75 @@ public class ColourTemperature extends ColourRGBA
|
|||
temp = t;
|
||||
}
|
||||
|
||||
public static ColourTemperature fromTemperature(double temperature)
|
||||
public static ColourTemperature fromTemperature(double temperature, ColourRGBA baseColour)
|
||||
{
|
||||
temperature += 300;
|
||||
temperature = temperature / 100;
|
||||
|
||||
if(cache.containsKey((int)temperature))
|
||||
if(temperature < 0)
|
||||
{
|
||||
return cache.get((int)temperature);
|
||||
double alphaBlend = -temperature/IHeatTransfer.AMBIENT_TEMP;
|
||||
if(alphaBlend < 0)
|
||||
alphaBlend = 0;
|
||||
if(alphaBlend > 1)
|
||||
alphaBlend = 1;
|
||||
return new ColourTemperature(1, 1, 1, alphaBlend, temperature).blendOnto(baseColour);
|
||||
}
|
||||
double absTemp = temperature + IHeatTransfer.AMBIENT_TEMP;
|
||||
absTemp /= 100;
|
||||
|
||||
if(cache.containsKey((int)absTemp))
|
||||
{
|
||||
return cache.get((int)absTemp).blendOnto(baseColour);
|
||||
}
|
||||
|
||||
double tmpCalc;
|
||||
double red, green, blue, alpha;
|
||||
double effectiveTemp = absTemp;
|
||||
|
||||
if(temperature < 10)
|
||||
temperature = 10;
|
||||
if(temperature > 400)
|
||||
temperature = 400;
|
||||
if(effectiveTemp < 10)
|
||||
effectiveTemp = 10;
|
||||
if(effectiveTemp > 400)
|
||||
effectiveTemp = 400;
|
||||
|
||||
if(temperature <= 66)
|
||||
if(effectiveTemp <= 66)
|
||||
{
|
||||
red = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpCalc = temperature - 60;
|
||||
tmpCalc = effectiveTemp - 60;
|
||||
tmpCalc = 329.698727446 * Math.pow(tmpCalc,-0.1332047592);
|
||||
red = tmpCalc/255D;
|
||||
}
|
||||
|
||||
if(temperature <= 66)
|
||||
if(effectiveTemp <= 66)
|
||||
{
|
||||
tmpCalc = temperature;
|
||||
tmpCalc = effectiveTemp;
|
||||
tmpCalc = 99.4708025861 * Math.log(tmpCalc) - 161.1195681661;
|
||||
green = tmpCalc/255D;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpCalc = temperature - 60;
|
||||
tmpCalc = effectiveTemp - 60;
|
||||
tmpCalc = 288.1221695283 * Math.pow(tmpCalc, -0.0755148492);
|
||||
green = tmpCalc/255D;
|
||||
}
|
||||
|
||||
if(temperature >= 66)
|
||||
if(effectiveTemp >= 66)
|
||||
{
|
||||
blue = 1;
|
||||
}
|
||||
else if(temperature <= 19)
|
||||
else if(effectiveTemp <= 19)
|
||||
{
|
||||
blue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpCalc = temperature - 10;
|
||||
tmpCalc = effectiveTemp - 10;
|
||||
tmpCalc = 138.5177312231 * Math.log(tmpCalc) - 305.0447927307;
|
||||
|
||||
blue = tmpCalc / 255D;
|
||||
}
|
||||
|
||||
alpha = (temperature - 3)/10;
|
||||
alpha = temperature/1000;
|
||||
|
||||
if(red < 0) red = 0;
|
||||
if(red > 1) red = 1;
|
||||
|
@ -88,10 +100,23 @@ public class ColourTemperature extends ColourRGBA
|
|||
if(alpha < 0) alpha = 0;
|
||||
if(alpha > 1) alpha = 1;
|
||||
|
||||
ColourTemperature colourTemperature = new ColourTemperature(red, green, blue, alpha, temperature*100-300);
|
||||
ColourTemperature colourTemperature = new ColourTemperature(red, green, blue, alpha, temperature);
|
||||
|
||||
cache.put((int)(temperature), colourTemperature);
|
||||
cache.put((int)(absTemp), colourTemperature);
|
||||
|
||||
return colourTemperature;
|
||||
return colourTemperature.blendOnto(baseColour);
|
||||
}
|
||||
|
||||
public ColourTemperature blendOnto(ColourRGBA baseColour)
|
||||
{
|
||||
double sR = (r & 0xFF)/255D, sG = (g & 0xFF)/255D, sB = (b & 0xFF)/255D, sA = (a & 0xFF)/255D;
|
||||
double dR = (baseColour.r & 0xFF)/255D, dG = (baseColour.g & 0xFF)/255D, dB = (baseColour.b & 0xFF)/255D, dA = (baseColour.a & 0xFF)/255D;
|
||||
|
||||
double rR = sR * sA + dR * (1-sA);
|
||||
double rG = sG * sA + dG * (1-sA);
|
||||
double rB = sB * sA + dB * (1-sA);
|
||||
double rA = dA * 1D + sA * (1-dA);
|
||||
|
||||
return new ColourTemperature(rR, rG, rB, rA, temp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -556,7 +556,7 @@ public class RenderPartTransmitter implements IIconSelfRegister
|
|||
public void renderHeatSide(ForgeDirection side, PartHeatTransmitter cable)
|
||||
{
|
||||
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());
|
||||
renderTransparency(MekanismRenderer.heatIcon, cable.getModelForSide(side, true), ColourTemperature.fromTemperature(cable.temperature));
|
||||
renderTransparency(MekanismRenderer.heatIcon, cable.getModelForSide(side, true), ColourTemperature.fromTemperature(cable.temperature, cable.getBaseColour()));
|
||||
}
|
||||
|
||||
public void renderFluidInOut(ForgeDirection side, PartMechanicalPipe pipe)
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import codechicken.lib.colour.ColourRGBA;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
|
@ -29,8 +30,12 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
|
||||
public double inversek = 5;
|
||||
|
||||
public double insulationInversek = 0;
|
||||
|
||||
public double inverseHeatCapacity = 1;
|
||||
|
||||
public ColourRGBA baseColour = new ColourRGBA(0.2, 0.2, 0.2, 1);
|
||||
|
||||
public double heatToAbsorb = 0;
|
||||
|
||||
public static TransmitterIcons heatIcons = new TransmitterIcons(1, 2);
|
||||
|
@ -89,6 +94,12 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
return inversek;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInsulationCoefficient(ForgeDirection side)
|
||||
{
|
||||
return insulationInversek;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferHeatTo(double heat)
|
||||
{
|
||||
|
@ -118,7 +129,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
}
|
||||
}
|
||||
//Transfer to air otherwise
|
||||
double heatToTransfer = getTemp() / (10000+getInverseConductionCoefficient());
|
||||
double heatToTransfer = getTemp() / (IHeatTransfer.AIR_INVERSE_COEFFICIENT+getInsulationCoefficient(side)+getInverseConductionCoefficient());
|
||||
transferHeatTo(-heatToTransfer);
|
||||
heatTransferred[1] += heatToTransfer;
|
||||
}
|
||||
|
@ -139,9 +150,9 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsulated(ForgeDirection side)
|
||||
public boolean canConnectHeat(ForgeDirection side)
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void registerIcons(IIconRegister register)
|
||||
|
@ -177,7 +188,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
@Override
|
||||
public boolean isValidAcceptor(TileEntity tile, ForgeDirection side)
|
||||
{
|
||||
return tile instanceof IHeatTransfer && !((IHeatTransfer)tile).isInsulated(side.getOpposite());
|
||||
return tile instanceof IHeatTransfer && ((IHeatTransfer)tile).canConnectHeat(side.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -252,4 +263,9 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
|
|||
}
|
||||
}
|
||||
|
||||
public ColourRGBA getBaseColour()
|
||||
{
|
||||
return baseColour;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
5
src/main/java/mekanism/common/util/HeatUtils.java
Normal file
5
src/main/java/mekanism/common/util/HeatUtils.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package mekanism.common.util;
|
||||
|
||||
public class HeatUtils
|
||||
{
|
||||
}
|
|
@ -389,6 +389,12 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInsulationCoefficient(ForgeDirection side)
|
||||
{
|
||||
return canConnectHeat(side) ? 0 : 10000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferHeatTo(double heat)
|
||||
{
|
||||
|
@ -403,7 +409,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 && !isInsulated(side))
|
||||
if(canConnectHeat(side) && tileEntity instanceof IHeatTransfer)
|
||||
{
|
||||
IHeatTransfer sink = (IHeatTransfer)tileEntity;
|
||||
double invConduction = sink.getInverseConductionCoefficient() + getInverseConductionCoefficient();
|
||||
|
@ -415,7 +421,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
|
|||
continue;
|
||||
}
|
||||
//Transfer to air otherwise
|
||||
double heatToTransfer = getTemp() / (10000+getInverseConductionCoefficient());
|
||||
double heatToTransfer = getTemp() / (IHeatTransfer.AIR_INVERSE_COEFFICIENT+getInverseConductionCoefficient());
|
||||
transferHeatTo(-heatToTransfer);
|
||||
heatTransferred[1] += heatToTransfer;
|
||||
}
|
||||
|
@ -434,8 +440,8 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsulated(ForgeDirection side)
|
||||
public boolean canConnectHeat(ForgeDirection side)
|
||||
{
|
||||
return side != ForgeDirection.DOWN;
|
||||
return side == ForgeDirection.DOWN;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue