Update to new DC circuit

This commit is contained in:
Calclavia 2014-10-26 22:41:40 +08:00
parent b694f8b1f8
commit cc7d1599f5
29 changed files with 487 additions and 449 deletions

View file

@ -98,7 +98,7 @@ class TileGrate extends TilePressureNode(Material.rock) with IRotatable
val pressure = getPressure(getDirection)
val blockEffect = Math.abs(pressure * grateEffectMultiplier).toInt
setCapacity(Math.max(blockEffect * FluidContainerRegistry.BUCKET_VOLUME * grateDrainSpeedMultiplier,
FluidContainerRegistry.BUCKET_VOLUME).toInt)
FluidContainerRegistry.BUCKET_VOLUME).toInt)
if (pressure > 0)
{
if (getFluidAmount >= FluidContainerRegistry.BUCKET_VOLUME)
@ -163,8 +163,7 @@ class TileGrate extends TilePressureNode(Material.rock) with IRotatable
if (!world.isRemote)
{
fillOver = !fillOver
player.addChatMessage(new ChatComponentText("Grate now set to " + (if (fillOver) "" else "not ") +
"fill higher than itself."))
player.addChatMessage(new ChatComponentText("Grate now set to " + (if (fillOver) "" else "not ") + "fill higher than itself."))
gratePath = null
}
return true
@ -181,18 +180,18 @@ class TileGrate extends TilePressureNode(Material.rock) with IRotatable
var navigationMap: HashMap[Vector3, Vector3] = new HashMap[Vector3, Vector3]()
var workingNodes: PriorityQueue[ComparableVector] = if (checkVertical) new PriorityQueue[ComparableVector]()
else new PriorityQueue[ComparableVector](1024,
new Comparator[ComparableVector]()
{
var workingNodes: PriorityQueue[ComparableVector] =
if (checkVertical) new PriorityQueue[ComparableVector]()
else new PriorityQueue[ComparableVector](1024, new Comparator[ComparableVector]()
{
override def compare(a: ComparableVector, b: ComparableVector): Int =
{
val wa = a.asInstanceOf[TileGrate.ComparableVector]
val wb = b.asInstanceOf[TileGrate.ComparableVector]
wa.iterations - wb.iterations
}
})
override def compare(a: ComparableVector, b: ComparableVector): Int =
{
val wa = a.asInstanceOf[TileGrate.ComparableVector]
val wb = b.asInstanceOf[TileGrate.ComparableVector]
wa.iterations - wb.iterations
}
})
var drainNodes: PriorityQueue[ComparableVector] = new PriorityQueue[ComparableVector](1024, Collections.reverseOrder())
@ -231,7 +230,7 @@ class TileGrate extends TilePressureNode(Material.rock) with IRotatable
return 0
}
val didFill = FluidUtility.fillBlock(TileGrate.this.worldObj, next.position, new FluidStack(fluidType,
amount), true)
amount), true)
filled += didFill
if (FluidUtility.getFluidAmountFromBlock(TileGrate.this.worldObj, next.position) >
0 ||

View file

@ -13,7 +13,7 @@ import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidContainerRegistry, FluidStack, FluidTank, IFluidTank}
import org.lwjgl.opengl.GL11
import resonant.api.IRemovable.ISneakPickup
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
import resonant.lib.utility.FluidUtility
import resonant.lib.utility.render.RenderBlockUtility

View file

