AliquotMesozoic

Mob Counter

Jun 10th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local m = peripheral.find("modem") -- Requires advanced pocket computer w/ modem
  2. m.open(42) -- Customize to your liking
  3.  
  4. local _getSize = term.getSize
  5. local _setCursorPos = term.setCursorPos
  6. local _getCursorPos = term.getCursorPos
  7.  
  8. -- Override cursor related functions so we have the first line all to ourselves
  9. term.getSize = function()
  10.   local w, h = _getSize()
  11.   return w, h-1
  12. end
  13.  
  14. term.setCursorPos = function(x, y)
  15.   return _setCursorPos(x, y + 1)
  16. end
  17.  
  18. term.getCursorPos = function()
  19.   local x, y = _getCursorPos()
  20.   return x, y - 1
  21. end
  22.  
  23. -- Make sure we save the current state of the terminal (e.g. colors and cursor pos)
  24. local function save()
  25.   return {
  26.     colors.black, -- Implement at some point
  27.     colors.white,
  28.     {_getCursorPos()}
  29.   }
  30. end
  31.  
  32. -- Restore state of terminal
  33. local function restore(ts)
  34.   term.setBackgroundColor(ts[1])
  35.   term.setTextColor(ts[2])
  36.   _setCursorPos(ts[3][1], ts[3][2])
  37. end
  38.  
  39. local w, h = _getSize()
  40.  
  41. -- Our function for writing to that first line
  42. local function writeMobStatus()
  43.   while true do
  44.     local e = {os.pullEvent("modem_message")}
  45.     local ts = save()
  46.     _setCursorPos(1,1)
  47.     term.setBackgroundColor(colors.red)
  48.     term.write(string.rep(" ", w))
  49.     _setCursorPos(1,1)
  50.     term.setTextColor(colors.white)
  51.     term.write("Mobs: " .. e[5])
  52.     restore(ts)
  53.   end
  54. end
  55.  
  56. -- A helper method to run the shell
  57. local function runTerm()
  58.   shell.run("rom/programs/shell")
  59. end
  60.  
  61. -- Clear the terminal so it's nice and clean that first go
  62. term.clear()
  63.  
  64. -- And bam!
  65. parallel.waitForAll(writeMobStatus, runTerm)
Advertisement
Add Comment
Please, Sign In to add comment