Rewrote and abstracted EnergyStorage

This commit is contained in:
Calclavia 2015-01-21 11:12:44 +08:00
parent 60a7384241
commit 5c00d74116
5 changed files with 99 additions and 106 deletions

View file

@ -28,8 +28,8 @@ class GridBattery extends Grid[TileBattery]
totalCapacity = 0 totalCapacity = 0
for (connector <- this.getNodes) for (connector <- this.getNodes)
{ {
totalEnergy += connector.energy.getEnergy totalEnergy += connector.energy.value
totalCapacity += connector.energy.getEnergyCapacity totalCapacity += connector.energy.max
lowestY = Math.min(connector.yCoord, lowestY) lowestY = Math.min(connector.yCoord, lowestY)
highestY = Math.max(connector.yCoord, highestY) highestY = Math.max(connector.yCoord, highestY)
//TODO: Update energy render //TODO: Update energy render
@ -53,7 +53,7 @@ class GridBattery extends Grid[TileBattery]
for (connector <- connectorsInlevel) for (connector <- connectorsInlevel)
{ {
val tryInject: Double = Math.min(remainingRenderEnergy / levelSize, connector.energy.getEnergyCapacity) val tryInject: Double = Math.min(remainingRenderEnergy / levelSize, connector.energy.max)
//TODO: Update energy render //TODO: Update energy render
used += tryInject used += tryInject
} }
@ -74,13 +74,13 @@ class GridBattery extends Grid[TileBattery]
{ {
if (node != firstNode && !Arrays.asList(exclusion).contains(node)) if (node != firstNode && !Arrays.asList(exclusion).contains(node))
{ {
val percentage: Double = node.energy.getEnergyCapacity / totalCapacity val percentage: Double = node.energy.max / totalCapacity
val energyForBattery: Double = Math.max(totalEnergy * percentage, 0) val energyForBattery: Double = Math.max(totalEnergy * percentage, 0)
node.energy.setEnergy(energyForBattery) node.energy.value = energyForBattery
remainingEnergy -= energyForBattery remainingEnergy -= energyForBattery
} }
} }
firstNode.energy.setEnergy(Math.max(remainingEnergy, 0)) firstNode.energy.value = Math.max(remainingEnergy, 0)
} }
} }
} }

View file

