Laser Receiver outputs Redstone

This commit is contained in:
Timo Ley 2021-04-11 14:05:50 +02:00
parent dad20980a2
commit ef6c5c7a57

View file

@ -9,6 +9,7 @@ import net.minecraft.block.material.Material
import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.EntityLivingBase
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.util.{MovingObjectPosition, ResourceLocation} import net.minecraft.util.{MovingObjectPosition, ResourceLocation}
import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11._ import org.lwjgl.opengl.GL11._
import resonantengine.lib.grid.energy.electric.NodeElectricComponent import resonantengine.lib.grid.energy.electric.NodeElectricComponent
@ -34,22 +35,27 @@ class TileLaserReceiver extends ResonantTile(Material.rock) with ILaserHandler w
private var energy = 0D private var energy = 0D
var redstoneValue = 0
private var prevRedstoneValue = 0;
domain = "" domain = ""
textureName = "stone" textureName = "stone"
normalRender = false normalRender = false
isOpaqueCube = false isOpaqueCube = false
nodes.add(electricNode) nodes.add(electricNode)
providePower = true
electricNode.dynamicTerminals = true electricNode.dynamicTerminals = true
electricNode.setPositives(Set(ForgeDirection.NORTH, ForgeDirection.EAST)) electricNode.setPositives(Set(ForgeDirection.NORTH, ForgeDirection.EAST))
electricNode.setNegatives(Set(ForgeDirection.SOUTH, ForgeDirection.WEST)) electricNode.setNegatives(Set(ForgeDirection.SOUTH, ForgeDirection.WEST))
override def canUpdate: Boolean = false override def canUpdate: Boolean = true
override def onLaserHit(renderStart: Vector3, incident: Vector3, hit: MovingObjectPosition, color: Vector3, energy: Double): Boolean = override def onLaserHit(renderStart: Vector3, incident: Vector3, hit: MovingObjectPosition, color: Vector3, energy: Double): Boolean =
{ {
if (hit.sideHit == getDirection.ordinal) if (hit.sideHit == getDirection.ordinal)
{ {
this.energy += energy
electricNode.generatePower(energy) electricNode.generatePower(energy)
} }
@ -109,4 +115,35 @@ class TileLaserReceiver extends ResonantTile(Material.rock) with ILaserHandler w
glPopMatrix() glPopMatrix()
} }
override def update()
{
super.update()
if (energy > 0)
{
redstoneValue = Math.min(Math.ceil(energy / (Laser.maxEnergy / 15)), 15).toInt
if (redstoneValue != prevRedstoneValue)
{
world.notifyBlocksOfNeighborChange(x.toInt, y.toInt, z.toInt, getBlockType)
ForgeDirection.VALID_DIRECTIONS.foreach(dir => world.notifyBlocksOfNeighborChange(x.toInt + dir.offsetX, y.toInt + dir.offsetY, z.toInt + dir.offsetZ, getBlockType))
prevRedstoneValue = redstoneValue
}
energy = 0
}
else
{
redstoneValue = 0
if (redstoneValue != prevRedstoneValue)
{
world.notifyBlocksOfNeighborChange(x.toInt, y.toInt, z.toInt, getBlockType)
ForgeDirection.VALID_DIRECTIONS.foreach(dir => world.notifyBlocksOfNeighborChange(x.toInt + dir.offsetX, y.toInt + dir.offsetY, z.toInt + dir.offsetZ, getBlockType))
prevRedstoneValue = redstoneValue
}
}
}
override def getWeakRedstonePower(access: IBlockAccess, side: Int): Int = redstoneValue
} }