Lasers now run electrically

This commit is contained in:
Calclavia 2015-01-25 16:58:35 +08:00
parent 173224b2cb
commit 4e27054df4
9 changed files with 85 additions and 99 deletions

View file

@ -67,6 +67,15 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
updateConnectionMask()
}
def updateConnectionMask()
{
electricNode.setPositives(getInputDirections())
electricNode.setNegatives(getOutputDirections())
electricNode.reconstruct()
markUpdate()
notifyChange()
}
override def update()
{
super.update()
@ -75,14 +84,11 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
{
if (isIndirectlyPowered)
{
if (electricNode.voltage >= 0)
{
//Discharge battery when current is flowing positive direction
//TODO: Allow player to set the power output
electricNode.generatePower(Math.min(10000, energy.value))
val dissipatedEnergy = electricNode.power / 20
energy -= dissipatedEnergy
}
//Discharge battery when current is flowing positive direction
//TODO: Allow player to set the power output
electricNode.generatePower(Math.min(energy.max * 0.0001, energy.value))
val dissipatedEnergy = electricNode.power / 20
energy -= dissipatedEnergy
}
else
{
@ -92,8 +98,10 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
if (energy.prev != energy.value)
markUpdate()
{
energyRenderLevel = Math.round((energy.value / TileBattery.getEnergyForTier(getBlockMetadata).toDouble) * 8).toInt
sendDescPacket()
}
/**
* Update packet when energy level changes.
@ -130,15 +138,6 @@ class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric wit
updateConnectionMask()
}
def updateConnectionMask()
{
electricNode.setPositives(getInputDirections())
electricNode.setNegatives(getOutputDirections())
electricNode.reconstruct()
markUpdate()
notifyChange()
}
override def onPlaced(entityLiving: EntityLivingBase, itemStack: ItemStack)
{
if (!world.isRemote && itemStack.getItem.isInstanceOf[ItemBlockBattery])

View file

@ -116,8 +116,6 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
return wire.getThickness > getThickness
}
def getThickness: Int = if (insulated) 1 else 0
/**
* Packet Methods
*/
@ -287,6 +285,8 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
def getOcclusionBoxes: JIterable[Cuboid6] = Seq(PartFlatWire.occlusionBounds(getThickness)(side))
def getThickness: Int = if (insulated) 1 else 0
override def solid(arg0: Int) = false
/**
@ -487,15 +487,19 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (tpCorner != null)
{
val part = tpCorner.partMap(absDir ^ 1)
val absToDir = ForgeDirection.getOrientation(absDir)
val absFromDir = ForgeDirection.getOrientation(absDir).getOpposite
val node = part.asInstanceOf[INodeProvider].getNode(classOf[NodeElectricComponent], absFromDir)
if (canConnect(node, absFromDir))
if (part != null)
{
//TODO: Check dir
connect(node, absToDir)
return true
val absToDir = ForgeDirection.getOrientation(absDir)
val absFromDir = ForgeDirection.getOrientation(absDir).getOpposite
val node = part.asInstanceOf[INodeProvider].getNode(classOf[NodeElectricComponent], absFromDir)
if (canConnect(node, absFromDir))
{
//TODO: Check dir
connect(node, absToDir)
return true
}
}
}
}

View file

@ -9,7 +9,7 @@ import net.minecraft.item.{Item, ItemStack}
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.tile.{IReactor, IReactorComponent}
import resonant.lib.grid.thermal.ThermalGrid
import resonant.lib.grid.thermal.GridThermal
import resonant.lib.transform.vector.VectorWorld
import resonant.lib.wrapper.CollectionWrapper._
@ -52,14 +52,14 @@ class ItemFuelRod extends ItemRadioactive with IReactorComponent
ForgeDirection.VALID_DIRECTIONS
.map(d => (new VectorWorld(tile) + d).getTileEntity)
.filter(_.isInstanceOf[IReactor])
.count(t => ThermalGrid.getTemperature(new VectorWorld(t)) > ItemFuelRod.breedingTemp)
.count(t => GridThermal.getTemperature(new VectorWorld(t)) > ItemFuelRod.breedingTemp)
if (reactors >= 2)
{
/**
* Do fuel breeding
*/
if (world.rand.nextInt(1000) <= 100 && ThermalGrid.getTemperature(new VectorWorld(tile)) > (ItemFuelRod.breedingTemp / 2))
if (world.rand.nextInt(1000) <= 100 && GridThermal.getTemperature(new VectorWorld(tile)) > (ItemFuelRod.breedingTemp / 2))
{
val breedAmount = world.rand.nextInt(5)
itemStack.setItemDamage(Math.max(itemStack.getItemDamage - breedAmount, 0))

View file

@ -16,18 +16,18 @@ import resonant.lib.transform.vector.Vector3
import scala.collection.mutable
/**
* Handles lasers
* Handles laser interaction
* @author Calclavia
*/
object Laser
{
val maxDistance = 100
val minEnergy = 100D
val maxEnergy = 8000D
val minEnergy = 100d
val maxEnergy = 20000d
val minEnergyToMine = 4000D
val maxEnergyToMine = 500000D
val minEnergyToMine = 4000d
val maxEnergyToMine = 500000d
val minBurnEnergy = minEnergyToMine
val currentBlockEnergy = mutable.HashMap[Vector3, Double]()
val accumilatedBlockEnergy = mutable.HashMap[Vector3, Double]()

View file

@ -13,11 +13,15 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11._
import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.grid.energy.electric.NodeElectricComponent
import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.prefab.tile.traits.TRotatable
import resonant.lib.render.RenderUtility
import resonant.lib.transform.vector.Vector3
import scala.collection.convert.wrapAll._
/**
* An emitter that shoots out lasers.
*
@ -27,18 +31,25 @@ import resonant.lib.transform.vector.Vector3
*/
object TileLaserEmitter
{
@SideOnly(Side.CLIENT) val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "laserEmitter.tcn"))
@SideOnly(Side.CLIENT) val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "laserEmitter.png")
@SideOnly(Side.CLIENT)
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "laserEmitter.tcn"))
@SideOnly(Side.CLIENT)
val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "laserEmitter.png")
}
class TileLaserEmitter extends SpatialTile(Material.iron) with ILaserHandler with TRotatable
class TileLaserEmitter extends SpatialTile(Material.iron) with ILaserHandler with TSpatialNodeProvider with TRotatable
{
var energy = 0D
val electricNode = new NodeElectricComponent(this)
domain = ""
textureName = "stone"
normalRender = false
isOpaqueCube = false
electricNode.dynamicTerminals = true
electricNode.setPositives(Set(ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.UP))
electricNode.setNegatives(Set(ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.DOWN))
nodes.add(electricNode)
/**
* Called when the block is placed by a living entity
@ -51,21 +62,17 @@ class TileLaserEmitter extends SpatialTile(Material.iron) with ILaserHandler wit
world.setBlockMetadataWithNotify(xi, yi, zi, l, 2)
}
override def getLightValue(access: IBlockAccess): Int = ((energy / Laser.maxEnergy) * 15).toInt
override def getLightValue(access: IBlockAccess): Int = ((electricNode.power / Laser.maxEnergy) * 15).toInt
override def onLaserHit(renderStart: Vector3, incidentDirection: Vector3, hit: MovingObjectPosition, color: Vector3, energy: Double) = false
override def update()
{
if (isIndirectlyPowered)
{
energy += world.getStrongestIndirectPower(xi, yi, zi) * (Laser.maxEnergy / 15)
}
super.update()
if (energy > 0)
if (electricNode.power > 0)
{
Laser.spawn(worldObj, toVector3 + 0.5 + new Vector3(getDirection) * 0.51, toVector3 + new Vector3(getDirection) * 0.6 + 0.5, new Vector3(getDirection), energy)
energy = 0
Laser.spawn(worldObj, toVector3 + 0.5 + new Vector3(getDirection) * 0.51, toVector3 + new Vector3(getDirection) * 0.6 + 0.5, new Vector3(getDirection), electricNode.power / 20)
}
}

View file

@ -8,15 +8,18 @@ import net.minecraft.block.material.Material
import net.minecraft.entity.EntityLivingBase
import net.minecraft.item.ItemStack
import net.minecraft.util.{MovingObjectPosition, ResourceLocation}
import net.minecraft.world.IBlockAccess
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11._
import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.grid.energy.electric.NodeElectricComponent
import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.prefab.tile.traits.TRotatable
import resonant.lib.render.RenderUtility
import resonant.lib.transform.vector.Vector3
import scala.collection.convert.wrapAll._
/**
* A block that receives laser light and generates a voltage.
* @author Calclavia
@ -27,50 +30,29 @@ object TileLaserReceiver
@SideOnly(Side.CLIENT) val texture = new ResourceLocation(Reference.domain, Reference.modelPath + "laserReceiver.png")
}
class TileLaserReceiver extends SpatialTile(Material.rock) with ILaserHandler with TRotatable
class TileLaserReceiver extends SpatialTile(Material.rock) with ILaserHandler with TSpatialNodeProvider with TRotatable
{
var redstoneValue = 0
val electricNode = new NodeElectricComponent(this)
private var energy = 0D
private var prevRedstoneValue = 0;
domain = ""
textureName = "stone"
normalRender = false
isOpaqueCube = false
nodes.add(electricNode)
override def update()
{
if (energy > 0)
{
redstoneValue = Math.min(Math.ceil(energy / (Laser.maxEnergy / 15)), 15).toInt
electricNode.dynamicTerminals = true
electricNode.setPositives(Set(ForgeDirection.NORTH, ForgeDirection.EAST))
electricNode.setNegatives(Set(ForgeDirection.SOUTH, ForgeDirection.WEST))
if (redstoneValue != prevRedstoneValue)
{
world.notifyBlocksOfNeighborChange(xi, yi, zi, getBlockType)
ForgeDirection.VALID_DIRECTIONS.foreach(dir => world.notifyBlocksOfNeighborChange(xi + dir.offsetX, yi + dir.offsetY, zi + dir.offsetZ, getBlockType))
prevRedstoneValue = redstoneValue
}
energy = 0
}
else
{
redstoneValue = 0
if (redstoneValue != prevRedstoneValue)
{
world.notifyBlocksOfNeighborChange(xi, yi, zi, getBlockType)
ForgeDirection.VALID_DIRECTIONS.foreach(dir => world.notifyBlocksOfNeighborChange(xi + dir.offsetX, yi + dir.offsetY, zi + dir.offsetZ, getBlockType))
prevRedstoneValue = redstoneValue
}
}
}
override def canUpdate: Boolean = false
override def onLaserHit(renderStart: Vector3, incident: Vector3, hit: MovingObjectPosition, color: Vector3, energy: Double): Boolean =
{
if (hit.sideHit == getDirection.ordinal)
{
this.energy += energy
electricNode.generatePower(energy)
}
return false
@ -82,12 +64,6 @@ class TileLaserReceiver extends SpatialTile(Material.rock) with ILaserHandler wi
world.setBlockMetadataWithNotify(xi, yi, zi, l, 2)
}
override def getLightValue(access: IBlockAccess): Int = redstoneValue
override def getWeakRedstonePower(access: IBlockAccess, side: Int): Int = getStrongRedstonePower(access, side)
override def getStrongRedstonePower(access: IBlockAccess, side: Int): Int = redstoneValue
@SideOnly(Side.CLIENT)
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
{

View file

@ -12,7 +12,7 @@ import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.event.PlasmaEvent
import resonant.lib.grid.thermal.ThermalGrid
import resonant.lib.grid.thermal.GridThermal
import resonant.lib.mod.config.Config
import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.transform.vector.Vector3
@ -58,7 +58,7 @@ class TilePlasma extends SpatialTile(Material.lava)
override def update
{
super.update
ThermalGrid.addHeat(toVectorWorld, ((temperature - ThermalGrid.getTemperature(toVectorWorld)) * 0.1f).asInstanceOf[Float])
GridThermal.addHeat(toVectorWorld, ((temperature - GridThermal.getTemperature(toVectorWorld)) * 0.1f).asInstanceOf[Float])
if (ticks % 20 == 0)
{
temperature /= 1.5

View file

@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.IIcon
import net.minecraft.world.IBlockAccess
import resonant.lib.grid.thermal.ThermalGrid
import resonant.lib.grid.thermal.GridThermal
import resonant.lib.prefab.tile.item.ItemBlockSaved
import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.transform.vector.{Vector3, VectorWorld}
@ -119,11 +119,11 @@ class TileThermometer extends SpatialTile(Material.piston) with SimpleComponent
{
if (trackCoordinate != null)
{
detectedTemperature = ThermalGrid.getTemperature(new VectorWorld(world, trackCoordinate))
detectedTemperature = GridThermal.getTemperature(new VectorWorld(world, trackCoordinate))
}
else
{
detectedTemperature = ThermalGrid.getTemperature(toVectorWorld)
detectedTemperature = GridThermal.getTemperature(toVectorWorld)
}
if (detectedTemperature != previousDetectedTemperature || isProvidingPower != this.isOverThreshold)
{

View file

@ -20,7 +20,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.api.tile.{IReactor, IReactorComponent}
import resonant.lib.grid.thermal.{ThermalGrid, ThermalPhysics}
import resonant.lib.grid.thermal.{GridThermal, ThermalPhysics}
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.poison.PoisonRadiation
import resonant.lib.prefab.tile.mixed.TileInventory
@ -68,11 +68,6 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc
updatePositionStatus()
}
override def onNeighborChanged(block: Block)
{
updatePositionStatus()
}
/** Multiblock Methods */
def updatePositionStatus()
{
@ -122,6 +117,11 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc
override def getMultiBlock: MultiBlockHandler[TileReactorCell] = multiBlock
override def onNeighborChanged(block: Block)
{
updatePositionStatus()
}
override def update()
{
super.update()
@ -203,8 +203,8 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc
* Heats up the surroundings. Control rods absorbs neutrons, reducing the heat produced.
*/
val controlRodCount = ForgeDirection.VALID_DIRECTIONS.map(toVectorWorld + _).count(_.getBlock == QuantumContent.blockControlRod)
ThermalGrid.addHeat(toVectorWorld, internalEnergy / ((controlRodCount + 1) * 0.3))
val temperature = ThermalGrid.getTemperature(toVectorWorld)
GridThermal.addHeat(toVectorWorld, internalEnergy / ((controlRodCount + 1) * 0.3))
val temperature = GridThermal.getTemperature(toVectorWorld)
internalEnergy = 0
@ -235,7 +235,7 @@ class TileReactorCell extends TileInventory(Material.iron) with IMultiBlockStruc
}
else
{
val temperature = ThermalGrid.getTemperature(toVectorWorld)
val temperature = GridThermal.getTemperature(toVectorWorld)
if (world.rand.nextInt(5) == 0 && temperature >= 373)
{