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

60 lines
1.3 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.core.prefab.part.connector
2014-09-14 09:02:11 +02:00
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
2015-01-26 13:17:04 +01:00
import resonantengine.api.misc.ISave
import resonantengine.prefab.block.impl.TNodeProvider
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-26 11:13:56 +01:00
trait TPartNodeProvider extends PartAbstract with TNodeProvider
2014-09-14 09:02:11 +02:00
{
override def start()
{
super.start()
if (!world.isRemote)
nodes.foreach(_.reconstruct())
}
2014-09-14 09:02:11 +02:00
override def onWorldJoin()
{
if (!world.isRemote)
nodes.foreach(_.reconstruct())
2014-09-14 09:02:11 +02:00
}
override def onNeighborChanged()
{
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)
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)
nodes.filter(_.isInstanceOf[ISave]).foreach(_.asInstanceOf[ISave].load(nbt))
2014-09-14 09:02:11 +02:00
}
}