@ -6,7 +6,7 @@ import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
import net.minecraftforge.client.IItemRenderer
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -16,7 +16,7 @@ class GuiNuclearBoiler(player: EntityPlayer, tileEntity: TileNuclearBoiler) exte
{
this.fontRendererObj.drawString("Boiler", 52, 6, 4210752)
this.renderUniversalDisplay(8, 112, TileNuclearBoiler.DIAN * 20, mouseX, mouseY, UnitDisplay.Unit.WATT)
this.renderUniversalDisplay(110, 112, tileEntity.getVoltage, mouseX, mouseY, UnitDisplay.Unit.VOLTAGE)
//this.renderUniversalDisplay(110, 112, tileEntity.getVoltage, mouseX, mouseY, UnitDisplay.Unit.VOLTAGE)
this.fontRendererObj.drawString("The nuclear boiler can boil", 8, 75, 4210752)
this.fontRendererObj.drawString("yellow cake into uranium", 8, 85, 4210752)
this.fontRendererObj.drawString("hexafluoride gas to be refined.", 8, 95, 4210752)

View file

@ -15,7 +15,7 @@ import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.{glPopMatrix, glPushMatrix, glRotatef}
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
import universalelectricity.core.transform.vector.Vector3

View file

@ -41,11 +41,10 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
private var markClientUpdate: Boolean = false
private var markDistributionUpdate: Boolean = false
var renderEnergyAmount: Double = 0
private var network: GridBattery = null
//Constructor
textureName = "material_metal_side"
ioMap = 0.toShort
ioMap = 0
saveIOMap = true
normalRender = false
isOpaqueCube = false
@ -57,12 +56,11 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
if (!world.isRemote)
{
//TODO: Test, remove this
if (doCharge)
{
dcNode.negativeTerminals.addAll(getInputDirections())
//TODO: Test, remove this
dcNode.positiveTerminals.addAll(getOutputDirections())
dcNode.buffer(100)
dcNode.update(1/20f)
doCharge = false
}
@ -87,9 +85,13 @@ class TileBattery extends TileAdvanced(Material.iron) with TElectric with IPacke
if (!world.isRemote)
{
if (player.isSneaking)
{
doCharge = !doCharge
}
println(dcNode)
}
return true
}

View file

@ -9,7 +9,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -6,6 +6,8 @@ import net.minecraft.block.material.Material
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.IRotatable
import resonant.content.prefab.java.TileNode
import resonant.lib.content.prefab.TElectric
import resonant.lib.content.prefab.java.TileElectric
import resonantinduction.core.interfaces.IMechanicalNode
import universalelectricity.api.core.grid.{IUpdate, INode, NodeRegistry}
@ -15,9 +17,9 @@ import universalelectricity.api.core.grid.{IUpdate, INode, NodeRegistry}
*
* @author Calclavia
*/
class TileMotor extends TileElectric(Material.iron) with IRotatable {
class TileMotor extends TileNode(Material.iron) with TElectric with IRotatable {
var mech_node : IMechanicalNode = NodeRegistry.get(this, classOf[IMechanicalNode])
var mechNode : IMechanicalNode = NodeRegistry.get(this, classOf[IMechanicalNode])
/** Generator turns KE -> EE. Inverted one will turn EE -> KE. */
var isInversed: Boolean = true
private var gearRatio: Byte = 0
@ -32,18 +34,18 @@ class TileMotor extends TileElectric(Material.iron) with IRotatable {
override def start {
super.start
if (mech_node != null) mech_node.reconstruct
if (mechNode != null) mechNode.reconstruct
}
override def invalidate {
mech_node.deconstruct
mechNode.deconstruct
super.invalidate
}
override def update {
super.update
if (mech_node != null && mech_node.isInstanceOf[IUpdate]) {
mech_node.asInstanceOf[IUpdate].update(0.05f)
if (mechNode != null && mechNode.isInstanceOf[IUpdate]) {
mechNode.asInstanceOf[IUpdate].update(0.05f)
if (!isInversed) {
receiveMechanical
}
@ -54,16 +56,16 @@ class TileMotor extends TileElectric(Material.iron) with IRotatable {
}
def receiveMechanical {
val power: Double = mech_node.getForce(ForgeDirection.UNKNOWN) * mech_node.getAngularSpeed(ForgeDirection.UNKNOWN)
val receive: Double = electricNode.addEnergy(ForgeDirection.UNKNOWN, power, true)
val power: Double = mechNode.getForce(ForgeDirection.UNKNOWN) * mechNode.getAngularSpeed(ForgeDirection.UNKNOWN)
val receive: Double =0// dcNode.addEnergy(ForgeDirection.UNKNOWN, power, true)
if (receive > 0) {
val percentageUsed: Double = receive / power
mech_node.apply(this, -mech_node.getForce(ForgeDirection.UNKNOWN) * percentageUsed, -mech_node.getAngularSpeed(ForgeDirection.UNKNOWN) * percentageUsed)
mechNode.apply(this, -mechNode.getForce(ForgeDirection.UNKNOWN) * percentageUsed, -mechNode.getAngularSpeed(ForgeDirection.UNKNOWN) * percentageUsed)
}
}
def produceMechanical {
val extract: Double = electricNode.removeEnergy(ForgeDirection.UNKNOWN, electricNode.getEnergy(ForgeDirection.UNKNOWN), false)
val extract: Double = 0//dcNode.removeEnergy(ForgeDirection.UNKNOWN, dcNode.getEnergy(ForgeDirection.UNKNOWN), false)
if (extract > 0) {
val torqueRatio: Long = ((gearRatio + 1) / 2.2d * (extract)).asInstanceOf[Long]
if (torqueRatio > 0) {
@ -71,12 +73,12 @@ class TileMotor extends TileElectric(Material.iron) with IRotatable {
val maxTorque: Double = (extract) / maxAngularVelocity
var setAngularVelocity: Double = maxAngularVelocity
var setTorque: Double = maxTorque
val currentTorque: Double = Math.abs(mech_node.getForce(ForgeDirection.UNKNOWN))
if (currentTorque != 0) { setTorque = Math.min(setTorque, maxTorque) * (mech_node.getForce(ForgeDirection.UNKNOWN) / currentTorque) }
val currentVelo: Double = Math.abs(mech_node.getAngularSpeed(ForgeDirection.UNKNOWN))
if (currentVelo != 0) setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (mech_node.getAngularSpeed(ForgeDirection.UNKNOWN) / currentVelo)
mech_node.apply(this, setTorque - mech_node.getForce(ForgeDirection.UNKNOWN), setAngularVelocity - mech_node.getAngularSpeed(ForgeDirection.UNKNOWN))
electricNode.removeEnergy(ForgeDirection.UNKNOWN, Math.abs(setTorque * setAngularVelocity).asInstanceOf[Long], true)
val currentTorque: Double = Math.abs(mechNode.getForce(ForgeDirection.UNKNOWN))
if (currentTorque != 0) { setTorque = Math.min(setTorque, maxTorque) * (mechNode.getForce(ForgeDirection.UNKNOWN) / currentTorque) }
val currentVelo: Double = Math.abs(mechNode.getAngularSpeed(ForgeDirection.UNKNOWN))
if (currentVelo != 0) setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (mechNode.getAngularSpeed(ForgeDirection.UNKNOWN) / currentVelo)
mechNode.apply(this, setTorque - mechNode.getForce(ForgeDirection.UNKNOWN), setAngularVelocity - mechNode.getAngularSpeed(ForgeDirection.UNKNOWN))
// dcNode.removeEnergy(ForgeDirection.UNKNOWN, Math.abs(setTorque * setAngularVelocity).asInstanceOf[Long], true)
}
}
}
@ -107,15 +109,15 @@ class TileMotor extends TileElectric(Material.iron) with IRotatable {
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode = {
if (from == getDirection || from == getDirection.getOpposite) {
if (nodeType.isAssignableFrom(mech_node.getClass)) return mech_node
if (nodeType.isAssignableFrom(mechNode.getClass)) return mechNode
}
return super.getNode(nodeType, from)
}
override def getNodes(nodes: java.util.List[INode])
{
nodes.add(this.mech_node)
nodes.add(this.electricNode)
nodes.add(this.mechNode)
nodes.add(this.dcNode)
}
override def toString: String = {

View file

@ -43,7 +43,7 @@ class TileThermopile extends TileElectric(Material.rock) {
}
val multiplier: Int = (3 - Math.abs(heatSources - coolingSources))
if (multiplier > 0 && coolingSources > 0 && heatSources > 0) {
electricNode.addEnergy(ForgeDirection.UNKNOWN, 15 * multiplier, true)
// electricNode.addEnergy(ForgeDirection.UNKNOWN, 15 * multiplier, true)
if (({
usingTicks += 1; usingTicks
}) >= MAX_USE_TICKS) {

View file

@ -8,7 +8,7 @@ import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonant.lib.utility.LanguageUtility
import resonantinduction.core.Reference

View file

@ -4,20 +4,20 @@ import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.compatibility.Compatibility
import universalelectricity.core.grid.node.NodeElectric
import universalelectricity.core.grid.node.DCNode
import universalelectricity.core.transform.vector.VectorWorld
/**
* Created by robert on 8/11/2014.
*/
class ElectricTransformerNode(parent: INodeProvider) extends NodeElectric(parent: INodeProvider)
class ElectricTransformerNode(parent: INodeProvider) extends DCNode(parent: INodeProvider)
{
var connectionDirection : ForgeDirection = ForgeDirection.NORTH
var input : Boolean = true;
var otherNode : ElectricTransformerNode = null
var step : Int = 2
var connectionDirection: ForgeDirection = ForgeDirection.NORTH
var input: Boolean = true;
var otherNode: ElectricTransformerNode = null
var step: Int = 2
def this(parent: INodeProvider, side: ForgeDirection, in : Boolean) =
def this(parent: INodeProvider, side: ForgeDirection, in: Boolean) =
{
this(parent)
connectionDirection = side
@ -26,21 +26,22 @@ class ElectricTransformerNode(parent: INodeProvider) extends NodeElectric(parent
def getVoltage: Double =
{
if(!input)
if (!input)
{
return otherNode.getVoltage * step
}
return 120
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
return source.isInstanceOf[INodeProvider] && from == connectionDirection
}
/*
override def addEnergy(dir: ForgeDirection, wattage: Double, doAdd: Boolean): Double =
{
if(input)
if (input)
{
return otherNode.sendEnergy(wattage, doAdd)
}
@ -49,17 +50,16 @@ class ElectricTransformerNode(parent: INodeProvider) extends NodeElectric(parent
def sendEnergy(wattage: Double, doAdd: Boolean): Double =
{
val tile : TileEntity = new VectorWorld(parent.asInstanceOf[TileEntity]).add(connectionDirection).getTileEntity
if(Compatibility.isHandler(tile,connectionDirection.getOpposite))
val tile: TileEntity = new VectorWorld(parent.asInstanceOf[TileEntity]).add(connectionDirection).getTileEntity
if (Compatibility.isHandler(tile, connectionDirection.getOpposite))
{
return Compatibility.fill(tile, connectionDirection.getOpposite, wattage, doAdd)
}
return 0
}
override def removeEnergy(dir: ForgeDirection, wattage: Double, doRemove: Boolean) : Double =
override def removeEnergy(dir: ForgeDirection, wattage: Double, doRemove: Boolean): Double =
{
return 0
}
}*/
}

View file

@ -9,7 +9,7 @@ import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.obj.WavefrontObject
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -7,7 +7,7 @@ import net.minecraftforge.common.util.ForgeDirection
import resonantinduction.core.prefab.part.connector._
import resonantinduction.electrical.ElectricalContent
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.simulator.dc.micro.DCNode
import universalelectricity.core.grid.node.DCNode
/**
* Abstract class extended by both flat and framed wires to handle material, insulation, color and multipart node logic.
@ -77,6 +77,7 @@ trait TWire extends PartAbstract with TNodePartConnector with TMaterial[WireMate
}
/**
* TODO: This is very messy. Need to reorganize canConnectTo
* Can this conductor connect with another potential wire object?
*/
def canConnectTo(obj: AnyRef): Boolean =

View file

@ -22,7 +22,7 @@ import resonantinduction.core.prefab.part.connector.PartAbstract
import resonantinduction.core.util.MultipartUtil
import resonantinduction.electrical.wire.base.TWire
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.simulator.dc.micro.DCNode
import universalelectricity.core.grid.node.DCNode
import scala.collection.convert.wrapAll._
@ -88,8 +88,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
override def update()
{
super.update()
//TODO: Temporary test. Remove
node.update(1 / 20f)
if (node.current > 0)
println("CURRENT!" + node.current)
}
override def activate(player: EntityPlayer, hit: MovingObjectPosition, item: ItemStack): Boolean =
@ -350,7 +351,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
*/
class FlatWireNode(provider: INodeProvider) extends DCNode(provider) with TMultipartNode
{
override def buildConnections()
override def reconstruct()
{
if (!world.isRemote)
{
@ -419,47 +420,54 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
val pos = new BlockCoord(tile).offset(absDir)
val tilePart = MultipartUtil.getMultipartTile(world, pos)
val forgeDir = ForgeDirection.getOrientation(absDir)
val fromDir = ForgeDirection.getOrientation(absDir).getOpposite
if (tilePart != null && r != -1)
{
val part = tilePart.partMap(side)
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
{
val otherR = (r + 2) % 4
val forgeDir = ForgeDirection.getOrientation(absDir)
val wireNode = getWireNode(part, forgeDir)
val dcNode = getComponent(part, fromDir)
//Check if it's another flat wire.
if (wireNode != null)
if (dcNode != null)
{
val wire = part.asInstanceOf[PartFlatWire]
if (wire.canConnectTo(PartFlatWire.this, ForgeDirection.getOrientation(absDir).getOpposite) && wire.maskOpen(otherR))
if (part.isInstanceOf[PartFlatWire])
{
connections.put(wireNode, forgeDir)
val wire = part.asInstanceOf[PartFlatWire]
if (wire.canConnectTo(PartFlatWire.this, fromDir) && wire.maskOpen(otherR))
{
connections.put(dcNode, forgeDir)
return true
}
}
else if (canConnectTo(part))
{
connections.put(dcNode, forgeDir)
return true
}
}
//TODO: Change to node
//Check if it's a component.
if (canConnectTo(part))
{
connections.put(part, forgeDir)
return true
}
}
disconnect(absDir)
}
/**
* Can't find another wire. Try TileEntity.
*/
val tileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
val forgeDir = ForgeDirection.getOrientation(absDir)
val tileComponent = getComponent(tileEntity, fromDir)
if (canConnectTo(tileEntity, forgeDir))
{
//TODO: Change to node
connections.put(tileEntity, forgeDir)
connections.put(tileComponent, forgeDir)
return true
}
@ -485,6 +493,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (canConnectTo(part, absForgeDir))
{
//TODO: Connect to node, not part.
connections.put(part, absForgeDir)
return true
}
@ -652,17 +661,17 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (t != null)
{
val tp = t.partMap(absDir ^ 1)
val part = t.partMap(absDir ^ 1)
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
{
val wire = getWireNode(tp, ForgeDirection.getOrientation(absDir))
val component = getComponent(part, ForgeDirection.getOrientation(absDir))
if (wire != null)
if (component.isInstanceOf[FlatWireNode])
{
if (wire.connectCorner(PartFlatWire.this, Rotation.rotationTo(absDir ^ 1, side ^ 1)))
if (component.asInstanceOf[FlatWireNode].connectCorner(PartFlatWire.this, Rotation.rotationTo(absDir ^ 1, side ^ 1)))
{
if (!renderThisCorner(tp.asInstanceOf[PartFlatWire]))
if (!renderThisCorner(part.asInstanceOf[PartFlatWire]))
{
return 1
}
@ -696,21 +705,21 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
val t: TileMultipart = MultipartUtil.getMultipartTile(world, pos)
if (t != null)
{
val tp: TMultiPart = t.partMap(side)
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
val part = t.partMap(side)
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
{
val wire = getWireNode(tp, ForgeDirection.getOrientation(absDir))
val component = getComponent(part, ForgeDirection.getOrientation(absDir))
if (wire != null)
if (component.isInstanceOf[FlatWireNode])
{
return wire.connectStraight(PartFlatWire.this, (r + 2) % 4)
return component.asInstanceOf[FlatWireNode].connectStraight(PartFlatWire.this, (r + 2) % 4)
}
return true
}
}
else
{
val tileEntity: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
val tileEntity = world.getTileEntity(pos.x, pos.y, pos.z)
return canConnectTo(tileEntity, ForgeDirection.getOrientation(absDir))
}
return false
@ -723,13 +732,14 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
{
return false
}
val tp: TMultiPart = tile.partMap(absDir)
val part: TMultiPart = tile.partMap(absDir)
if (canConnectTo(tp, ForgeDirection.getOrientation(absDir)))
if (canConnectTo(part, ForgeDirection.getOrientation(absDir)))
{
val wire = getWireNode(tp, ForgeDirection.getOrientation(absDir))
if (wire != null)
return wire.connectInternal(PartFlatWire.this, Rotation.rotationTo(absDir, side))
val component = getComponent(part, ForgeDirection.getOrientation(absDir))
if (component.isInstanceOf[FlatWireNode])
return component.asInstanceOf[FlatWireNode].connectInternal(PartFlatWire.this, Rotation.rotationTo(absDir, side))
}
return false
@ -802,13 +812,13 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
return false
}
private def getWireNode(obj: AnyRef, from: ForgeDirection): FlatWireNode =
/**
* Gets a potential DCNode from an object.
*/
private def getComponent(obj: AnyRef, from: ForgeDirection): DCNode =
{
if (obj.isInstanceOf[FlatWireNode])
return obj.asInstanceOf[FlatWireNode]
if (obj.isInstanceOf[INodeProvider])
return getWireNode(obj.asInstanceOf[INodeProvider].getNode(classOf[FlatWireNode], from), from)
return obj.asInstanceOf[INodeProvider].getNode(classOf[DCNode], from).asInstanceOf[DCNode]
return null
}

View file

@ -11,7 +11,7 @@ import resonant.lib.wrapper.BitmaskWrapper._
import resonantinduction.core.prefab.node.TMultipartNode
import resonantinduction.core.prefab.part.connector.PartFramedNode
import resonantinduction.electrical.wire.base.TWire
import universalelectricity.simulator.dc.micro.DCNode
import universalelectricity.core.grid.node.DCNode
/**
* Fluid transport pipe
@ -22,12 +22,12 @@ class PartFramedWire extends PartFramedNode with TWire
{
override lazy val node = new DCNode(this) with TMultipartNode
{
override def buildConnections()
override def reconstruct()
{
val prevCon = connectionMask
connectionMask = 0x00
super.buildConnections()
super.reconstruct()
if (connectionMask != prevCon)
sendConnectionUpdate()

View file

@ -16,7 +16,7 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
{
def pipe: PartPipe = getParent.asInstanceOf[PartPipe]
override def buildConnections()
override def reconstruct()
{
connections.clear()
@ -35,13 +35,13 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
{
val check = tile.asInstanceOf[INodeProvider].getNode(classOf[NodePressure], dir.getOpposite)
if (check.isInstanceOf[NodePressure] && canConnect(dir, check) && check.asInstanceOf[NodePressure].canConnect(dir.getOpposite, this))
if (check.isInstanceOf[NodePressure] && canConnect(check,dir) && check.asInstanceOf[NodePressure].canConnect(this, dir.getOpposite))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connections.put(check, dir)
}
}
else if (canConnect(dir, tile))
else if (canConnect(tile,dir))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connections.put(tile, dir)
@ -56,7 +56,7 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
}
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
if (!pipe.isBlockedOnSide(from))
{
@ -74,7 +74,7 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
return false
}
return super.canConnect(from, source) || source.isInstanceOf[IFluidHandler]
return super.canConnect(source, from) || source.isInstanceOf[IFluidHandler]
}
return false

View file

@ -9,7 +9,7 @@ import net.minecraftforge.client.IItemRenderer.ItemRenderType
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
import resonant.lib.utility.WorldUtility
import resonantinduction.core.Reference

View file

@ -9,26 +9,26 @@ import universalelectricity.api.core.grid.INodeProvider
*/
class PumpNode(parent: INodeProvider) extends NodePressure(parent)
{
def pump : TilePump = getParent.asInstanceOf[TilePump]
def pump: TilePump = getParent.asInstanceOf[TilePump]
override def getPressure(dir: ForgeDirection): Int =
override def getPressure(dir: ForgeDirection): Int =
{
if (pump.mechanicalNode.getPower > 0)
{
if (pump.mechanicalNode.getPower > 0)
{
if (dir == pump.getDirection)
{
return Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int]
}
else if (dir == pump.getDirection.getOpposite)
{
return -Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int]
}
}
return 0
if (dir == pump.getDirection)
{
return Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int]
}
else if (dir == pump.getDirection.getOpposite)
{
return -Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int]
}
}
return 0
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
return super.canConnect(from, source) && (from == pump.getDirection || from == pump.getDirection.getOpposite)
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
return super.canConnect(source, from) && (from == pump.getDirection || from == pump.getDirection.getOpposite)
}
}

View file

@ -1,8 +1,5 @@
package resonantinduction.mechanical.mech;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.lib.utility.nbt.ISaveObj;
@ -14,6 +11,9 @@ import universalelectricity.api.core.grid.IUpdate;
import universalelectricity.core.grid.node.NodeConnector;
import universalelectricity.core.transform.vector.IVectorWorld;
import java.util.Iterator;
import java.util.Map.Entry;
/**
* Prefab node for the mechanical system used by almost ever mechanical object in Resonant Induction. Handles connections to other tiles, and shares power with them
*
@ -22,33 +22,44 @@ import universalelectricity.core.transform.vector.IVectorWorld;
//Don't convert to scala as this will find its way into RE later - From Darkguardsman
public class MechanicalNode extends NodeConnector implements TMultipartNode, IMechanicalNode, ISaveObj, IVectorWorld, IUpdate
{
/** Marks that the rotation has changed and should be updated client side */
/**
* Marks that the rotation has changed and should be updated client side
*/
public boolean markRotationUpdate = false;
/** Makrs that the torque value has changed and should be updated client side */
/**
* Makrs that the torque value has changed and should be updated client side
*/
public boolean markTorqueUpdate = false;
/** Allows the node to share its power with other nodes*/
public boolean sharePower = true;
/**
* Allows the node to share its power with other nodes
*/
public boolean sharePower = true;
public double torque = 0, prevTorque;
public double prevAngularVelocity, angularVelocity = 0;
/** Current angle of rotation, mainly used for rendering */
public double renderAngle = 0;
/**
* Current angle of rotation, mainly used for rendering
*/
public double renderAngle = 0;
/** Angle of rotation of last update */
public double prev_angle = 0;
/**
* Angle of rotation of last update
*/
public double prev_angle = 0;
public float acceleration = 2f;
protected double maxDeltaAngle = Math.toRadians(120);
protected double load = 2;
private double power = 0;
/** Current update tick # */
/**
* Current update tick #
*/
private long ticks = 0;
public MechanicalNode(INodeProvider parent)
@ -62,25 +73,25 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
return 0.5;
}
@Override
public double getAngularSpeed(ForgeDirection side)
{
return angularVelocity;
}
@Override
public double getAngularSpeed(ForgeDirection side)
{
return angularVelocity;
}
@Override
public double getForce(ForgeDirection side)
{
return torque;
}
@Override
public double getForce(ForgeDirection side)
{
return torque;
}
@Override
public boolean inverseRotation(ForgeDirection side)
{
return false;
}
@Override
public boolean inverseRotation(ForgeDirection side)
{
return false;
}
final public void update()
final public void update()
{
update(0.05f);
}
@ -98,7 +109,7 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
// Render Update
//-----------------------------------
// Updates rotation angle and prevents it from rotating too fast
// Updates rotation angle and prevents it from rotating too fast
if (angularVelocity >= 0)
{
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
@ -108,11 +119,11 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
}
// Cap rotation angle to prevent render issues
// Cap rotation angle to prevent render issues
if (renderAngle >= Math.PI * 2)
{
revolve();
renderAngle = renderAngle % (Math.PI * 2);
renderAngle = renderAngle % (Math.PI * 2);
}
//-----------------------------------
@ -150,82 +161,92 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
power = getEnergy() / deltaTime;
if(sharePower)
{
// Power sharing calculations
Iterator<Entry<Object, ForgeDirection>> it = connections.entrySet().iterator();
if (sharePower)
{
// Power sharing calculations
Iterator<Entry<Object, ForgeDirection>> it = getConnections().entrySet().iterator();
while (it.hasNext())
{
MechanicalNode adjacentMech = null;
Entry<Object, ForgeDirection> entry = it.next();
ForgeDirection dir = entry.getValue();
while (it.hasNext())
{
MechanicalNode adjacentMech = null;
Entry<Object, ForgeDirection> entry = it.next();
ForgeDirection dir = entry.getValue();
// Get mech node
if (entry.getKey() instanceof MechanicalNode)
{
adjacentMech = (MechanicalNode) entry.getKey();
}
else if (entry.getKey() instanceof INodeProvider)
{
INode node = ((INodeProvider) entry.getKey()).getNode(MechanicalNode.class, dir.getOpposite());
if (node instanceof MechanicalNode)
adjacentMech = (MechanicalNode) node;
}
else
{
it.remove();
}
// Get mech node
if (entry.getKey() instanceof MechanicalNode)
{
adjacentMech = (MechanicalNode) entry.getKey();
}
else if (entry.getKey() instanceof INodeProvider)
{
INode node = ((INodeProvider) entry.getKey()).getNode(MechanicalNode.class, dir.getOpposite());
if (node instanceof MechanicalNode)
{
adjacentMech = (MechanicalNode) node;
}
}
else
{
it.remove();
}
// If node is not null apply power
if (adjacentMech != null)
{
/** Calculate angular velocity and torque. */
double ratio = adjacentMech.getRadius(dir.getOpposite(), this) / getRadius(dir, adjacentMech);
boolean inverseRotation = inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite());
// If node is not null apply power
if (adjacentMech != null)
{
/** Calculate angular velocity and torque. */
double ratio = adjacentMech.getRadius(dir.getOpposite(), this) / getRadius(dir, adjacentMech);
boolean inverseRotation = inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite());
int inversion = inverseRotation ? -1 : 1;
int inversion = inverseRotation ? -1 : 1;
double targetTorque = inversion * adjacentMech.getTorque() / ratio;
double applyTorque = targetTorque * acceleration;
double targetTorque = inversion * adjacentMech.getTorque() / ratio;
double applyTorque = targetTorque * acceleration;
if (Math.abs(torque + applyTorque) < Math.abs(targetTorque)) {
torque += applyTorque;
} else if (Math.abs(torque - applyTorque) > Math.abs(targetTorque)) {
torque -= applyTorque;
}
if (Math.abs(torque + applyTorque) < Math.abs(targetTorque))
{
torque += applyTorque;
}
else if (Math.abs(torque - applyTorque) > Math.abs(targetTorque))
{
torque -= applyTorque;
}
double targetVelocity = inversion * adjacentMech.getAngularSpeed() * ratio;
double applyVelocity = targetVelocity * acceleration;
double targetVelocity = inversion * adjacentMech.getAngularSpeed() * ratio;
double applyVelocity = targetVelocity * acceleration;
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity)) {
angularVelocity += applyVelocity;
} else if (Math.abs(angularVelocity - applyVelocity) > Math.abs(targetVelocity)) {
angularVelocity -= applyVelocity;
}
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity))
{
angularVelocity += applyVelocity;
}
else if (Math.abs(angularVelocity - applyVelocity) > Math.abs(targetVelocity))
{
angularVelocity -= applyVelocity;
}
/** Set all current rotations */
// adjacentMech.angle = Math.abs(angle) * (adjacentMech.angle >= 0 ? 1 : -1);
}
}
}
}
/** Set all current rotations */
// adjacentMech.angle = Math.abs(angle) * (adjacentMech.angle >= 0 ? 1 : -1);
}
}
}
}
onUpdate();
prev_angle = renderAngle;
}
@Override
public boolean canUpdate() {
return true;
}
@Override
public boolean canUpdate()
{
return true;
}
@Override
public boolean continueUpdate() {
return true;
}
@Override
public boolean continueUpdate()
{
return true;
}
protected void onUpdate()
protected void onUpdate()
{
}
@ -292,22 +313,23 @@ public class MechanicalNode extends NodeConnector implements TMultipartNode, IMe
nbt.setDouble("angularVelocity", angularVelocity);
}
@Override
public boolean canConnect(ForgeDirection direction, Object object)
{
if(canConnect(direction)) {
if (object instanceof INodeProvider)
{
return ((INodeProvider) object).getNode(MechanicalNode.class, direction.getOpposite()) instanceof MechanicalNode;
}
return object instanceof MechanicalNode;
}
return false;
}
@Override
public boolean canConnect(Object object, ForgeDirection direction)
{
if (canConnect(direction))
{
if (object instanceof INodeProvider)
{
return ((INodeProvider) object).getNode(MechanicalNode.class, direction.getOpposite()) instanceof MechanicalNode;
}
return object instanceof MechanicalNode;
}
return false;
}
@Override
public boolean isValidConnection(Object object)
{
return true;
}
@Override
public boolean isValidConnection(Object object)
{
return true;
}
}

View file

@ -54,7 +54,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
return 0.3
}
override def buildConnections
override def reconstruct()
{
connections.clear
if (!gear.getMultiBlock.isPrimary || world == null)
@ -65,7 +65,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
if (tileBehind.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (tileBehind.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide.getOpposite).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && !(instance.getParent.isInstanceOf[PartGearShaft]) && instance.canConnect(gear.placementSide.getOpposite, this))
if (instance != null && instance != this && !(instance.getParent.isInstanceOf[PartGearShaft]) && instance.canConnect(this,gear.placementSide.getOpposite))
{
addConnection(instance, gear.placementSide)
}
@ -81,7 +81,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
if (tile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode]
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(checkDir.getOpposite, this))
if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(this,checkDir.getOpposite))
{
addConnection(instance, checkDir)
}
@ -99,7 +99,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
if (!connections.containsValue(checkDir) && checkTile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this) && !(instance.getParent.isInstanceOf[PartGearShaft]))
if (instance != null && instance != this && instance.canConnect(this,checkDir.getOpposite) && !(instance.getParent.isInstanceOf[PartGearShaft]))
{
addConnection(instance, checkDir)
}
@ -114,7 +114,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
* @param with - The source of the connection.
* @return True is so.
*/
override def canConnect(from: ForgeDirection, `with`: AnyRef): Boolean =
override def canConnect(`with`: AnyRef,from: ForgeDirection): Boolean =
{
if (!gear.getMultiBlock.isPrimary)
{

View file

@ -9,7 +9,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -10,83 +10,84 @@ import universalelectricity.core.transform.vector.Vector3
class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
{
override def getTorqueLoad: Double =
override def getTorqueLoad: Double =
{
shaft.tier match
{
shaft.tier match
case 1 =>
return 0.02
case 2 =>
return 0.01
case _ =>
return 0.03
}
}
override def getAngularVelocityLoad: Double =
{
return 0
}
override def reconstruct()
{
connections.clear
for (ch <- List(shaft.placementSide, shaft.placementSide.getOpposite))
{
val checkDir: ForgeDirection = ch
if (checkDir == shaft.placementSide || checkDir == shaft.placementSide.getOpposite)
{
if (shaft.tile.isInstanceOf[INodeProvider])
{
case 1 =>
return 0.02
case 2 =>
return 0.01
case _ =>
return 0.03
val instance: MechanicalNode = (shaft.tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.canConnect(this, checkDir.getOpposite))
{
addConnection(instance, checkDir)
}
}
}
override def getAngularVelocityLoad: Double =
{
return 0
}
override def buildConnections
{
connections.clear
for(ch <- List(shaft.placementSide, shaft.placementSide.getOpposite))
else
{
val checkDir: ForgeDirection = ch
if (checkDir == shaft.placementSide || checkDir == shaft.placementSide.getOpposite)
val checkTile: TileEntity = new Vector3(shaft.tile).add(checkDir).getTileEntity(world)
if (checkTile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir.getOpposite).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.getParent.isInstanceOf[PartGearShaft] && instance.canConnect(this, checkDir.getOpposite))
{
if (shaft.tile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (shaft.tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this))
{
addConnection(instance, checkDir)
}
}else
{
val checkTile: TileEntity = new Vector3(shaft.tile).add(checkDir).getTileEntity(world)
if (checkTile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], checkDir.getOpposite).asInstanceOf[MechanicalNode]
if (instance != null && instance != this && instance.getParent.isInstanceOf[PartGearShaft] && instance.canConnect(checkDir.getOpposite, this))
{
addConnection(instance, checkDir)
}
}
}
addConnection(instance, checkDir)
}
}
}
}
}
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
if (source.isInstanceOf[MechanicalNode])
{
if (source.isInstanceOf[MechanicalNode])
if ((source.asInstanceOf[MechanicalNode]).getParent.isInstanceOf[PartGear])
{
val gear: PartGear = (source.asInstanceOf[MechanicalNode]).getParent.asInstanceOf[PartGear]
if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(shaft.placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(shaft.placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(shaft.placementSide.offsetZ)))
{
if ((source.asInstanceOf[MechanicalNode]).getParent.isInstanceOf[PartGear])
{
val gear: PartGear = (source.asInstanceOf[MechanicalNode]).getParent.asInstanceOf[PartGear]
if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(shaft.placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(shaft.placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(shaft.placementSide.offsetZ)))
{
return false
}
}
return false
}
return from == shaft.placementSide || from == shaft.placementSide.getOpposite
}
}
return from == shaft.placementSide || from == shaft.placementSide.getOpposite
}
override def inverseRotation(dir: ForgeDirection): Boolean =
override def inverseRotation(dir: ForgeDirection): Boolean =
{
if (shaft.placementSide.offsetY != 0 || shaft.placementSide.offsetZ != 0)
{
if (shaft.placementSide.offsetY != 0 || shaft.placementSide.offsetZ != 0)
{
return dir eq shaft.placementSide.getOpposite
}
return dir eq shaft.placementSide
return dir eq shaft.placementSide.getOpposite
}
return dir eq shaft.placementSide
}
def shaft: PartGearShaft =
{
return this.getParent.asInstanceOf[PartGearShaft]
}
def shaft: PartGearShaft =
{
return this.getParent.asInstanceOf[PartGearShaft]
}
}

