mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
keeping updating envs managed by adapter in list and iterating that instead of all of them
This commit is contained in:
parent
a042b71a15
commit
20f7f97846
@ -6,12 +6,15 @@ import li.cil.oc.{Settings, api}
|
|||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
import scala.collection.mutable
|
||||||
|
|
||||||
class Adapter extends traits.Environment with Analyzable {
|
class Adapter extends traits.Environment with Analyzable {
|
||||||
val node = api.Network.newNode(this, Visibility.Network).create()
|
val node = api.Network.newNode(this, Visibility.Network).create()
|
||||||
|
|
||||||
private val blocks = Array.fill[Option[(ManagedEnvironment, api.driver.Block)]](6)(None)
|
private val blocks = Array.fill[Option[(ManagedEnvironment, api.driver.Block)]](6)(None)
|
||||||
|
|
||||||
|
private val updatingBlocks = mutable.ArrayBuffer.empty[ManagedEnvironment]
|
||||||
|
|
||||||
private val blocksData = Array.fill[Option[BlockData]](6)(None)
|
private val blocksData = Array.fill[Option[BlockData]](6)(None)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
@ -24,10 +27,10 @@ class Adapter extends traits.Environment with Analyzable {
|
|||||||
|
|
||||||
override def updateEntity() {
|
override def updateEntity() {
|
||||||
super.updateEntity()
|
super.updateEntity()
|
||||||
for (block <- blocks) block match {
|
if (blocks.nonEmpty) {
|
||||||
// TODO Track updating environments in a list, loop that.
|
for (block <- updatingBlocks) {
|
||||||
case Some((environment, _)) if environment.canUpdate => environment.update()
|
block.update()
|
||||||
case _ => // Empty.
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +53,10 @@ class Adapter extends traits.Environment with Analyzable {
|
|||||||
node.disconnect(oldEnvironment.node)
|
node.disconnect(oldEnvironment.node)
|
||||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||||
|
updatingBlocks -= oldEnvironment
|
||||||
|
if (environment.canUpdate) {
|
||||||
|
updatingBlocks += environment
|
||||||
|
}
|
||||||
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
blocksData(d.ordinal()) = Some(new BlockData(environment.getClass.getName, new NBTTagCompound()))
|
||||||
node.connect(environment.node)
|
node.connect(environment.node)
|
||||||
} // else: the more things change, the more they stay the same.
|
} // else: the more things change, the more they stay the same.
|
||||||
@ -57,6 +64,9 @@ class Adapter extends traits.Environment with Analyzable {
|
|||||||
// A challenger appears.
|
// A challenger appears.
|
||||||
val environment = newDriver.createEnvironment(world, x, y, z)
|
val environment = newDriver.createEnvironment(world, x, y, z)
|
||||||
blocks(d.ordinal()) = Some((environment, newDriver))
|
blocks(d.ordinal()) = Some((environment, newDriver))
|
||||||
|
if (environment.canUpdate) {
|
||||||
|
updatingBlocks += environment
|
||||||
|
}
|
||||||
blocksData(d.ordinal()) match {
|
blocksData(d.ordinal()) match {
|
||||||
case Some(data) if data.name == environment.getClass.getName =>
|
case Some(data) if data.name == environment.getClass.getName =>
|
||||||
environment.load(data.data)
|
environment.load(data.data)
|
||||||
@ -71,6 +81,7 @@ class Adapter extends traits.Environment with Analyzable {
|
|||||||
node.disconnect(environment.node)
|
node.disconnect(environment.node)
|
||||||
environment.save(blocksData(d.ordinal()).get.data)
|
environment.save(blocksData(d.ordinal()).get.data)
|
||||||
blocks(d.ordinal()) = None
|
blocks(d.ordinal()) = None
|
||||||
|
updatingBlocks -= environment
|
||||||
case _ => // Nothing before, nothing now.
|
case _ => // Nothing before, nothing now.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user