Refactored grid classes

This commit is contained in:
Calclavia 2015-01-17 12:30:25 +08:00
parent 3f5c2db1b7
commit 5373b7c12a
12 changed files with 46 additions and 48 deletions

View file

@ -17,10 +17,9 @@ import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import org.lwjgl.opengl.GL11
import resonant.api.tile.IRemovable
import resonant.api.tile.IRemovable.ISneakPickup
import resonant.api.tile.node.INode
import resonant.lib.grid.node.Node
import resonant.lib.grid.core.Node
import resonant.lib.render.block.RenderConnectedTexture
import resonant.lib.render.{FluidRenderUtility, RenderBlockUtility, RenderUtility}
import resonant.lib.transform.vector.Vector3

View file

@ -4,7 +4,7 @@ import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidContainerRegistry, IFluidHandler}
import resonant.api.IUpdate
import resonant.api.tile.INodeProvider
import resonant.lib.grid.UpdateTicker
import resonant.lib.grid.core.UpdateTicker
import resonant.lib.prefab.fluid.NodeFluid
import scala.collection.convert.wrapAll._

View file

@ -3,7 +3,7 @@ package edx.core.prefab.node
import codechicken.multipart.TMultiPart
import net.minecraft.tileentity.TileEntity
import net.minecraft.world.World
import resonant.lib.grid.node.NodeConnector
import resonant.lib.grid.core.NodeConnector
/**
* A trait that allows nodes to works with Forge Multipart. This trait MUST be mixed in.

View file

@ -5,7 +5,7 @@ import net.minecraft.block.material.Material
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.lib.grid.node.TSpatialNodeProvider
import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.fluid.NodeFluid
@ -94,10 +94,6 @@ abstract class TileFluidProvider(material: Material) extends SpatialTile(materia
override def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack = fluidNode.drain(from, maxDrain, doDrain)
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canFill(from, fluid)
override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canDrain(from, fluid)
def fluidNode = _fluidNode
def fluidNode_=(newNode: NodeFluid)
@ -112,6 +108,10 @@ abstract class TileFluidProvider(material: Material) extends SpatialTile(materia
nodes.add(fluidNode)
}
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canFill(from, fluid)
override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canDrain(from, fluid)
override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int = fluidNode.fill(from, resource, doFill)
override def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = fluidNode.getTankInfo(from)

View file

@ -12,7 +12,7 @@ import edx.core.prefab.part.CuboidShapes
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.{IIcon, MovingObjectPosition}
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.grid.node.NodeConnector
import resonant.lib.grid.core.NodeConnector
import resonant.lib.wrapper.BitmaskWrapper._
import scala.collection.convert.wrapAll._

View file

@ -9,7 +9,7 @@ import resonant.api.ISave
import resonant.api.tile.INodeProvider
import resonant.api.tile.node.INode
import resonant.lib.debug.DebugInfo
import resonant.lib.grid.node.Node
import resonant.lib.grid.core.Node
import scala.collection.convert.wrapAll._

View file

@ -2,7 +2,7 @@ package edx.electrical.battery
import java.util.{Arrays, LinkedHashSet, Set}
import resonant.lib.grid.Grid
import resonant.lib.grid.core.Grid
import scala.collection.JavaConversions._

View file

@ -13,7 +13,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.lib.content.prefab.TElectric
import resonant.lib.grid.node.TSpatialNodeProvider
import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.prefab.tile.spatial.SpatialTile
import resonant.lib.prefab.tile.traits.TRotatable
import resonant.lib.render.RenderUtility

View file

@ -3,7 +3,7 @@ package edx.electrical.multimeter
import edx.electrical.multimeter.graph._
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
import resonant.api.IUpdate
import resonant.lib.grid.{Grid, UpdateTicker}
import resonant.lib.grid.core.{Grid, UpdateTicker}
import resonant.lib.transform.vector.Vector3
import resonant.lib.utility.LanguageUtility
import resonant.lib.utility.science.UnitDisplay

View file

@ -5,7 +5,7 @@ import io.netty.buffer.ByteBuf
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.grid.node.TSpatialNodeProvider
import resonant.lib.grid.core.TSpatialNodeProvider
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.tile.spatial.SpatialTile
@ -42,6 +42,18 @@ abstract class TileMechanical(material: Material) extends SpatialTile(material:
return false
}
def mechanicalNode = _mechanicalNode
def mechanicalNode_=(newNode: NodeMechanical)
{
_mechanicalNode = newNode
mechanicalNode.onVelocityChanged = () => sendPacket(1)
nodes.removeAll(nodes.filter(_.isInstanceOf[NodeMechanical]))
nodes.add(mechanicalNode)
}
mechanicalNode = new NodeMechanical(this)
override def write(buf: ByteBuf, id: Int)
{
super.write(buf, id)
@ -64,16 +76,4 @@ abstract class TileMechanical(material: Material) extends SpatialTile(material:
}
}
mechanicalNode = new NodeMechanical(this)
def mechanicalNode = _mechanicalNode
def mechanicalNode_=(newNode: NodeMechanical)
{
_mechanicalNode = newNode
mechanicalNode.onVelocityChanged = () => sendPacket(1)
nodes.removeAll(nodes.filter(_.isInstanceOf[NodeMechanical]))
nodes.add(mechanicalNode)
}
}

View file

@ -1,7 +1,7 @@
package edx.mechanical.mech.grid
import resonant.api.IUpdate
import resonant.lib.grid.{GridNode, UpdateTicker}
import resonant.lib.grid.core.{GridNode, UpdateTicker}
import scala.collection.convert.wrapAll._

View file

@ -4,8 +4,7 @@ import edx.core.interfaces.TNodeMechanical
import edx.core.prefab.node.TMultipartNode
import resonant.api.tile.INodeProvider
import resonant.lib.debug.DebugInfo
import resonant.lib.grid.GridNode
import resonant.lib.grid.node.{NodeGrid, TTileConnector}
import resonant.lib.grid.core.{GridNode, NodeGrid, TTileConnector}
import resonant.lib.transform.vector.IVectorWorld
import scala.beans.BeanProperty
@ -52,6 +51,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
return prevAngle
}
/**
* Gets the angular velocity of the mechanical device from a specific side
*
* @return Angular velocity in meters per second
*/
override def angularVelocity = _angularVelocity
def angularVelocity_=(newVel: Double) = _angularVelocity = newVel
/**
* Sets the mechanical node's angle based on its connections
*/
@ -80,24 +88,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
def power: Double = torque * angularVelocity
/**
* Gets the angular velocity of the mechanical device from a specific side
*
* @return Angular velocity in meters per second
*/
override def angularVelocity = _angularVelocity
def angularVelocity_=(newVel: Double) = _angularVelocity = newVel
/**
* Gets the torque of the mechanical device from a specific side
*
* @return force
*/
override def torque = _torque
def torque_=(newTorque: Double) = _torque = newTorque
def getMechanicalGrid: MechanicalGrid = super.grid.asInstanceOf[MechanicalGrid]
override def newGrid: GridNode[NodeMechanical] = new MechanicalGrid
@ -108,6 +98,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
override def toString = "NodeMechanical [" + connections.size() + " Torque: " + BigDecimal(torque).setScale(2, BigDecimal.RoundingMode.HALF_UP) + " Velocity: " + BigDecimal(angularVelocity).setScale(2, BigDecimal.RoundingMode.HALF_UP) + "]"
/**
* Gets the torque of the mechanical device from a specific side
*
* @return force
*/
override def torque = _torque
def torque_=(newTorque: Double) = _torque = newTorque
/**
* The class used to compare when making connections
*/