2015-01-14 12:06:03 +01:00
|
|
|
package edx.mechanical.mech
|
2014-09-29 22:36:56 +02:00
|
|
|
|
2015-01-14 12:06:03 +01:00
|
|
|
import edx.mechanical.mech.grid.NodeMechanical
|
2014-09-29 22:36:56 +02:00
|
|
|
import io.netty.buffer.ByteBuf
|
|
|
|
import net.minecraft.block.material.Material
|
|
|
|
import net.minecraft.entity.player.EntityPlayer
|
2014-11-29 09:34:09 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection
|
2015-01-26 13:28:38 +01:00
|
|
|
import resonantengine.core.network.discriminator.PacketType
|
2015-01-26 12:40:32 +01:00
|
|
|
import resonantengine.lib.grid.core.TBlockNodeProvider
|
2015-01-26 13:28:38 +01:00
|
|
|
import resonantengine.lib.modcontent.block.ResonantTile
|
2015-01-26 12:40:32 +01:00
|
|
|
import resonantengine.lib.transform.vector.Vector3
|
|
|
|
import resonantengine.lib.wrapper.ByteBufWrapper._
|
2015-01-26 13:28:38 +01:00
|
|
|
import resonantengine.prefab.block.traits.TRotatable
|
|
|
|
import resonantengine.prefab.network.{TPacketReceiver, TPacketSender}
|
2014-11-08 17:42:20 +01:00
|
|
|
|
2014-11-22 13:21:51 +01:00
|
|
|
import scala.collection.convert.wrapAll._
|
|
|
|
|
2014-09-29 22:36:56 +02:00
|
|
|
/** Prefab for resonantinduction.mechanical tiles
|
|
|
|
*
|
|
|
|
* @author Calclavia */
|
2015-01-26 11:17:24 +01:00
|
|
|
abstract class TileMechanical(material: Material) extends ResonantTile(material: Material) with TRotatable with TBlockNodeProvider with TPacketSender with TPacketReceiver
|
2014-09-29 22:36:56 +02:00
|
|
|
{
|
2014-11-02 13:51:56 +01:00
|
|
|
/** Node that handles most mechanical actions */
|
2014-11-13 03:22:46 +01:00
|
|
|
private var _mechanicalNode: NodeMechanical = null
|
2014-11-11 14:09:30 +01:00
|
|
|
|
2014-11-29 09:34:09 +01:00
|
|
|
override def setDirection(direction: ForgeDirection): Unit =
|
|
|
|
{
|
|
|
|
super.setDirection(direction)
|
|
|
|
|
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.reconstruct())
|
|
|
|
}
|
|
|
|
|
2014-11-02 13:51:56 +01:00
|
|
|
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
|
|
|
{
|
2014-11-22 14:52:45 +01:00
|
|
|
if (!world.isRemote)
|
2014-11-22 15:53:50 +01:00
|
|
|
{
|
2014-11-29 09:34:09 +01:00
|
|
|
println(mechanicalNode + " in " + mechanicalNode.grid)
|
|
|
|
mechanicalNode.reconstruct()
|
2014-11-22 15:53:50 +01:00
|
|
|
}
|
2014-11-22 14:52:45 +01:00
|
|
|
|
2014-11-02 13:51:56 +01:00
|
|
|
return false
|
|
|
|
}
|
2014-09-29 22:36:56 +02:00
|
|
|
|
2014-11-11 14:09:30 +01:00
|
|
|
override def write(buf: ByteBuf, id: Int)
|
2014-11-08 17:41:34 +01:00
|
|
|
{
|
|
|
|
super.write(buf, id)
|
|
|
|
|
|
|
|
id match
|
|
|
|
{
|
|
|
|
case 0 =>
|
2014-11-11 14:09:30 +01:00
|
|
|
case 1 => buf <<< mechanicalNode.angularVelocity.toFloat
|
2014-11-08 17:41:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override def read(buf: ByteBuf, id: Int, packetType: PacketType)
|
2014-11-02 13:51:56 +01:00
|
|
|
{
|
2014-11-08 17:42:20 +01:00
|
|
|
super.read(buf, id, packetType)
|
|
|
|
|
|
|
|
id match
|
2014-09-29 22:36:56 +02:00
|
|
|
{
|
2014-11-08 17:42:20 +01:00
|
|
|
case 0 =>
|
2014-11-11 14:09:30 +01:00
|
|
|
case 1 => mechanicalNode.angularVelocity = buf.readFloat()
|
2014-09-29 22:36:56 +02:00
|
|
|
}
|
2014-11-02 13:51:56 +01:00
|
|
|
}
|
2015-01-08 11:59:14 +01:00
|
|
|
|
2015-01-26 11:17:24 +01:00
|
|
|
def mechanicalNode = _mechanicalNode
|
|
|
|
|
2015-01-26 11:13:56 +01:00
|
|
|
def mechanicalNode_=(newNode: NodeMechanical)
|
|
|
|
{
|
|
|
|
_mechanicalNode = newNode
|
|
|
|
mechanicalNode.onVelocityChanged = () => sendPacket(1)
|
|
|
|
nodes.removeAll(nodes.filter(_.isInstanceOf[NodeMechanical]))
|
|
|
|
nodes.add(mechanicalNode)
|
|
|
|
}
|
|
|
|
|
|
|
|
mechanicalNode = new NodeMechanical(this)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-29 22:36:56 +02:00
|
|
|
}
|