Fixed robots sometimes holding their innards in their hands.

This *probably* fixes #637 (it at least fixes it partially).
This commit is contained in:
Florian Nücke 2014-11-25 20:51:03 +01:00
parent a96aa6a997
commit 1b3f1fa2db
2 changed files with 18 additions and 4 deletions

View File

@ -591,7 +591,7 @@ object TextBuffer {
private lazy val Debugger = api.Items.get("debugger") private lazy val Debugger = api.Items.get("debugger")
private def debug(message: String) { private def debug(message: String) {
if (api.Items.get(Minecraft.getMinecraft.thePlayer.getHeldItem) == Debugger) { if (Minecraft.getMinecraft != null && Minecraft.getMinecraft.thePlayer != null && api.Items.get(Minecraft.getMinecraft.thePlayer.getHeldItem) == Debugger) {
OpenComputers.log.info(s"[NETWORK DEBUGGER] Sending packet to node $nodeAddress: " + message) OpenComputers.log.info(s"[NETWORK DEBUGGER] Sending packet to node $nodeAddress: " + message)
} }
} }

View File

@ -486,7 +486,20 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand
override def markDirty() { override def markDirty() {
super.markDirty() super.markDirty()
updateInventorySize() // Avoid getting into a bad state on the client when updating before we
// got the descriptor packet from the server. If we manage to open the
// GUI before the descriptor packet arrived, close it again because it is
// invalid anyway.
if (inventorySize >= 0) {
updateInventorySize()
}
else if (isClient) {
Minecraft.getMinecraft.currentScreen match {
case robotGui: gui.Robot if robotGui.robot == this =>
Minecraft.getMinecraft.displayGuiScreen(null)
case _ =>
}
}
renderingErrored = false renderingErrored = false
} }
@ -592,8 +605,9 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand
setInventorySlotContents(slot, null) setInventorySlotContents(slot, null)
if (stack != null) removed += stack if (stack != null) removed += stack
} }
Array.copy(components, getSizeInventory - componentCount, components, realSize, componentCount) val copyComponentCount = math.min(getSizeInventory, componentCount)
for (slot <- getSizeInventory - componentCount until getSizeInventory if slot < realSize || slot >= realSize + componentCount) { Array.copy(components, getSizeInventory - copyComponentCount, components, realSize, copyComponentCount)
for (slot <- math.max(0, getSizeInventory - componentCount) until getSizeInventory if slot < realSize || slot >= realSize + componentCount) {
components(slot) = None components(slot) = None
} }
getSizeInventory = realSize + componentCount getSizeInventory = realSize + componentCount