fixed (harmless) warnings when resuming a stopped computer after loading ('missing filesystem' -> rom and tmp were not saved while stopped); fixed weird assertion error on client; making robot proxies' nodes use the same address as the robot's internal node. this is safe since the two networks will never be connected, and makes it more intuitive to interact with robots from the outside.

This commit is contained in:
Florian Nücke 2014-02-01 20:43:33 +01:00
parent 36612ffcaf
commit 19d61646c8
4 changed files with 22 additions and 15 deletions

View File

@ -37,7 +37,7 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
// Note: we implement IContext in the TE to allow external components to cast
// their owner to it (to allow interacting with their owning computer).
def address() = computer.address
def address = computer.address
def canInteract(player: String) =
if (isServer) computer.canInteract(player)

View File

@ -159,9 +159,11 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
// the client by sending a corresponding packet. This also saves us from
// having to send the complete state again (e.g. screen buffer) each move.
world.setBlockToAir(nx, ny, nz)
val created = Blocks.robotProxy.setBlock(world, nx, ny, nz, 1)
// In some cases (though I couldn't quite figure out which one) setBlock
// will return true, even though the block was not created / adjusted.
val created = Blocks.robotProxy.setBlock(world, nx, ny, nz, 1) &&
world.getBlockTileEntity(nx, ny, nz) == proxy
if (created) {
assert(world.getBlockTileEntity(nx, ny, nz) == proxy)
assert(x == nx && y == ny && z == nz)
world.setBlock(ox, oy, oz, 0, 0, 1)
Blocks.robotAfterimage.setBlock(world, ox, oy, oz, 1)

View File

@ -2,7 +2,7 @@ package li.cil.oc.common.tileentity
import cpw.mods.fml.common.Optional
import cpw.mods.fml.relauncher.{Side, SideOnly}
import li.cil.oc.api
import li.cil.oc.{Settings, api}
import li.cil.oc.api.Network
import li.cil.oc.api.network._
import li.cil.oc.client.gui
@ -61,10 +61,17 @@ class RobotProxy(val robot: Robot) extends Computer(robot.isClient) with ISidedI
// ----------------------------------------------------------------------- //
override def updateEntity() {
if (node != null && node.network == null) {
robot.updateEntity()
if (!addedToNetwork) {
addedToNetwork = true
// Use the same address we use internally on the outside.
if (isServer) {
val nbt = new NBTTagCompound()
nbt.setString("address", robot.address)
node.load(nbt)
}
Network.joinOrCreateNetwork(this)
}
robot.updateEntity()
}
override def validate() {
@ -127,10 +134,7 @@ class RobotProxy(val robot: Robot) extends Computer(robot.isClient) with ISidedI
// ----------------------------------------------------------------------- //
override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
robot.onAnalyze(player, side, hitX, hitY, hitZ)
Array(node)
}
override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = robot.onAnalyze(player, side, hitX, hitY, hitZ)
// ----------------------------------------------------------------------- //

View File

@ -508,6 +508,9 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi
components ++= nbt.getTagList("components").iterator[NBTTagCompound].map(c =>
c.getString("address") -> c.getString("name"))
rom.foreach(rom => rom.load(nbt.getCompoundTag("rom")))
tmp.foreach(tmp => tmp.load(nbt.getCompoundTag("tmp")))
if (state.size > 0 && state.top != Machine.State.Stopped && init()) {
architecture.load(nbt)
@ -534,8 +537,6 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi
}.toArray)
})
rom.foreach(rom => rom.load(nbt.getCompoundTag("rom")))
tmp.foreach(tmp => tmp.load(nbt.getCompoundTag("tmp")))
timeStarted = nbt.getLong("timeStarted")
cpuTime = nbt.getLong("cpuTime")
remainingPause = nbt.getInteger("remainingPause")
@ -572,6 +573,9 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi
}
nbt.setTag("components", componentsNbt)
rom.foreach(rom => nbt.setNewCompoundTag("rom", rom.save))
tmp.foreach(tmp => nbt.setNewCompoundTag("tmp", tmp.save))
if (state.top != Machine.State.Stopped) {
architecture.save(nbt)
@ -601,9 +605,6 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi
}
nbt.setTag("signals", signalsNbt)
rom.foreach(rom => nbt.setNewCompoundTag("rom", rom.save))
tmp.foreach(tmp => nbt.setNewCompoundTag("tmp", tmp.save))
nbt.setLong("timeStarted", timeStarted)
nbt.setLong("cpuTime", cpuTime)
nbt.setInteger("remainingPause", remainingPause)