Cleaned up Heating code for thermal couple

This commit is contained in:
DarkGuardsman 2013-10-23 08:58:39 -04:00
parent cbba4fe310
commit c38354b890
5 changed files with 38 additions and 26 deletions

View file

@ -7,7 +7,7 @@ import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.Pair;
/** Information about block not provided by minecraft such as density, mass, volume, tempature, etc
/** Information about blocks not provided by minecraft such as density, mass, volume, heating values, chemical properties, etc
* etc
*
* @author DarkGuardsman */

View file

@ -1,16 +1,19 @@
package dark.api.energy;
import dark.api.parts.ITileConnector;
import net.minecraftforge.common.ForgeDirection;
/** Used by TileEntities or Entities to show heat stored and cooling rate of the object
*
* @author DarkGuardsman */
public interface IHeatObject
public interface IHeatObject extends ITileConnector
{
/** Amount of heat stored in the body of the object
/** Amount of heat stored in the body of the object. Think of it as a battery for heat but
* remember that heat is lost very fast
*
* @return amount of heat in generic units */
public double getHeat(ForgeDirection side);
public float getHeat(ForgeDirection side);
/** Sets the heat level of the object or increase it
*
@ -18,6 +21,7 @@ public interface IHeatObject
* @param incrase - true if should increase the current heat level */
public void setHeat(double amount, boolean incrase);
/** Rate by which this object can cool by from the given side */
public double getCoolingRate(ForgeDirection side);
/** Rate by which this object can cool by from the given side. Generally is decided by the blocks
* next to it and the biome the block is in. Is a self heat loss value. */
public float getCoolingRate(ForgeDirection side);
}

View file

@ -1,12 +0,0 @@
package dark.api.energy;
import net.minecraftforge.common.ForgeDirection;
public interface IHeatProducer
{
/** Checks too see if this can produce heat */
public boolean getCanProduceHeat(ForgeDirection dir);
/** Gets the amount of heat in joules this can output */
public float getHeatAmmount(ForgeDirection dir);
}

View file

@ -16,6 +16,7 @@ public interface ITileConnector
ITEMS(),
DATA(),
TILE(),
NETWORK();
NETWORK(),
HEAT();
}
}

View file

@ -5,7 +5,8 @@ import java.util.EnumSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import dark.api.energy.IHeatProducer;
import dark.api.energy.IHeatObject;
import dark.api.parts.ITileConnector.Connection;
import dark.core.prefab.machine.TileEntityEnergyMachine;
/** Machine that turns heat into usable electrical energy
@ -16,6 +17,7 @@ public class TileEntityHeatCouple extends TileEntityEnergyMachine
protected float tempture = 0.0f;
protected float outputWatts = 0f;
protected float heatJoules = 0f;
protected float maxHeat = 1000f;
@Override
public void updateEntity()
@ -30,9 +32,26 @@ public class TileEntityHeatCouple extends TileEntityEnergyMachine
{
Vector3 loc = new Vector3(this).translate(new Vector3(side));
TileEntity entity = loc.getTileEntity(this.worldObj);
if (entity instanceof IHeatProducer && ((IHeatProducer) entity).getCanProduceHeat(side.getOpposite()))
if (entity instanceof IHeatObject && ((IHeatObject) entity).canTileConnect(Connection.HEAT, side.getOpposite()))
{
this.heatJoules = ((IHeatProducer) entity).getHeatAmmount(side.getOpposite());
if (this.heatJoules < this.maxHeat)
{
float heat = ((IHeatObject) entity).getHeat(side.getOpposite());
if (heat + heatJoules <= maxHeat)
{
this.heatJoules += heat;
((IHeatObject) entity).setHeat(-heat, true);
}
else
{
float room = (heat - ((this.heatJoules + heat) - this.maxHeat));
if (room > 0)
{
this.heatJoules += room;
((IHeatObject) entity).setHeat(-room, true);
}
}
}
}
}
this.outputWatts = heatJoules * .4f;