@ -16,12 +16,13 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11._ import org.lwjgl.opengl.GL11._
import resonant.api.items.ISimpleItemRenderer import resonant.api.items.ISimpleItemRenderer
import resonant.lib.content.prefab.{TElectric, TEnergyStorage, TIO} import resonant.lib.content.prefab.{TElectric, TIO}
import resonant.lib.grid.core.TSpatialNodeProvider import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.grid.energy.EnergyStorage import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.network.discriminator.PacketType import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.tile.spatial.SpatialTile import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.prefab.tile.traits.TEnergyProvider
import resonant.lib.render.RenderUtility import resonant.lib.render.RenderUtility
import resonant.lib.transform.vector.Vector3 import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.science.UnitDisplay import resonant.lib.utility.science.UnitDisplay
@ -46,7 +47,7 @@ object TileBattery
def getEnergyForTier(tier: Int) = Math.round(Math.pow(500000000, (tier / (maxTier + 0.7f)) + 1) / 500000000) * 500000000 def getEnergyForTier(tier: Int) = Math.round(Math.pow(500000000, (tier / (maxTier + 0.7f)) + 1) / 500000000) * 500000000
} }
class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric with TSpatialNodeProvider with TPacketSender with TPacketReceiver with TEnergyStorage with ISimpleItemRenderer class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric with TSpatialNodeProvider with TPacketSender with TPacketReceiver with TEnergyProvider with ISimpleItemRenderer
{ {
var energyRenderLevel = 0 var energyRenderLevel = 0
@ -66,6 +67,14 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
updateConnectionMask() updateConnectionMask()
} }
def updateConnectionMask()
{
dcNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
dcNode.positiveTerminals.addAll(getInputDirections())
dcNode.negativeTerminals.addAll(getOutputDirections())
notifyChange()
}
override def update() override def update()
{ {
super.update() super.update()
@ -74,7 +83,7 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
{ {
if (isIndirectlyPowered) if (isIndirectlyPowered)
{ {
if (energy.getEnergy > 0) if (energy > 0)
{ {
//TODO: Voltage of battery should decrease over time. //TODO: Voltage of battery should decrease over time.
dcNode.generateVoltage(500) dcNode.generateVoltage(500)
@ -89,7 +98,7 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
* Update packet when energy level changes. * Update packet when energy level changes.
*/ */
val prevEnergyLevel = energyRenderLevel val prevEnergyLevel = energyRenderLevel
energyRenderLevel = Math.round((energy.getEnergy / TileBattery.getEnergyForTier(getBlockMetadata).toDouble) * 8).toInt energyRenderLevel = Math.round((energy.value / TileBattery.getEnergyForTier(getBlockMetadata).toDouble) * 8).toInt
if (prevEnergyLevel != energyRenderLevel) if (prevEnergyLevel != energyRenderLevel)
{ {
@ -101,7 +110,7 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
override def write(buf: ByteBuf, id: Int) override def write(buf: ByteBuf, id: Int)
{ {
super.write(buf, id) super.write(buf, id)
buf <<< energy.getEnergy buf <<< energy.value
buf <<< energyRenderLevel.toByte buf <<< energyRenderLevel.toByte
buf <<< ioMap buf <<< ioMap
} }
@ -109,8 +118,8 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
override def read(buf: ByteBuf, id: Int, packetType: PacketType) override def read(buf: ByteBuf, id: Int, packetType: PacketType)
{ {
super.read(buf, id, packetType) super.read(buf, id, packetType)
energy.setCapacity(TileBattery.getEnergyForTier(metadata)).setMaxTransfer(energy.getEnergyCapacity) energy.max = TileBattery.getEnergyForTier(metadata)
energy.setEnergy(buf.readDouble()) energy.value = buf.readDouble()
energyRenderLevel = buf.readByte() energyRenderLevel = buf.readByte()
ioMap = buf.readInt() ioMap = buf.readInt()
} }
@ -123,20 +132,12 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
markUpdate() markUpdate()
} }
def updateConnectionMask()
{
dcNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
dcNode.positiveTerminals.addAll(getInputDirections())
dcNode.negativeTerminals.addAll(getOutputDirections())
notifyChange()
}
override def onPlaced(entityLiving: EntityLivingBase, itemStack: ItemStack) override def onPlaced(entityLiving: EntityLivingBase, itemStack: ItemStack)
{ {
if (!world.isRemote && itemStack.getItem.isInstanceOf[ItemBlockBattery]) if (!world.isRemote && itemStack.getItem.isInstanceOf[ItemBlockBattery])
{ {
energy.setCapacity(TileBattery.getEnergyForTier(ItemBlockBattery.getTier(itemStack))).setMaxTransfer(energy.getEnergyCapacity) energy.max = (TileBattery.getEnergyForTier(ItemBlockBattery.getTier(itemStack)))
energy.setEnergy(itemStack.getItem.asInstanceOf[ItemBlockBattery].getEnergy(itemStack)) energy.value = itemStack.getItem.asInstanceOf[ItemBlockBattery].getEnergy(itemStack)
world.setBlockMetadataWithNotify(xi, yi, zi, ItemBlockBattery.getTier(itemStack), 3) world.setBlockMetadataWithNotify(xi, yi, zi, ItemBlockBattery.getTier(itemStack), 3)
} }
} }
@ -147,7 +148,7 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
val itemStack: ItemStack = new ItemStack(getBlockType, 1) val itemStack: ItemStack = new ItemStack(getBlockType, 1)
val itemBlock: ItemBlockBattery = itemStack.getItem.asInstanceOf[ItemBlockBattery] val itemBlock: ItemBlockBattery = itemStack.getItem.asInstanceOf[ItemBlockBattery]
ItemBlockBattery.setTier(itemStack, world.getBlockMetadata(xi, yi, zi).asInstanceOf[Byte]) ItemBlockBattery.setTier(itemStack, world.getBlockMetadata(xi, yi, zi).asInstanceOf[Byte])
itemBlock.setEnergy(itemStack, energy.getEnergy) itemBlock.setEnergy(itemStack, energy.value)
ret.add(itemStack) ret.add(itemStack)
return ret return ret
} }
@ -254,19 +255,19 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
* Render energy tooltip * Render energy tooltip
*/ */
if (isPlayerLooking(Minecraft.getMinecraft.thePlayer)) if (isPlayerLooking(Minecraft.getMinecraft.thePlayer))
RenderUtility.renderFloatingText(new UnitDisplay(UnitDisplay.Unit.JOULES, energy.getEnergy).symbol + " / " + new UnitDisplay(UnitDisplay.Unit.JOULES, energy.getEnergyCapacity).symbol, new Vector3(0, 0.9, 0)) RenderUtility.renderFloatingText(new UnitDisplay(UnitDisplay.Unit.JOULES, energy.value).symbol + " / " + new UnitDisplay(UnitDisplay.Unit.JOULES, energy.max).symbol, new Vector3(0, 0.9, 0))
glPopMatrix() glPopMatrix()
} }
override def readFromNBT(nbt: NBTTagCompound) override def readFromNBT(nbt: NBTTagCompound)
{ {
super.readFromNBT(nbt) super.readFromNBT(nbt)
energy.readFromNBT(nbt) energy.load(nbt)
} }
override def writeToNBT(nbt: NBTTagCompound) override def writeToNBT(nbt: NBTTagCompound)
{ {
super.writeToNBT(nbt) super.writeToNBT(nbt)
energy.writeToNBT(nbt) energy.save(nbt)
} }
} }

View file

@ -20,12 +20,13 @@ import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ChatComponentText import net.minecraft.util.ChatComponentText
import net.minecraft.world.World import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.content.prefab.{TEnergyStorage, TIO} import resonant.lib.content.prefab.TIO
import resonant.lib.grid.energy.EnergyStorage import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.network.discriminator.{PacketTile, PacketType} import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.{TPacketIDReceiver, TPacketSender} import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.tile.mixed.TileElectric import resonant.lib.prefab.tile.mixed.TileElectric
import resonant.lib.prefab.tile.multiblock.reference.{IMultiBlockStructure, MultiBlockHandler} import resonant.lib.prefab.tile.multiblock.reference.{IMultiBlockStructure, MultiBlockHandler}
import resonant.lib.prefab.tile.traits.TEnergyProvider
import resonant.lib.render.EnumColor import resonant.lib.render.EnumColor
import resonant.lib.transform.vector.{Vector3, VectorWorld} import resonant.lib.transform.vector.{Vector3, VectorWorld}
import resonant.lib.utility.{LanguageUtility, LinkUtility} import resonant.lib.utility.{LanguageUtility, LinkUtility}
@ -45,7 +46,7 @@ object TileTesla
final val DEFAULT_COLOR: Int = 12 final val DEFAULT_COLOR: Int = 12
} }
class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[TileTesla] with ITesla with TPacketIDReceiver with TPacketSender with TEnergyStorage with TIO class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[TileTesla] with ITesla with TPacketReceiver with TPacketSender with TEnergyProvider with TIO
{ {
final val TRANSFER_CAP: Double = 10000D final val TRANSFER_CAP: Double = 10000D
@ -76,10 +77,8 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
//Constructor //Constructor
//TODO: Dummy //TODO: Dummy
energy = new EnergyStorage(0) energy = new EnergyStorage
energy.setCapacity(TRANSFER_CAP * 2) textureName = "material_metal_side"
energy.setMaxTransfer(TRANSFER_CAP)
setTextureName(Reference.prefix + "material_metal_side")
normalRender = false normalRender = false
isOpaqueCube = false isOpaqueCube = false
@ -94,7 +93,7 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
super.update super.update
if (this.getMultiBlock.isPrimary) if (this.getMultiBlock.isPrimary)
{ {
if (this.ticks % (4 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && isTransfering) || (!this.energy.isEmpty && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)))) if (this.ticks % (4 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && isTransfering) || (this.energy.value != 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
{ {
val topTesla: TileTesla = this.getTopTelsa val topTesla: TileTesla = this.getTopTelsa
val topTeslaVector: Vector3 = toVector3 val topTeslaVector: Vector3 = toVector3
@ -108,10 +107,10 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
val transferTile: TileEntity = this.linked.getTileEntity(dimWorld) val transferTile: TileEntity = this.linked.getTileEntity(dimWorld)
if (transferTile.isInstanceOf[TileTesla] && !transferTile.isInvalid) if (transferTile.isInstanceOf[TileTesla] && !transferTile.isInvalid)
{ {
this.transfer((transferTile.asInstanceOf[TileTesla]), Math.min(energy.getEnergy, TRANSFER_CAP)) this.transfer((transferTile.asInstanceOf[TileTesla]), Math.min(energy.value, TRANSFER_CAP))
if (this.zapCounter % 5 == 0 && Settings.SOUND_FXS) if (this.zapCounter % 5 == 0 && Settings.SOUND_FXS)
{ {
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "electricshock", this.energy.getEnergy.asInstanceOf[Float] / TRANSFER_CAP.asInstanceOf[Float], 1.3f - 0.5f * (this.dyeID / 16f)) this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "electricshock", energy.value.toFloat / TRANSFER_CAP.asInstanceOf[Float], 1.3f - 0.5f * (this.dyeID / 16f))
} }
} }
} }
@ -158,7 +157,7 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
} }
if (teslaToTransfer.size > 0) if (teslaToTransfer.size > 0)
{ {
val transferEnergy: Double = this.energy.getEnergy / teslaToTransfer.size val transferEnergy: Double = this.energy.value / teslaToTransfer.size
val sentPacket: Boolean = false val sentPacket: Boolean = false
for (count <- 0 to 10) for (count <- 0 to 10)
@ -168,7 +167,7 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
val tesla: ITesla = teslaToTransfer.poll val tesla: ITesla = teslaToTransfer.poll
if (this.zapCounter % 5 == 0 && Settings.SOUND_FXS) if (this.zapCounter % 5 == 0 && Settings.SOUND_FXS)
{ {
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "electricshock", this.energy.getEnergy.asInstanceOf[Float] / TRANSFER_CAP.asInstanceOf[Float], 1.3f - 0.5f * (this.dyeID / 16f)) this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "electricshock", this.energy.value.asInstanceOf[Float] / TRANSFER_CAP.asInstanceOf[Float], 1.3f - 0.5f * (this.dyeID / 16f))
} }
var targetVector: Vector3 = new Vector3(tesla.asInstanceOf[TileEntity]) var targetVector: Vector3 = new Vector3(tesla.asInstanceOf[TileEntity])
var heightRange: Int = 1 var heightRange: Int = 1
@ -194,7 +193,7 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
this.outputBlacklist.clear this.outputBlacklist.clear
this.doTransfer = false this.doTransfer = false
} }
if (!this.worldObj.isRemote && this.energy.didEnergyStateChange) if (!this.worldObj.isRemote && this.energy.isLastEmpty)
{ {
this.sendPacket(2) this.sendPacket(2)
} }
@ -241,35 +240,37 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
} }
if (`type` == 2) if (`type` == 2)
{ {
data.add(this.energy.getEnergy > 0) data.add(this.energy.value > 0)
} }
return data return data
} }
override def read(data: ByteBuf, id: Int, player: EntityPlayer, `type`: PacketType): Boolean = override def read(buf: ByteBuf, id: Int, packetType: PacketType)
{ {
super.read(buf, id, packetType)
if (id == 1) if (id == 1)
{ {
this.dyeID = data.readInt this.dyeID = buf.readInt
this.canReceive = data.readBoolean this.canReceive = buf.readBoolean
this.attackEntities = data.readBoolean this.attackEntities = buf.readBoolean
this.isLinkedClient = data.readBoolean this.isLinkedClient = buf.readBoolean
getMultiBlock.load(ByteBufUtils.readTag(data)) getMultiBlock.load(ByteBufUtils.readTag(buf))
return true
} }
else else if (id == 2)
if (id == 2)
{ {
this.isTransfering = data.readBoolean this.isTransfering = buf.readBoolean
return true
} }
else else if (id == 3)
if (id == 3)
{ {
this.doTransfer = true this.doTransfer = true
return true
} }
return false }
def getMultiBlock: MultiBlockHandler[TileTesla] =
{
if (multiBlock == null) multiBlock = new MultiBlockHandler[TileTesla](this)
return multiBlock
} }
def teslaTransfer(e: Double, doTransfer: Boolean): Double = def teslaTransfer(e: Double, doTransfer: Boolean): Double =
@ -279,8 +280,8 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
{ {
if (doTransfer) if (doTransfer)
{ {
this.energy.receiveEnergy(transferEnergy, true) this.energy += transferEnergy
if (this.energy.didEnergyStateChange) if (this.energy.isLastEmpty)
{ {
this.sendPacket(2) this.sendPacket(2)
} }
@ -289,10 +290,10 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
} }
else else
{ {
if (this.energy.getEnergy > 0) if (energy.value > 0)
{ {
transferEnergy += this.energy.getEnergy transferEnergy += energy.value
this.energy.setEnergy(0) energy.value = 0
} }
return getMultiBlock.get.teslaTransfer(transferEnergy, doTransfer) return getMultiBlock.get.teslaTransfer(transferEnergy, doTransfer)
} }
@ -407,12 +408,6 @@ class TileTesla extends TileElectric(Material.iron) with IMultiBlockStructure[Ti
getMultiBlock.save(nbt) getMultiBlock.save(nbt)
} }
def getMultiBlock: MultiBlockHandler[TileTesla] =
{
if (multiBlock == null) multiBlock = new MultiBlockHandler[TileTesla](this)
return multiBlock
}
def setLink(vector3: Vector3, dimID: Int, setOpponent: Boolean) def setLink(vector3: Vector3, dimID: Int, setOpponent: Boolean)
{ {
if (!worldObj.isRemote) if (!worldObj.isRemote)

View file

@ -13,17 +13,17 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.IIcon import net.minecraft.util.IIcon
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import resonant.api.tile.{IElectromagnet, IRotatable} import resonant.api.tile.{IElectromagnet, IRotatable}
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.grid.energy.EnergyStorage import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.network.discriminator.{PacketTile, PacketType} import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.{TPacketIDReceiver, TPacketSender} import resonant.lib.network.handle.{TPacketIDReceiver, TPacketSender}
import resonant.lib.prefab.tile.mixed.TileElectricInventory import resonant.lib.prefab.tile.mixed.TileElectricInventory
import resonant.lib.prefab.tile.traits.TEnergyProvider
import resonant.lib.transform.vector.Vector3 import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.BlockUtility import resonant.lib.utility.BlockUtility
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
class TileAccelerator extends TileElectricInventory(Material.iron) with IElectromagnet with IRotatable with TPacketIDReceiver with TPacketSender with TEnergyStorage class TileAccelerator extends TileElectricInventory(Material.iron) with IElectromagnet with IRotatable with TPacketIDReceiver with TPacketSender with TEnergyProvider
{ {
final val DESC_PACKET_ID = 2 final val DESC_PACKET_ID = 2
/** /**
@ -45,9 +45,7 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
//Constructor //Constructor
//TODO: Dummy //TODO: Dummy
energy = new EnergyStorage(0) energy = new EnergyStorage
energy.setCapacity(Settings.ACCELERATOR_ENERGY_COST_PER_TICK * 20)
energy.setMaxTransfer(Settings.ACCELERATOR_ENERGY_COST_PER_TICK)
override def getSizeInventory: Int = 4 override def getSizeInventory: Int = 4
@ -56,13 +54,13 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
super.update super.update
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
clientEnergy = energy.getEnergy clientEnergy = energy.value
velocity = getParticleVel() velocity = getParticleVel()
outputAntimatter() outputAntimatter()
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{ {
if (energy.checkExtract) if (energy >= Settings.ACCELERATOR_ENERGY_COST_PER_TICK)
{ {
if (entityParticle == null) if (entityParticle == null)
{ {
@ -114,7 +112,7 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix + "accelerator", 1.5f, (0.6f + (0.4 * (entityParticle.getParticleVelocity) / EntityParticle.ANITMATTER_CREATION_SPEED)).asInstanceOf[Float]) worldObj.playSoundEffect(xCoord, yCoord, zCoord, Reference.prefix + "accelerator", 1.5f, (0.6f + (0.4 * (entityParticle.getParticleVelocity) / EntityParticle.ANITMATTER_CREATION_SPEED)).asInstanceOf[Float])
} }
} }
energy.extractEnergy energy -= Settings.ACCELERATOR_ENERGY_COST_PER_TICK
} }
else else
{ {
@ -206,7 +204,7 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
override def getDescPacket: PacketTile = override def getDescPacket: PacketTile =
{ {
return new PacketTile(xi, yi, zi, Array[Any](DESC_PACKET_ID, velocity, totalEnergyConsumed, antimatter, energy.getEnergy)) return new PacketTile(xi, yi, zi, Array[Any](DESC_PACKET_ID, velocity, totalEnergyConsumed, antimatter, energy.value))
} }
///////////////////////////////////////// /////////////////////////////////////////
@ -222,6 +220,20 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
return 0 return 0
} }
override def getDirection: ForgeDirection =
{
return ForgeDirection.getOrientation(getBlockMetadata)
}
/////////////////////////////////////////
/// Save handling ///
////////////////////////////////////////
override def setDirection(direction: ForgeDirection)
{
world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal, 3)
}
override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean = override def activate(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{ {
player.openGui(Electrodynamics, 0, world, xi, yi, zi) player.openGui(Electrodynamics, 0, world, xi, yi, zi)
@ -229,7 +241,7 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
} }
///////////////////////////////////////// /////////////////////////////////////////
/// Save handling /// /// Inventory Overrides ///
//////////////////////////////////////// ////////////////////////////////////////
override def read(buf: ByteBuf, id: Int, player: EntityPlayer, packet: PacketType): Boolean = override def read(buf: ByteBuf, id: Int, player: EntityPlayer, packet: PacketType): Boolean =
@ -242,7 +254,7 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
this.velocity = buf.readFloat() this.velocity = buf.readFloat()
this.totalEnergyConsumed = buf.readDouble() this.totalEnergyConsumed = buf.readDouble()
this.antimatter = buf.readInt() this.antimatter = buf.readInt()
this.energy.setEnergy(buf.readDouble()) this.energy.value = buf.readDouble()
return true return true
} }
} }
@ -257,10 +269,6 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
antimatter = par1NBTTagCompound.getInteger("antimatter") antimatter = par1NBTTagCompound.getInteger("antimatter")
} }
/////////////////////////////////////////
/// Inventory Overrides ///
////////////////////////////////////////
override def writeToNBT(par1NBTTagCompound: NBTTagCompound) override def writeToNBT(par1NBTTagCompound: NBTTagCompound)
{ {
super.writeToNBT(par1NBTTagCompound) super.writeToNBT(par1NBTTagCompound)
@ -268,6 +276,10 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
par1NBTTagCompound.setInteger("antimatter", antimatter) par1NBTTagCompound.setInteger("antimatter", antimatter)
} }
/////////////////////////////////////////
/// Field Getters & Setters ///
////////////////////////////////////////
override def canInsertItem(slotID: Int, itemStack: ItemStack, j: Int): Boolean = override def canInsertItem(slotID: Int, itemStack: ItemStack, j: Int): Boolean =
{ {
return isItemValidForSlot(slotID, itemStack) && slotID != 2 && slotID != 3 return isItemValidForSlot(slotID, itemStack) && slotID != 2 && slotID != 3
@ -289,10 +301,6 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
return false return false
} }
/////////////////////////////////////////
/// Field Getters & Setters ///
////////////////////////////////////////
override def canExtractItem(slotID: Int, itemstack: ItemStack, j: Int): Boolean = override def canExtractItem(slotID: Int, itemstack: ItemStack, j: Int): Boolean =
{ {
return slotID == 2 || slotID == 3 return slotID == 2 || slotID == 3
@ -312,14 +320,4 @@ class TileAccelerator extends TileElectricInventory(Material.iron) with IElectro
} }
return getIcon return getIcon
} }
override def getDirection: ForgeDirection =
{
return ForgeDirection.getOrientation(getBlockMetadata)
}
override def setDirection(direction: ForgeDirection)
{
world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal, 3)
}
} }

View file

@ -13,23 +13,23 @@ import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._ import net.minecraftforge.fluids._
import resonant.api.tile.ITagRender import resonant.api.tile.ITagRender
import resonant.engine.ResonantEngine import resonant.engine.ResonantEngine
import resonant.lib.content.prefab.TEnergyStorage
import resonant.lib.grid.energy.EnergyStorage import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.mod.config.Config import resonant.lib.mod.config.Config
import resonant.lib.network.discriminator.{PacketTile, PacketType} import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketReceiver import resonant.lib.network.handle.IPacketReceiver
import resonant.lib.prefab.tile.mixed.TileElectric import resonant.lib.prefab.tile.mixed.TileElectric
import resonant.lib.prefab.tile.traits.TEnergyProvider
import resonant.lib.transform.vector.Vector3 import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.science.UnitDisplay import resonant.lib.utility.science.UnitDisplay
import resonant.lib.utility.{FluidUtility, LanguageUtility} import resonant.lib.utility.{FluidUtility, LanguageUtility}
object TilePlasmaHeater object TilePlasmaHeater
{ {
var joules: Long = 10000000000L var power: Long = 10000000000L
@Config var plasmaHeatAmount: Int = 100 @Config var plasmaHeatAmount: Int = 100
} }
class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver with ITagRender with IFluidHandler with TEnergyStorage class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver with ITagRender with IFluidHandler with TEnergyProvider
{ {
final val tankInputDeuterium: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10) final val tankInputDeuterium: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10)
final val tankInputTritium: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10) final val tankInputTritium: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 10)
@ -39,26 +39,25 @@ class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver
//Constructor //Constructor
//TODO: Dummy //TODO: Dummy
energy = new EnergyStorage(0) energy = new EnergyStorage
energy.setCapacity(TilePlasmaHeater.joules) energy.max = TilePlasmaHeater.power
energy.setMaxTransfer(TilePlasmaHeater.joules / 20)
normalRender = false normalRender = false
isOpaqueCube = false isOpaqueCube = false
override def update() override def update()
{ {
super.update() super.update()
rotation = (rotation + energy.getEnergy / 10000f).asInstanceOf[Float] rotation = (rotation + energy.value / 10000f).asInstanceOf[Float]
if (!worldObj.isRemote) if (!worldObj.isRemote)
{ {
if (energy.checkExtract) if (energy >= TilePlasmaHeater.power / 20)
{ {
if (tankInputDeuterium.getFluidAmount >= TilePlasmaHeater.plasmaHeatAmount && tankInputTritium.getFluidAmount >= TilePlasmaHeater.plasmaHeatAmount && tankOutput.getFluidAmount < tankOutput.getCapacity) if (tankInputDeuterium.getFluidAmount >= TilePlasmaHeater.plasmaHeatAmount && tankInputTritium.getFluidAmount >= TilePlasmaHeater.plasmaHeatAmount && tankOutput.getFluidAmount < tankOutput.getCapacity)
{ {
tankInputDeuterium.drain(TilePlasmaHeater.plasmaHeatAmount, true) tankInputDeuterium.drain(TilePlasmaHeater.plasmaHeatAmount, true)
tankInputTritium.drain(TilePlasmaHeater.plasmaHeatAmount, true) tankInputTritium.drain(TilePlasmaHeater.plasmaHeatAmount, true)
tankOutput.fill(new FluidStack(QuantumContent.FLUID_PLASMA, tankOutput.getCapacity), true) tankOutput.fill(new FluidStack(QuantumContent.FLUID_PLASMA, tankOutput.getCapacity), true)
energy.extractEnergy energy -= TilePlasmaHeater.power / 20
} }
} }
} }
@ -134,7 +133,7 @@ class TilePlasmaHeater extends TileElectric(Material.iron) with IPacketReceiver
{ {
if (energy != null) if (energy != null)
{ {
map.put(LanguageUtility.getLocal("tooltip.energy") + ": " + new UnitDisplay(UnitDisplay.Unit.JOULES, energy.getEnergy), 0xFFFFFF) map.put(LanguageUtility.getLocal("tooltip.energy") + ": " + new UnitDisplay(UnitDisplay.Unit.JOULES, energy.value), 0xFFFFFF)
} }
if (tankInputDeuterium.getFluidAmount > 0) if (tankInputDeuterium.getFluidAmount > 0)
{ {