View file

@ -8,7 +8,7 @@ import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.glRotatef
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -1,32 +1,32 @@
package resonantinduction.mechanical.mech.process.grinder
import resonantinduction.mechanical.mech.MechanicalNode
import net.minecraftforge.common.util.ForgeDirection
import resonantinduction.mechanical.mech.MechanicalNode
/** Node just for the grinder
*
* @author Darkguardsman */
class GrinderNode(parent: TileGrindingWheel) extends MechanicalNode(parent: TileGrindingWheel)
{
//constructor
sharePower = false
//constructor
sharePower = false
def grider: TileGrindingWheel =
{
return getParent.asInstanceOf[TileGrindingWheel]
}
def grider: TileGrindingWheel =
{
return getParent.asInstanceOf[TileGrindingWheel]
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
if (grider.getDirection == ForgeDirection.UP || grider.getDirection == ForgeDirection.DOWN)
{
if (grider.getDirection == ForgeDirection.UP || grider.getDirection == ForgeDirection.DOWN)
{
return grider.getDirection == from || grider.getDirection.getOpposite == from
}
return grider.getDirection != from && grider.getDirection.getOpposite != from
return grider.getDirection == from || grider.getDirection.getOpposite == from
}
return grider.getDirection != from && grider.getDirection.getOpposite != from
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return !(dir.offsetX > 0 || dir.offsetZ < 0 || dir.offsetY < 0)
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return !(dir.offsetX > 0 || dir.offsetZ < 0 || dir.offsetY < 0)
}
}

