Cleaned up Heating code for thermal couple
This commit is contained in:
parent
cbba4fe310
commit
c38354b890
5 changed files with 38 additions and 26 deletions
|
@ -7,9 +7,9 @@ import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
import com.builtbroken.common.Pair;
|
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
|
* etc
|
||||||
*
|
*
|
||||||
* @author DarkGuardsman */
|
* @author DarkGuardsman */
|
||||||
public class ExtraBlockData
|
public class ExtraBlockData
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
package dark.api.energy;
|
package dark.api.energy;
|
||||||
|
|
||||||
|
import dark.api.parts.ITileConnector;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
/** Used by TileEntities or Entities to show heat stored and cooling rate of the object
|
/** Used by TileEntities or Entities to show heat stored and cooling rate of the object
|
||||||
*
|
*
|
||||||
* @author DarkGuardsman */
|
* @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 */
|
* @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
|
/** Sets the heat level of the object or increase it
|
||||||
*
|
*
|
||||||
* @param amount - amount to set or increase by
|
* @param amount - amount to set or increase by
|
||||||
* @param incrase - true if should increase the current heat level */
|
* @param incrase - true if should increase the current heat level */
|
||||||
public void setHeat(double amount, boolean incrase);
|
public void setHeat(double amount, boolean incrase);
|
||||||
|
|
||||||
/** Rate by which this object can cool by from the given side */
|
/** Rate by which this object can cool by from the given side. Generally is decided by the blocks
|
||||||
public double getCoolingRate(ForgeDirection side);
|
* next to it and the biome the block is in. Is a self heat loss value. */
|
||||||
|
public float getCoolingRate(ForgeDirection side);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -16,6 +16,7 @@ public interface ITileConnector
|
||||||
ITEMS(),
|
ITEMS(),
|
||||||
DATA(),
|
DATA(),
|
||||||
TILE(),
|
TILE(),
|
||||||
NETWORK();
|
NETWORK(),
|
||||||
|
HEAT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import java.util.EnumSet;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.core.vector.Vector3;
|
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;
|
import dark.core.prefab.machine.TileEntityEnergyMachine;
|
||||||
|
|
||||||
/** Machine that turns heat into usable electrical energy
|
/** Machine that turns heat into usable electrical energy
|
||||||
|
@ -16,6 +17,7 @@ public class TileEntityHeatCouple extends TileEntityEnergyMachine
|
||||||
protected float tempture = 0.0f;
|
protected float tempture = 0.0f;
|
||||||
protected float outputWatts = 0f;
|
protected float outputWatts = 0f;
|
||||||
protected float heatJoules = 0f;
|
protected float heatJoules = 0f;
|
||||||
|
protected float maxHeat = 1000f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
|
@ -30,9 +32,26 @@ public class TileEntityHeatCouple extends TileEntityEnergyMachine
|
||||||
{
|
{
|
||||||
Vector3 loc = new Vector3(this).translate(new Vector3(side));
|
Vector3 loc = new Vector3(this).translate(new Vector3(side));
|
||||||
TileEntity entity = loc.getTileEntity(this.worldObj);
|
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;
|
this.outputWatts = heatJoules * .4f;
|
||||||
|
|
Loading…
Reference in a new issue