diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index 7746fea92..16522b7b6 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -591,7 +591,7 @@ object TextBuffer { private lazy val Debugger = api.Items.get("debugger") 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) } } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index 82a5e6f9f..a708b1609 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -486,7 +486,20 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand override def 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 } @@ -592,8 +605,9 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand setInventorySlotContents(slot, null) if (stack != null) removed += stack } - Array.copy(components, getSizeInventory - componentCount, components, realSize, componentCount) - for (slot <- getSizeInventory - componentCount until getSizeInventory if slot < realSize || slot >= realSize + componentCount) { + val copyComponentCount = math.min(getSizeInventory, 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 } getSizeInventory = realSize + componentCount