View file

@ -9,7 +9,7 @@ import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.{glPopMatrix, glPushMatrix, glRotatef, glTranslatef}
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -10,7 +10,7 @@ import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -8,7 +8,7 @@ import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.content.prefab.scal.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference

View file

@ -13,11 +13,11 @@ import net.minecraft.util.Vec3
import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
import resonant.content.prefab.itemblock.ItemBlockMetadata
import resonant.lib.wrapper.WrapList._
import resonantinduction.core.Settings
import resonantinduction.mechanical.mech.MechanicalNode
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.transform.vector.Vector3
import resonant.lib.wrapper.WrapList._
/**
* The vertical water turbine collects flowing water flowing on X axis.
@ -28,120 +28,121 @@ import resonant.lib.wrapper.WrapList._
*/
class TileWaterTurbine extends TileTurbine
{
var powerTicks: Int = 0
var powerTicks: Int = 0
//Constructor
this.itemBlock_$eq(classOf[ItemBlockMetadata])
mechanicalNode.torque = defaultTorque
mechanicalNode = new TurbineNode((this))
//Constructor
this.itemBlock_$eq(classOf[ItemBlockMetadata])
mechanicalNode.torque = defaultTorque
mechanicalNode = new TurbineNode((this))
{
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
if (source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TileTurbine]))
{
val sourceTile: TileEntity = position.add(from).getTileEntity(getWorld)
if (sourceTile.isInstanceOf[INodeProvider])
{
if (source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TileTurbine]))
val sourceInstance: MechanicalNode = sourceTile.asInstanceOf[INodeProvider].getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
return sourceInstance == source && (from == getDirection.getOpposite || from == getDirection)
}
}
return false
}
}
//End Constructor
override def update
{
super.update
if (getMultiBlock.isConstructed)
{
mechanicalNode.torque = (defaultTorque / (1d / multiBlockRadius)).asInstanceOf[Long]
}
else
{
mechanicalNode.torque = defaultTorque / 12
}
if (getDirection.offsetY != 0)
{
maxPower = 10000
if (powerTicks > 0)
{
getMultiBlock.get.power += getWaterPower
powerTicks -= 1
}
if (ticks % 20 == 0)
{
val blockIDAbove: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
val metadata: Int = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord)
val isWater: Boolean = (blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water)
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
{
powerTicks = 20
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
}
}
}
else
{
maxPower = 2500
val currentDir: ForgeDirection = getDirection
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
if (dir != currentDir && dir != currentDir.getOpposite)
{
val check: Vector3 = asVector3.add(dir)
val blockID: Block = worldObj.getBlock(check.xi, check.yi, check.zi)
val metadata: Int = worldObj.getBlockMetadata(check.xi, check.yi, check.zi)
if (blockID == Blocks.water || blockID == Blocks.flowing_water)
{
try
{
val sourceTile: TileEntity = position.add(from).getTileEntity(getWorld)
if (sourceTile.isInstanceOf[INodeProvider])
val m: Method = ReflectionHelper.findMethod(classOf[BlockDynamicLiquid], null, Array[String]("getFlowVector", "func_72202_i"), classOf[IBlockAccess], Integer.TYPE, Integer.TYPE, Integer.TYPE)
val vector: Vector3 = new Vector3(m.invoke(Blocks.water, Array(worldObj, check.xi, check.yi, check.zi)).asInstanceOf[Vec3])
if ((currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0))
{
mechanicalNode.torque = -mechanicalNode.torque
}
if (getDirection.offsetX != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f)
powerTicks = 20
}
if (getDirection.offsetZ != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f)
powerTicks = 20
}
}
catch
{
case e: Exception =>
{
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
return sourceInstance == source && (from == getDirection.getOpposite || from == getDirection)
e.printStackTrace
}
}
return false
}
}
}
}
}
//End Constructor
}
override def update
{
super.update
if (getMultiBlock.isConstructed)
{
mechanicalNode.torque = (defaultTorque / (1d / multiBlockRadius)).asInstanceOf[Long]
}
else
{
mechanicalNode.torque = defaultTorque / 12
}
if (getDirection.offsetY != 0)
{
maxPower = 10000
if (powerTicks > 0)
{
getMultiBlock.get.power += getWaterPower
powerTicks -= 1
}
if (ticks % 20 == 0)
{
val blockIDAbove: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
val metadata: Int = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord)
val isWater: Boolean = (blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water)
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
{
powerTicks = 20
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
}
}
}
else
{
maxPower = 2500
val currentDir: ForgeDirection = getDirection
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
if (dir != currentDir && dir != currentDir.getOpposite)
{
val check: Vector3 = asVector3.add(dir)
val blockID: Block = worldObj.getBlock(check.xi, check.yi, check.zi)
val metadata: Int = worldObj.getBlockMetadata(check.xi, check.yi, check.zi)
if (blockID == Blocks.water || blockID == Blocks.flowing_water)
{
try
{
val m: Method = ReflectionHelper.findMethod(classOf[BlockDynamicLiquid], null, Array[String]("getFlowVector", "func_72202_i"), classOf[IBlockAccess], Integer.TYPE, Integer.TYPE, Integer.TYPE)
val vector: Vector3 = new Vector3(m.invoke(Blocks.water, Array(worldObj, check.xi, check.yi, check.zi)).asInstanceOf[Vec3])
if ((currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0))
{
mechanicalNode.torque = -mechanicalNode.torque
}
if (getDirection.offsetX != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f)
powerTicks = 20
}
if (getDirection.offsetZ != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f)
powerTicks = 20
}
}
catch
{
case e: Exception =>
{
e.printStackTrace
}
}
}
}
}
}
}
/**
* Gravitation Potential Energy:
* PE = mgh
*/
private def getWaterPower: Long =
{
return (maxPower / (2 - tier + 1)) * Settings.WATER_POWER_RATIO
}
/**
* Gravitation Potential Energy:
* PE = mgh
*/
private def getWaterPower: Long =
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
for (i <- 0 to 2)
{
return (maxPower / (2 - tier + 1)) * Settings.WATER_POWER_RATIO
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
for (i <- 0 to 2)
{
par3List.add(new ItemStack(par1, 1, i))
}
par3List.add(new ItemStack(par1, 1, i))
}
}
}

View file

@ -1,7 +1,7 @@
package resonantinduction.mechanical.mech.turbine
import resonantinduction.mechanical.mech.MechanicalNode
import net.minecraftforge.common.util.ForgeDirection
import resonantinduction.mechanical.mech.MechanicalNode
/**
* Turbine's Mechanical node
@ -12,18 +12,18 @@ import net.minecraftforge.common.util.ForgeDirection
class TurbineNode(tileTurbineBase: TileTurbine) extends MechanicalNode(tileTurbineBase)
{
def turbine: TileTurbine =
{
return getParent.asInstanceOf[TileTurbine]
}
def turbine: TileTurbine =
{
return getParent.asInstanceOf[TileTurbine]
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
return turbine.getMultiBlock.isPrimary && source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TurbineNode]) && from == turbine.getDirection
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
{
return turbine.getMultiBlock.isPrimary && source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TurbineNode]) && from == turbine.getDirection
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return dir == turbine.getDirection.getOpposite
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return dir == turbine.getDirection.getOpposite
}
}