2014-08-06 13:57:45 +02:00
|
|
|
package resonantinduction.electrical.generator
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly
|
|
|
|
import net.minecraft.block.Block
|
|
|
|
import net.minecraft.block.material.Material
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister
|
|
|
|
import net.minecraft.init.Blocks
|
|
|
|
import net.minecraft.util.IIcon
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection
|
2014-12-10 19:47:51 +01:00
|
|
|
import resonant.lib.prefab.tile.TileElectric
|
|
|
|
import resonant.lib.prefab.tile.spatial.SpatialBlock
|
2014-08-06 13:57:45 +02:00
|
|
|
import resonantinduction.core.Reference
|
2014-10-27 18:31:42 +01:00
|
|
|
import resonant.lib.transform.vector.Vector3
|
2014-08-06 13:57:45 +02:00
|
|
|
|
|
|
|
class TileThermopile extends TileElectric(Material.rock) {
|
|
|
|
|
|
|
|
this.ioMap = 728.asInstanceOf[Short]
|
|
|
|
|
|
|
|
override def update {
|
|
|
|
super.update
|
|
|
|
if (!this.worldObj.isRemote) {
|
|
|
|
var heatSources: Int = 0
|
|
|
|
var coolingSources: Int = 0
|
|
|
|
for (dir <- ForgeDirection.VALID_DIRECTIONS) {
|
2014-11-08 13:58:31 +01:00
|
|
|
val checkPos: Vector3 = toVector3.add(dir)
|
2014-08-06 13:57:45 +02:00
|
|
|
val block: Block = checkPos.getBlock(worldObj)
|
|
|
|
if (block eq Blocks.water) {
|
|
|
|
coolingSources += 1
|
|
|
|
}
|
|
|
|
else if (block eq Blocks.snow) {
|
|
|
|
coolingSources += 2
|
|
|
|
}
|
|
|
|
else if (block eq Blocks.ice) {
|
|
|
|
coolingSources += 2
|
|
|
|
}
|
|
|
|
else if (block eq Blocks.fire) {
|
|
|
|
heatSources += 1
|
|
|
|
}
|
|
|
|
else if (block eq Blocks.lava) {
|
|
|
|
heatSources += 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val multiplier: Int = (3 - Math.abs(heatSources - coolingSources))
|
|
|
|
if (multiplier > 0 && coolingSources > 0 && heatSources > 0) {
|
2014-10-26 15:41:40 +01:00
|
|
|
// electricNode.addEnergy(ForgeDirection.UNKNOWN, 15 * multiplier, true)
|
2014-08-06 13:57:45 +02:00
|
|
|
if (({
|
|
|
|
usingTicks += 1; usingTicks
|
|
|
|
}) >= MAX_USE_TICKS) {
|
|
|
|
for (dir <- ForgeDirection.VALID_DIRECTIONS) {
|
2014-11-08 13:58:31 +01:00
|
|
|
val checkPos: Vector3 = toVector3.add(dir)
|
2014-08-06 13:57:45 +02:00
|
|
|
val blockID: Block = checkPos.getBlock(worldObj)
|
|
|
|
if (blockID eq Blocks.water) {
|
|
|
|
checkPos.setBlockToAir(worldObj)
|
|
|
|
}
|
|
|
|
else if (blockID eq Blocks.ice) {
|
|
|
|
checkPos.setBlock(worldObj, Blocks.water)
|
|
|
|
}
|
|
|
|
else if (blockID eq Blocks.fire) {
|
|
|
|
checkPos.setBlockToAir(worldObj)
|
|
|
|
}
|
|
|
|
else if (blockID eq Blocks.lava) {
|
|
|
|
checkPos.setBlock(worldObj, Blocks.stone)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usingTicks = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
|
|
|
|
{
|
|
|
|
SpatialBlock.icon.put("thermopile_top", iconReg.registerIcon(Reference.prefix + "thermopile_top"))
|
|
|
|
super.registerIcons(iconReg)
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
|
|
|
|
{
|
|
|
|
if (side == 1)
|
|
|
|
{
|
|
|
|
return SpatialBlock.icon.get("thermopile_top")
|
|
|
|
}
|
|
|
|
return super.getIcon(side, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
private final val MAX_USE_TICKS: Int = 120 * 20
|
|
|
|
/**
|
|
|
|
* The amount of ticks the thermopile will use the temperature differences before turning all
|
|
|
|
* adjacent sides to thermal equilibrium.
|
|
|
|
*/
|
|
|
|
private var usingTicks: Int = 0
|
|
|
|
}
|