also initializing disk drive and keyboard networks via one block tick; removed another false assert; underped network initialization

This commit is contained in:
Florian Nücke 2013-11-22 04:46:00 +01:00
parent 7f40926102
commit 17c8c96f3d
8 changed files with 48 additions and 31 deletions

View File

@ -1,7 +1,7 @@
package li.cil.oc.common.block package li.cil.oc.common.block
import li.cil.oc.common.{GuiType, tileentity} import li.cil.oc.common.{GuiType, tileentity}
import li.cil.oc.{OpenComputers, Config} import li.cil.oc.{api, OpenComputers, Config}
import net.minecraft.client.renderer.texture.IconRegister import net.minecraft.client.renderer.texture.IconRegister
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.Icon import net.minecraft.util.Icon
@ -33,6 +33,12 @@ class DiskDrive(val parent: SimpleDelegator) extends SimpleDelegate {
override def createTileEntity(world: World) = Some(new tileentity.DiskDrive) override def createTileEntity(world: World) = Some(new tileentity.DiskDrive)
override def update(world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case drive: tileentity.DiskDrive => api.Network.joinOrCreateNetwork(drive)
case _ =>
}
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,

View File

@ -1,5 +1,6 @@
package li.cil.oc.common.block package li.cil.oc.common.block
import li.cil.oc.api
import li.cil.oc.common.tileentity import li.cil.oc.common.tileentity
import net.minecraft.world.World import net.minecraft.world.World
@ -9,4 +10,10 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
override def hasTileEntity = true override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Keyboard(world.isRemote)) override def createTileEntity(world: World) = Some(new tileentity.Keyboard(world.isRemote))
override def update(world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case keyboard: tileentity.Keyboard => api.Network.joinOrCreateNetwork(keyboard)
case _ =>
}
} }

View File

@ -44,13 +44,13 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
override def updateEntity() { override def updateEntity() {
if (isServer) { if (isServer) {
// If we're not yet in a network we were just loaded from disk. We skip // If we're not yet in a network we might have just been loaded from disk,
// the update this round to allow other tile entities to join the network, // meaning there may be other tile entities that also have not re-joined
// too, avoiding issues of missing nodes (e.g. in the GPU which would // the network. We skip the update this round to allow other tile entities
// otherwise loose track of its screen). // to join the network, too, avoiding issues of missing nodes (e.g. in the
// GPU which would otherwise loose track of its screen).
if (node != null && node.network != null) { if (node != null && node.network != null) {
computer.update() computer.update()
}
if (hasChanged) { if (hasChanged) {
hasChanged = false hasChanged = false
@ -70,6 +70,7 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
case _ => // Empty. case _ => // Empty.
} }
} }
}
super.updateEntity() super.updateEntity()
} }

View File

@ -4,7 +4,7 @@ import li.cil.oc.api.driver.Slot
import li.cil.oc.api.network.{Component, Visibility} import li.cil.oc.api.network.{Component, Visibility}
import li.cil.oc.client.{PacketSender => ClientPacketSender} import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.server.driver.Registry import li.cil.oc.server.driver.Registry
import li.cil.oc.{api, Config} import li.cil.oc.{Blocks, api, Config}
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
class DiskDrive extends Environment with ComponentInventory with Rotatable { class DiskDrive extends Environment with ComponentInventory with Rotatable {
@ -12,11 +12,14 @@ class DiskDrive extends Environment with ComponentInventory with Rotatable {
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
override def canUpdate = false
override def validate() = { override def validate() = {
super.validate() super.validate()
if (isClient) { if (isClient) {
ClientPacketSender.sendRotatableStateRequest(this) ClientPacketSender.sendRotatableStateRequest(this)
} }
world.scheduleBlockUpdateFromLoad(x, y, z, Blocks.diskDrive.parent.blockID, 0, 0)
} }
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //

View File

@ -1,8 +1,8 @@
package li.cil.oc.common.tileentity package li.cil.oc.common.tileentity
import li.cil.oc.Config
import li.cil.oc.server.component import li.cil.oc.server.component
import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ExtendedNBT._
import li.cil.oc.{Blocks, Config}
import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagCompound
class Keyboard(isRemote: Boolean) extends Environment with Rotatable { class Keyboard(isRemote: Boolean) extends Environment with Rotatable {
@ -14,6 +14,13 @@ class Keyboard(isRemote: Boolean) extends Environment with Rotatable {
override def isClient = keyboard == null override def isClient = keyboard == null
override def canUpdate = false
override def validate() {
super.validate()
world.scheduleBlockUpdateFromLoad(x, y, z, Blocks.keyboard.parent.blockID, 0, 0)
}
override def readFromNBT(nbt: NBTTagCompound) { override def readFromNBT(nbt: NBTTagCompound) {
super.readFromNBT(nbt) super.readFromNBT(nbt)
if (isServer) { if (isServer) {

View File

@ -54,7 +54,7 @@ class Router extends net.minecraft.tileentity.TileEntity with api.network.SidedE
val node = api.Network.newNode(this, Visibility.Network).create() val node = api.Network.newNode(this, Visibility.Network).create()
def onMessage(message: Message) { def onMessage(message: Message) {
if (isPrimaryNode) { if (isPrimary) {
plugsInOtherNetworks.foreach(_.node.sendToReachable(message.name, message.data: _*)) plugsInOtherNetworks.foreach(_.node.sendToReachable(message.name, message.data: _*))
} }
} }
@ -63,7 +63,7 @@ class Router extends net.minecraft.tileentity.TileEntity with api.network.SidedE
def onConnect(node: Node) {} def onConnect(node: Node) {}
private def isPrimaryNode = plugs(plugs.indexWhere(_.node.network == node.network)) == this private def isPrimary = plugs(plugs.indexWhere(_.node.network == node.network)) == this
private def plugsInOtherNetworks = plugs.filter(_.node.network != node.network) private def plugsInOtherNetworks = plugs.filter(_.node.network != node.network)
} }

View File

@ -496,7 +496,6 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
override def save(nbt: NBTTagCompound): Unit = this.synchronized { override def save(nbt: NBTTagCompound): Unit = this.synchronized {
assert(state.top != Computer.State.Running) // Lock on 'this' should guarantee this. assert(state.top != Computer.State.Running) // Lock on 'this' should guarantee this.
assert(state.top != Computer.State.Stopping) // Only set while executor is running.
super.save(nbt) super.save(nbt)

View File

@ -251,13 +251,7 @@ object Network extends api.detail.NetworkAPI {
tileEntity.yCoord + side.offsetY, tileEntity.yCoord + side.offsetY,
tileEntity.zCoord + side.offsetZ) tileEntity.zCoord + side.offsetZ)
getNetworkNode(tileEntity.getWorldObj.getBlockTileEntity(nx, ny, nz), side.getOpposite) match { getNetworkNode(tileEntity.getWorldObj.getBlockTileEntity(nx, ny, nz), side.getOpposite) match {
case Some(neighbor: MutableNode) if neighbor != node => case Some(neighbor: MutableNode) if neighbor != node && neighbor.network != null => neighbor.connect(node)
if (node.network != null) {
node.connect(neighbor)
}
else if (neighbor.network != null) {
neighbor.connect(node)
}
case _ => // Ignore. case _ => // Ignore.
} }
if (node.network == null) { if (node.network == null) {