diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua index a8680de28..6a59a6c6e 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/lib/term.lua @@ -81,17 +81,20 @@ function term.setCursorBlink(enabled) end function term.isWide(x, y) - local charLeft, char = component.gpu.get(x - 1, y), component.gpu.get(x, y) + local char = component.gpu.get(x, y) if unicode.isWide(char) then -- The char at the specified position is a wide char. return true - elseif char == " " and charLeft and unicode.isWide(charLeft) then - -- The char left to the specified position is a wide char. - return true, true - else - -- Not a wide char. - return false end + if char == " " and x > 1 then + local charLeft = component.gpu.get(x - 1, y) + if charLeft and unicode.isWide(charLeft) then + -- The char left to the specified position is a wide char. + return true, true + end + end + -- Not a wide char. + return false end function term.isAvailable() 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 986d6a618..e3c7403be 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -273,25 +273,31 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone override def getForegroundColor(column: Int, row: Int) = if (isForegroundFromPalette(column, row)) { - PackedColor.extractForeground(data.color(row)(column)) + PackedColor.extractForeground(color(column, row)) } else { - PackedColor.unpackForeground(data.color(row)(column), data.format) + PackedColor.unpackForeground(color(column, row), data.format) } override def isForegroundFromPalette(column: Int, row: Int) = - data.format.isFromPalette(PackedColor.extractForeground(data.color(row)(column))) + data.format.isFromPalette(PackedColor.extractForeground(color(column, row))) override def getBackgroundColor(column: Int, row: Int) = if (isBackgroundFromPalette(column, row)) { - PackedColor.extractBackground(data.color(row)(column)) + PackedColor.extractBackground(color(column, row)) } else { - PackedColor.unpackBackground(data.color(row)(column), data.format) + PackedColor.unpackBackground(color(column, row), data.format) } override def isBackgroundFromPalette(column: Int, row: Int) = - data.format.isFromPalette(PackedColor.extractBackground(data.color(row)(column))) + data.format.isFromPalette(PackedColor.extractBackground(color(column, row))) + + private def color(column: Int, row: Int) = { + if (column < 0 || column >= getWidth || row < 0 || row >= getHeight) + throw new IndexOutOfBoundsException() + else data.color(row)(column) + } @SideOnly(Side.CLIENT) override def renderText() = relativeLitArea != 0 && proxy.render() diff --git a/src/main/scala/li/cil/oc/util/TextBuffer.scala b/src/main/scala/li/cil/oc/util/TextBuffer.scala index 4d48ca80b..23dd12841 100644 --- a/src/main/scala/li/cil/oc/util/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/util/TextBuffer.scala @@ -95,7 +95,11 @@ class TextBuffer(var width: Int, var height: Int, initialFormat: PackedColor.Col } /** Get the char at the specified index. */ - def get(col: Int, row: Int) = buffer(row)(col) + def get(col: Int, row: Int) = { + if (col < 0 || col >= width || row < 0 || row >= height) + throw new IndexOutOfBoundsException() + else buffer(row)(col) + } /** String based fill starting at a specified location. */ def set(col: Int, row: Int, s: String, vertical: Boolean): Boolean =