maxsar

user

Dec 21st, 2020 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. function charToColor(code)
  2. if code == "0" then
  3. return colors.white
  4. elseif code == "1" then
  5. return colors.orange
  6. elseif code == "2" then
  7. return colors.magenta
  8. elseif code == "3" then
  9. return colors.lightBlue
  10. elseif code == "4" then
  11. return colors.yellow
  12. elseif code == "5" then
  13. return colors.lime
  14. elseif code == "6" then
  15. return colors.pink
  16. elseif code == "7" then
  17. return colors.gray
  18. elseif code == "8" then
  19. return colors.lightGray
  20. elseif code == "9" then
  21. return colors.cyan
  22. elseif code == "a" then
  23. return colors.purple
  24. elseif code == "b" then
  25. return colors.blue
  26. elseif code == "c" then
  27. return colors.brown
  28. elseif code == "d" then
  29. return colors.green
  30. elseif code == "e" then
  31. return colors.red
  32. elseif code == "f" then
  33. return colors.black
  34. else
  35. return nil
  36. end
  37. end
  38.  
  39. function drawPixel(x,y,color)
  40. term.setCursorPos(x,y)
  41. term.setBackgroundColor(color)
  42. write(" ")
  43. end
  44.  
  45. function pixel(color,ch)
  46. term.setBackgroundColor(color)
  47. write(ch)
  48. end
  49.  
  50.  
  51. term.clear()
  52. term.setCursorPos(1,1)
  53.  
  54. --manual
  55. posY = -1
  56. filename = "block_colors.txt"
  57. net = peripheral.wrap("back")
  58. port = 420
  59. net.open(port)
  60. --auto
  61. blockID = {}
  62. colorID = {}
  63. screenSize = 0
  64. if fs.exists(filename) then
  65. print("file exist loading...")
  66. sleep(1)
  67.  
  68. file = fs.open(filename, "r")
  69. switch = true
  70. line = file.readLine()
  71. while line ~= nil do
  72. if switch then
  73. table.insert(blockID,line)
  74. print("wczytano: " ..line .." do blockID")
  75. switch = false
  76. else
  77. table.insert(colorID,line)
  78. term.setTextColor(charToColor(line))
  79. print("wczytano: " ..line .." do colorID")
  80. term.setTextColor(charToColor("0"))
  81. switch = true
  82. end
  83. line = file.readLine()
  84. end
  85. file.close()
  86. print("file loaded setting screen size...")
  87. sleep(1)
  88. end
  89.  
  90. --ustawia rozmiar ekranu
  91. event, side, port1, port2, msg = os.pullEvent( "modem_message" )
  92. for i, block in pairs(msg) do
  93. if block.x > screenSize then
  94. screenSize = block.x
  95. end
  96. end
  97. print("screen size: " ..screenSize)
  98. sleep(1)
  99. print("starting scanning!")
  100. sleep(1)
  101.  
  102.  
  103. tempBlockID = ""
  104. while true do
  105. event, side, port1, port2, msg = os.pullEvent( "modem_message" )
  106. term.setBackgroundColor(colors.black)
  107. term.clear()
  108. for i, block in pairs(msg) do
  109.  
  110. --evenevenlower
  111. tempBlockID = ""
  112. if block.name ~= "minecraft:air" and block.y == posY - 2 then
  113. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  114.  
  115. tempBlockID = ""
  116. for o, line in pairs(blockID) do
  117. if block.name == blockID[o] then
  118. tempBlockID = o
  119. end
  120. end
  121.  
  122. if tempBlockID ~= "" then
  123. term.setBackgroundColor(colors.black)
  124. term.setTextColor(charToColor(colorID[tempBlockID]))
  125. write("\127")
  126. end
  127.  
  128. end
  129.  
  130. --evelower
  131. tempBlockID = ""
  132. if block.name ~= "minecraft:air" and block.y == posY - 1 then
  133. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  134.  
  135. tempBlockID = ""
  136. for o, line in pairs(blockID) do
  137. if block.name == blockID[o] then
  138. tempBlockID = o
  139. end
  140. end
  141.  
  142. if tempBlockID ~= "" then
  143. term.setTextColor(colors.black)
  144. pixel(charToColor(colorID[tempBlockID]),"\127")
  145. else
  146. term.setBackgroundColor(colors.black)
  147. term.setTextColor(colors.red)
  148. write("\191")
  149. end
  150.  
  151. end
  152.  
  153. --floor
  154. tempBlockID = ""
  155. if block.name ~= "minecraft:air" and block.y == posY then
  156. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  157.  
  158.  
  159. for o, line in pairs(blockID) do
  160. if block.name == blockID[o] then
  161. tempBlockID = o
  162. end
  163. end
  164.  
  165. if tempBlockID ~= "" then
  166. term.setTextColor(colors.gray)
  167. pixel(charToColor(colorID[tempBlockID]),"\127")
  168. else
  169. term.setBackgroundColor(colors.black)
  170. term.setTextColor(colors.red)
  171. write("?")
  172. end
  173.  
  174. end
  175.  
  176. --walls
  177. tempBlockID = ""
  178. if block.name ~= "minecraft:air" and block.y == posY + 1 then
  179. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  180.  
  181. tempBlockID = ""
  182. for o, line in pairs(blockID) do
  183. if block.name == blockID[o] then
  184. tempBlockID = o
  185. end
  186. end
  187.  
  188. if tempBlockID ~= "" then
  189. term.setTextColor(colors.white)
  190. pixel(charToColor(colorID[tempBlockID]),"\127")
  191. else
  192. term.setBackgroundColor(colors.black)
  193. term.setTextColor(colors.red)
  194. write("X")
  195. end
  196.  
  197. end
  198.  
  199. --walls +1
  200. tempBlockID = ""
  201. if block.name ~= "minecraft:air" and block.y == posY + 2 then
  202. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  203.  
  204. tempBlockID = ""
  205. for o, line in pairs(blockID) do
  206. if block.name == blockID[o] then
  207. tempBlockID = o
  208. end
  209. end
  210.  
  211. if tempBlockID ~= "" then
  212. term.setTextColor(colors.black)
  213. pixel(charToColor(colorID[tempBlockID])," ")
  214. else
  215. term.setBackgroundColor(colors.black)
  216. term.setTextColor(colors.red)
  217. write("X")
  218. end
  219.  
  220. end
  221.  
  222. end
  223.  
  224. --pozycja gracza
  225. term.setCursorPos(screenSize,screenSize)
  226. term.setBackgroundColor(term.getBackgroundColor())
  227. term.setTextColor(colors.red)
  228. write("\2")
  229. sleep(0.2)
  230. end
  231.  
Add Comment
Please, Sign In to add comment