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
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,

View File

@ -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 _ =>
}
}

View File

@ -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.
}
}
}

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.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)
}
// ----------------------------------------------------------------------- //

View File

@ -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) {

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()
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)
}

View File

@ -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)

View File

@ -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) {