electrodynamics/src/main/scala/resonantinduction/core/prefab/part/connector/TPartNodeProvider.scala

61 lines
1.2 KiB
Scala
Raw Normal View History

2014-09-14 09:02:11 +02:00
package resonantinduction.core.prefab.part.connector
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.ISave
2014-11-02 13:51:56 +01:00
import resonant.api.grid.{INode, INodeProvider}
2014-09-14 09:02:11 +02:00
/**
2014-09-14 09:48:55 +02:00
* A node trait that can be mixed into any multipart nodes. Mixing this trait will cause nodes to reconstruct/deconstruct when needed.
2014-09-14 09:02:11 +02:00
* @author Calclavia
*/
2014-11-06 16:11:08 +01:00
trait TPartNodeProvider extends PartAbstract with INodeProvider
2014-09-14 09:02:11 +02:00
{
protected lazy val node: INode = null
override def start()
{
super.start()
node.reconstruct()
}
2014-09-14 09:02:11 +02:00
override def onWorldJoin()
{
node.reconstruct()
}
override def onNeighborChanged()
{
node.reconstruct()
}
override def onWorldSeparate()
{
node.deconstruct()
}
override def save(nbt: NBTTagCompound)
{
super.save(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].save(nbt)
}
override def load(nbt: NBTTagCompound)
{
super.load(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].load(nbt)
}
2014-11-02 13:51:56 +01:00
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
2014-09-14 09:02:11 +02:00
{
2014-11-04 14:41:07 +01:00
if (nodeType.isAssignableFrom(node.getClass))
2014-11-02 13:51:56 +01:00
return node.asInstanceOf[N]
return null.asInstanceOf[N]
2014-09-14 09:02:11 +02:00
}
}