2014-09-28 03:40:01 +02:00
|
|
|
package resonantinduction.atomic.machine.thermometer
|
|
|
|
|
|
|
|
import java.util.ArrayList
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.Optional
|
|
|
|
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
2014-12-01 12:59:35 +01:00
|
|
|
import li.cil.oc.api.network.{Arguments, Callback, Context, SimpleComponent}
|
2014-09-28 03:40:01 +02:00
|
|
|
import net.minecraft.block.Block
|
|
|
|
import net.minecraft.block.material.Material
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister
|
|
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
|
|
import net.minecraft.util.IIcon
|
|
|
|
import net.minecraft.world.IBlockAccess
|
|
|
|
import resonant.content.prefab.itemblock.ItemBlockSaved
|
|
|
|
import resonant.content.prefab.java.TileAdvanced
|
|
|
|
import resonant.engine.grid.thermal.ThermalGrid
|
|
|
|
import resonant.lib.network.Synced
|
|
|
|
import resonant.lib.network.discriminator.PacketAnnotation
|
2014-12-01 12:59:35 +01:00
|
|
|
import resonant.lib.transform.vector.{Vector3, VectorWorld}
|
2014-09-28 03:40:01 +02:00
|
|
|
import resonant.lib.utility.inventory.InventoryUtility
|
|
|
|
import resonantinduction.core.Reference
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thermometer TileEntity
|
|
|
|
*/
|
|
|
|
object TileThermometer
|
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
final val MAX_THRESHOLD: Int = 5000
|
|
|
|
private var iconSide: IIcon = null
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")
|
|
|
|
class TileThermometer extends TileAdvanced(Material.piston) with SimpleComponent
|
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
@Synced var detectedTemperature: Float = 295
|
|
|
|
@Synced var previousDetectedTemperature: Float = 295
|
|
|
|
@Synced var trackCoordinate: Vector3 = null
|
|
|
|
@Synced private var threshold: Int = 1000
|
|
|
|
@Synced private var isProvidingPower: Boolean = false
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
//Constructor
|
|
|
|
providePower = true
|
|
|
|
normalRender = false
|
|
|
|
renderStaticBlock = true
|
|
|
|
itemBlock = classOf[ItemBlockThermometer]
|
|
|
|
isOpaqueCube = true
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def getIcon(side: Int, meta: Int): IIcon =
|
|
|
|
{
|
|
|
|
return if (side == 1 || side == 0) super.getIcon(side, meta) else TileThermometer.iconSide
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
@SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister)
|
|
|
|
{
|
|
|
|
super.registerIcons(iconRegister)
|
|
|
|
TileThermometer.iconSide = iconRegister.registerIcon(Reference.prefix + "machine")
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
|
|
|
{
|
|
|
|
if (player.isSneaking)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
setThreshold(getThershold + 100)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
else
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
setThreshold(getThershold - 100)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
return true
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def configure(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
|
|
|
{
|
|
|
|
if (player.isSneaking)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
setThreshold(getThershold - 10)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
else
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
setThreshold(getThershold + 10)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
return true
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def getStrongRedstonePower(access: IBlockAccess, side: Int): Int =
|
|
|
|
{
|
|
|
|
return if (isProvidingPower) 15 else 0
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def getDrops(metadata: Int, fortune: Int): ArrayList[ItemStack] =
|
|
|
|
{
|
|
|
|
return new ArrayList[ItemStack]
|
|
|
|
}
|
|
|
|
|
|
|
|
override def onRemove(block: Block, par6: Int)
|
|
|
|
{
|
|
|
|
val stack: ItemStack = ItemBlockSaved.getItemStackWithNBT(getBlockType, world, xi, yi, zi)
|
|
|
|
InventoryUtility.dropItemStack(world, center, stack)
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def update
|
|
|
|
{
|
|
|
|
super.update
|
|
|
|
if (!worldObj.isRemote)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
if (ticks % 10 == 0)
|
|
|
|
{
|
|
|
|
if (trackCoordinate != null)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
detectedTemperature = ThermalGrid.getTemperature(new VectorWorld(world, trackCoordinate))
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
detectedTemperature = ThermalGrid.getTemperature(toVectorWorld)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
if (detectedTemperature != previousDetectedTemperature || isProvidingPower != this.isOverThreshold)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
previousDetectedTemperature = detectedTemperature
|
|
|
|
isProvidingPower = isOverThreshold
|
|
|
|
notifyChange
|
|
|
|
//sendPacket(getDescPacket)
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
override def getDescPacket: PacketAnnotation =
|
|
|
|
{
|
|
|
|
return new PacketAnnotation(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
def setTrack(track: Vector3)
|
|
|
|
{
|
|
|
|
trackCoordinate = track
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a tile entity from NBT.
|
|
|
|
*/
|
|
|
|
override def readFromNBT(nbt: NBTTagCompound)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbt)
|
|
|
|
threshold = nbt.getInteger("threshold")
|
|
|
|
if (nbt.hasKey("trackCoordinate"))
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
trackCoordinate = new Vector3(nbt.getCompoundTag("trackCoordinate"))
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
else
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
trackCoordinate = null
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
/**
|
|
|
|
* Writes a tile entity to NBT.
|
|
|
|
*/
|
|
|
|
override def writeToNBT(nbt: NBTTagCompound)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbt)
|
|
|
|
nbt.setInteger("threshold", threshold)
|
|
|
|
if (trackCoordinate != null)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
nbt.setTag("trackCoordinate", this.trackCoordinate.writeNBT(new NBTTagCompound))
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def getThershold: Int =
|
|
|
|
{
|
|
|
|
return threshold
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
def setThreshold(newThreshold: Int)
|
|
|
|
{
|
|
|
|
threshold = newThreshold % TileThermometer.MAX_THRESHOLD
|
|
|
|
if (threshold <= 0)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
threshold = TileThermometer.MAX_THRESHOLD
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
markUpdate
|
|
|
|
}
|
|
|
|
|
|
|
|
def isOverThreshold: Boolean =
|
|
|
|
{
|
|
|
|
return detectedTemperature >= getThershold
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
|
2014-12-01 12:59:35 +01:00
|
|
|
@Callback
|
|
|
|
@Optional.Method(modid = "OpenComputers")
|
|
|
|
def getTemperature(context: Context, args: Arguments): Array[Any] =
|
|
|
|
{
|
|
|
|
return Array[Any](this.detectedTemperature)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Callback
|
|
|
|
@Optional.Method(modid = "OpenComputers") def getWarningTemperature(context: Context, args: Arguments): Array[Any] =
|
|
|
|
{
|
|
|
|
return Array[Any](this.getThershold)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Callback
|
|
|
|
@Optional.Method(modid = "OpenComputers") def isAboveWarningTemperature(context: Context, args: Arguments): Array[Any] =
|
|
|
|
{
|
|
|
|
return Array[Any](this.isOverThreshold)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Callback
|
|
|
|
@Optional.Method(modid = "OpenComputers") def setWarningTemperature(context: Context, args: Arguments): Array[Any] =
|
|
|
|
{
|
|
|
|
if (args.count <= 0)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
throw new IllegalArgumentException("Not enough Arguments. Must provide one argument")
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
if (args.count >= 2)
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
throw new IllegalArgumentException("Too many Arguments. Must provide one argument")
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
if (!(args.isInteger(0)))
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
throw new IllegalArgumentException("Invalid Argument. Must provide an Integer")
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
this synchronized
|
2014-09-28 03:40:01 +02:00
|
|
|
{
|
2014-12-01 12:59:35 +01:00
|
|
|
this.setThreshold(args.checkInteger(0))
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|
2014-12-01 12:59:35 +01:00
|
|
|
return Array[Any](this.threshold == args.checkInteger(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
def getComponentName: String =
|
|
|
|
{
|
|
|
|
return "AS Thermometer"
|
|
|
|
}
|
2014-09-28 03:40:01 +02:00
|
|
|
}
|