Advertisement
cyber_Ahn

ME Bridge

Aug 29th, 2016
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. -- Database for Mods under construction
  2. -- for mc 1.7.x and 1.8.x
  3.  
  4. shell.run("delete caAPI")
  5. shell.run("pastebin get EDLdR1nF caAPI")
  6. os.loadAPI("caAPI")
  7. local me_number = caAPI.get_hardware("meBridge")
  8. if me_number == "meBridge_off" then
  9. shell.run("clear")
  10. else
  11. net = peripheral.wrap(me_number)
  12. end
  13. shell.run("delete database/IdNameENG.db")
  14. shell.run("pastebin get hTJaBiJA database/IdNameENG.db")
  15. local IDlist = caAPI.loadFile("database/IdNameENG.db")
  16. local page = 1
  17. local maxPage = 40
  18. local maxEntries = 23
  19.  
  20. --set monitor
  21. function set_monitor()
  22. local monitor_number = caAPI.get_hardware("monitor")
  23. local found = fs.exists("config/monitor.cfg")
  24. if found == true then
  25. file = fs.open("config/monitor.cfg","r")
  26. local fileData = {}
  27. local line = file.readLine()
  28. repeat
  29. table.insert(fileData,line)
  30. line = file.readLine()
  31. until line == nil
  32. file.close()
  33. monitor_number = fileData[1]
  34. end
  35. mon = peripheral.wrap(monitor_number)
  36. end
  37.  
  38. --draw screen
  39. function draw_screen(page)
  40. mon.setBackgroundColor(colors.black)
  41. mon.setTextColor(colors.white)
  42. mon.clear()
  43. mon.setBackgroundColor(colors.black)
  44. mon.setCursorPos(2,1)
  45. mon.setTextColor(colors.blue)
  46. mon.write("ME Bridge Port:"..me_number)
  47. mon.setCursorPos(50,1)
  48. mon.setBackgroundColor(colors.red)
  49. mon.setTextColor(colors.black)
  50. mon.write("X")
  51. mon.setBackgroundColor(colors.black)
  52. mon.setTextColor(colors.green)
  53. mon.setCursorPos(2,2)
  54. local items = net.listAll()
  55. mon.write(#items.." kinds of items found.")
  56. mon.setTextColor(colors.yellow)
  57. mon.setCursorPos(34,1)
  58. mon.write("Page:"..tostring(page))
  59. mon.setCursorPos(34,2)
  60. mon.write("Back Next Refresh")
  61. mon.setTextColor(colors.white)
  62. mon.setCursorPos(2,3)
  63. mon.write("Mod")
  64. mon.setCursorPos(17,3)
  65. mon.write("Slot")
  66. mon.setCursorPos(25,3)
  67. mon.write("Name")
  68. y = 4
  69. max = page * maxEntries
  70. min = max - maxEntries
  71. for num, itemID in pairs(items) do
  72. if itemID~=nil then
  73. if num > (min -1) and num < (max + 1) then
  74. data = caAPI.split(itemID,":")
  75. mon.setCursorPos(2,y)
  76. mon.write(data[1])
  77. dataC = caAPI.split(data[2]," ")
  78. if dataC[2] == "0" then
  79. name = dataC[1]
  80. else
  81. name = dataC[1]..":"..dataC[2]
  82. end
  83. mon.setCursorPos(18,y)
  84. mon.write(num)
  85. mon.setCursorPos(25,y)
  86. mon.write(caAPI.AtoB(name,IDlist))
  87. y = y + 1
  88. end
  89. end
  90. end
  91. touch()
  92. end
  93.  
  94. --touch
  95. function touch()
  96. local ix = true
  97. while ix == true do
  98. event, side, x, y = os.pullEvent()
  99. if event == "monitor_touch" then
  100. if x == 50 and y == 1 then
  101. ix = false
  102. shell.run("clear")
  103. end
  104. if y == 2 and x > 33 and x < 38 then
  105. ix = false
  106. if page ~= 1 then
  107. page = page - 1
  108. sleep(1)
  109. end
  110. draw_screen(page)
  111. end
  112. if y == 2 and x > 38 and x < 43 then
  113. ix = false
  114. page = page + 1
  115. sleep(1)
  116. if page > maxPage then
  117. page = maxPage
  118. sleep(1)
  119. end
  120. draw_screen(page)
  121. end
  122. if y == 2 and x > 43 and x < 50 then
  123. ix = false
  124. page = 1
  125. sleep(1)
  126. draw_screen(page)
  127. end
  128. end
  129. end
  130. end
  131. --start program
  132. set_monitor()
  133. draw_screen(page)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement