diff --git a/li/cil/oc/common/block/DiskDrive.scala b/li/cil/oc/common/block/DiskDrive.scala index facb413fa..95fb6ca8f 100644 --- a/li/cil/oc/common/block/DiskDrive.scala +++ b/li/cil/oc/common/block/DiskDrive.scala @@ -1,7 +1,7 @@ package li.cil.oc.common.block 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.entity.player.EntityPlayer 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 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, diff --git a/li/cil/oc/common/block/Keyboard.scala b/li/cil/oc/common/block/Keyboard.scala index c750a544a..b6d3f1de4 100644 --- a/li/cil/oc/common/block/Keyboard.scala +++ b/li/cil/oc/common/block/Keyboard.scala @@ -1,5 +1,6 @@ package li.cil.oc.common.block +import li.cil.oc.api import li.cil.oc.common.tileentity import net.minecraft.world.World @@ -9,4 +10,10 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate { override def hasTileEntity = true 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 _ => + } } \ No newline at end of file diff --git a/li/cil/oc/common/tileentity/Computer.scala b/li/cil/oc/common/tileentity/Computer.scala index 06d00b4ef..b199f9099 100644 --- a/li/cil/oc/common/tileentity/Computer.scala +++ b/li/cil/oc/common/tileentity/Computer.scala @@ -44,30 +44,31 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv override def updateEntity() { if (isServer) { - // If we're not yet in a network we were just loaded from disk. We skip - // the update this round to allow other tile entities to join the network, - // too, avoiding issues of missing nodes (e.g. in the GPU which would - // otherwise loose track of its screen). + // If we're not yet in a network we might have just been loaded from disk, + // meaning there may be other tile entities that also have not re-joined + // the network. We skip the update this round to allow other tile entities + // 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) { computer.update() - } - if (hasChanged) { - hasChanged = false - world.markTileEntityChunkModified(x, y, z, this) - } + if (hasChanged) { + hasChanged = false + world.markTileEntityChunkModified(x, y, z, this) + } - if (_isRunning != computer.isRunning) { - isOutputEnabled = hasRedstoneCard && computer.isRunning - ServerPacketSender.sendComputerState(this, computer.isRunning) - } - _isRunning = computer.isRunning + if (_isRunning != computer.isRunning) { + isOutputEnabled = hasRedstoneCard && computer.isRunning + ServerPacketSender.sendComputerState(this, computer.isRunning) + } + _isRunning = computer.isRunning - updateRedstoneInput() + updateRedstoneInput() - for (component <- components) component match { - case Some(environment) => environment.update() - case _ => // Empty. + for (component <- components) component match { + case Some(environment) => environment.update() + case _ => // Empty. + } } } diff --git a/li/cil/oc/common/tileentity/DiskDrive.scala b/li/cil/oc/common/tileentity/DiskDrive.scala index 6e7bc4fd2..da78a8fb4 100644 --- a/li/cil/oc/common/tileentity/DiskDrive.scala +++ b/li/cil/oc/common/tileentity/DiskDrive.scala @@ -4,7 +4,7 @@ import li.cil.oc.api.driver.Slot import li.cil.oc.api.network.{Component, Visibility} import li.cil.oc.client.{PacketSender => ClientPacketSender} 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 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() = { super.validate() if (isClient) { ClientPacketSender.sendRotatableStateRequest(this) } + world.scheduleBlockUpdateFromLoad(x, y, z, Blocks.diskDrive.parent.blockID, 0, 0) } // ----------------------------------------------------------------------- // diff --git a/li/cil/oc/common/tileentity/Keyboard.scala b/li/cil/oc/common/tileentity/Keyboard.scala index f441533a1..a1f8b0074 100644 --- a/li/cil/oc/common/tileentity/Keyboard.scala +++ b/li/cil/oc/common/tileentity/Keyboard.scala @@ -1,8 +1,8 @@ package li.cil.oc.common.tileentity -import li.cil.oc.Config import li.cil.oc.server.component import li.cil.oc.util.ExtendedNBT._ +import li.cil.oc.{Blocks, Config} import net.minecraft.nbt.NBTTagCompound 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 canUpdate = false + + override def validate() { + super.validate() + world.scheduleBlockUpdateFromLoad(x, y, z, Blocks.keyboard.parent.blockID, 0, 0) + } + override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) if (isServer) { diff --git a/li/cil/oc/common/tileentity/Router.scala b/li/cil/oc/common/tileentity/Router.scala index d36f23fc6..da19e715d 100644 --- a/li/cil/oc/common/tileentity/Router.scala +++ b/li/cil/oc/common/tileentity/Router.scala @@ -54,7 +54,7 @@ class Router extends net.minecraft.tileentity.TileEntity with api.network.SidedE val node = api.Network.newNode(this, Visibility.Network).create() def onMessage(message: Message) { - if (isPrimaryNode) { + if (isPrimary) { 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) {} - 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) } diff --git a/li/cil/oc/server/component/Computer.scala b/li/cil/oc/server/component/Computer.scala index 873e5fa8e..0bdb43929 100644 --- a/li/cil/oc/server/component/Computer.scala +++ b/li/cil/oc/server/component/Computer.scala @@ -496,7 +496,6 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con 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.Stopping) // Only set while executor is running. super.save(nbt) diff --git a/li/cil/oc/server/network/Network.scala b/li/cil/oc/server/network/Network.scala index cda381c09..e665821c8 100644 --- a/li/cil/oc/server/network/Network.scala +++ b/li/cil/oc/server/network/Network.scala @@ -251,13 +251,7 @@ object Network extends api.detail.NetworkAPI { tileEntity.yCoord + side.offsetY, tileEntity.zCoord + side.offsetZ) getNetworkNode(tileEntity.getWorldObj.getBlockTileEntity(nx, ny, nz), side.getOpposite) match { - case Some(neighbor: MutableNode) if neighbor != node => - if (node.network != null) { - node.connect(neighbor) - } - else if (neighbor.network != null) { - neighbor.connect(node) - } + case Some(neighbor: MutableNode) if neighbor != node && neighbor.network != null => neighbor.connect(node) case _ => // Ignore. } if (node.network == null) {