2014-09-14 09:02:11 +02:00
|
|
|
package resonantinduction.core.prefab.part.connector
|
|
|
|
|
2014-11-08 13:58:48 +01:00
|
|
|
import java.util
|
|
|
|
|
2014-11-09 06:28:58 +01:00
|
|
|
import codechicken.multipart.TMultiPart
|
2014-09-14 09:02:11 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection
|
2014-10-27 18:31:42 +01:00
|
|
|
import resonant.api.ISave
|
2014-12-09 23:46:07 +01:00
|
|
|
import resonant.api.tile.INodeProvider
|
|
|
|
import resonant.api.tile.node.INode
|
2015-01-08 14:24:04 +01:00
|
|
|
import resonant.lib.debug.DebugInfo
|
2014-11-08 13:58:48 +01:00
|
|
|
import resonant.lib.grid.node.Node
|
|
|
|
|
|
|
|
import scala.collection.convert.wrapAll._
|
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
|
|
|
|
*/
|
2015-01-08 14:24:04 +01:00
|
|
|
trait TPartNodeProvider extends PartAbstract with INodeProvider with DebugInfo
|
2014-09-14 09:02:11 +02:00
|
|
|
{
|
2014-11-08 13:58:48 +01:00
|
|
|
protected val nodes = new util.HashSet[Node]
|
2014-09-14 09:02:11 +02:00
|
|
|
|
2014-09-22 13:04:25 +02:00
|
|
|
override def start()
|
|
|
|
{
|
|
|
|
super.start()
|
2014-11-08 13:58:48 +01:00
|
|
|
|
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.reconstruct())
|
2014-09-22 13:04:25 +02:00
|
|
|
}
|
|
|
|
|
2014-09-14 09:02:11 +02:00
|
|
|
override def onWorldJoin()
|
|
|
|
{
|
2014-11-08 13:58:48 +01:00
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.reconstruct())
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override def onNeighborChanged()
|
|
|
|
{
|
2014-11-08 13:58:48 +01:00
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.reconstruct())
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
2014-11-09 06:28:58 +01:00
|
|
|
override def onPartChanged(part: TMultiPart)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.reconstruct())
|
|
|
|
}
|
|
|
|
|
2014-09-14 09:02:11 +02:00
|
|
|
override def onWorldSeparate()
|
|
|
|
{
|
2014-11-10 14:20:42 +01:00
|
|
|
if (!world.isRemote)
|
|
|
|
nodes.foreach(_.deconstruct())
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override def save(nbt: NBTTagCompound)
|
|
|
|
{
|
|
|
|
super.save(nbt)
|
2014-11-08 13:58:48 +01:00
|
|
|
nodes.filter(_.isInstanceOf[ISave]).foreach(_.asInstanceOf[ISave].save(nbt))
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override def load(nbt: NBTTagCompound)
|
|
|
|
{
|
|
|
|
super.load(nbt)
|
2014-11-08 13:58:48 +01:00
|
|
|
nodes.filter(_.isInstanceOf[ISave]).foreach(_.asInstanceOf[ISave].load(nbt))
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
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-08 13:58:48 +01:00
|
|
|
return nodes.filter(node => nodeType.isAssignableFrom(node.getClass)).headOption.getOrElse(null).asInstanceOf[N]
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|
2015-01-08 14:24:04 +01:00
|
|
|
|
|
|
|
override def getDebugInfo: List[String] =
|
|
|
|
{
|
|
|
|
val debugs = nodes.toList.filter(_.isInstanceOf[DebugInfo])
|
|
|
|
|
|
|
|
if (debugs.size > 0)
|
|
|
|
{
|
|
|
|
return debugs.map(_.asInstanceOf[DebugInfo].getDebugInfo).reduceLeft(_ ::: _)
|
|
|
|
}
|
|
|
|
return List[String]()
|
|
|
|
}
|
2014-09-14 09:02:11 +02:00
|
|
|
}
|