Impshial

ImpShial API

Jun 9th, 2019 (edited)
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ImpShial API
  2. -- Version 0.2
  3. ---------------------------------------------------------------------------------------
  4. -- Tested on Computercraft version 1.58
  5. -- Minecraft version 1.6.4
  6. ---------------------------------------------------------------------------------------
  7. --
  8. -- NOTE: THIS IS A WORK IN PROGRESS
  9. --
  10. -- This code was written by Impshial and is free software:
  11. -- You can redistribute it and/or modify
  12. -- it under the terms of the GNU General Public License as published by
  13. -- the Free Software Foundation, either version 3 of the License, or
  14. -- (at your option) any later version.
  15.  
  16. -- This program is distributed in the hope that it will be useful,
  17. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. -- GNU General Public License for more details.
  20. --
  21. -- See https://www.gnu.org/licenses/ for details
  22. --
  23. -- Pastebin for this program: https://pastebin.com/pwBMKNCb
  24. --
  25. ---------------------------------------------------------------------------------------
  26. -- Version notes:
  27. --
  28. -- Added Table functions
  29. ---------------------------------------------------------------------------------------
  30.  
  31. --Finds a monitor on the network
  32. function monitorSearch()
  33.    local names = peripheral.getNames()
  34.    local i, name
  35.    for i, name in pairs(names) do
  36.       if peripheral.getType(name) == "monitor" then
  37.         test = name
  38.          return peripheral.wrap(name)
  39.       else
  40.          --return null
  41.       end
  42.    end
  43. end
  44.  
  45. function getCentertextPos(text, mon)
  46.     w, h = mon.getSize()
  47.     mon.setCursorPos(math.floor((x - #text) / 2) + 1)
  48.  
  49. end
  50.  
  51. --Sorting function: Alpha
  52. function pairsByKeys (t, f)
  53.       local a = {}
  54.       for n in pairs(t) do table.insert(a, n) end
  55.       table.sort(a, f)
  56.       local i = 0      -- iterator variable
  57.       local iter = function ()   -- iterator function
  58.         i = i + 1
  59.         if a[i] == nil then return nil
  60.         else return a[i], t[a[i]]
  61.         end
  62.       end
  63.       return iter
  64.     end
  65.  
  66. --Draw line on monitor
  67. function draw_line(x, y, length, color, monitor)
  68.     monitor.setBackgroundColor(color)
  69.     monitor.setCursorPos(x,y)
  70.     monitor.write(string.rep(" ", length))
  71. end
  72.  
  73. --Draw line in Terminal
  74. function draw_line_term(x, y, length, color)
  75.     term.setBackgroundColor(color)
  76.     term.setCursorPos(x,y)
  77.     term.write(string.rep(" ", length))
  78. end
  79.  
  80. -- Compact Monitor Write function
  81. function CWrite(col, row, monitor, text, color)
  82.     color = color or colors.white
  83.     monitor.setCursorPos(col,row)
  84.     monitor.clearLine()
  85.     monitor.setTextColor(color)
  86.     monitor.write(text)
  87. end
  88.  
  89. -- Compact Terminal Write function
  90. function CTWrite(col, row, text, color)
  91.     color = color or colors.white
  92.     term.setCursorPos(col,row)
  93.     term.setTextColor(color)
  94.     term.write(text)
  95. end
  96.  
  97. -- Get number of items in a table
  98. function tablelength(T)
  99.   local count = 0
  100.   for _ in pairs(T) do count = count + 1 end
  101.   return count
  102. end
RAW Paste Data