maxsar

skan

Dec 21st, 2020 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 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. local me = peripheral.wrap("back")
  51. term.clear()
  52. term.setCursorPos(1,1)
  53.  
  54. --manual
  55. posY = -1
  56. filename = "block_colors.txt"
  57. --auto
  58. blockID = {}
  59. colorID = {}
  60. screenSize = 0
  61. if fs.exists(filename) then
  62. print("file exist loading...")
  63. sleep(1)
  64.  
  65. file = fs.open(filename, "r")
  66. switch = true
  67. line = file.readLine()
  68. while line ~= nil do
  69. if switch then
  70. table.insert(blockID,line)
  71. print("wczytano: " ..line .." do blockID")
  72. switch = false
  73. else
  74. table.insert(colorID,line)
  75. term.setTextColor(charToColor(line))
  76. print("wczytano: " ..line .." do colorID")
  77. term.setTextColor(charToColor("0"))
  78. switch = true
  79. end
  80. line = file.readLine()
  81. end
  82. file.close()
  83. print("file loaded setting screen size...")
  84. sleep(1)
  85. end
  86.  
  87. --ustawia rozmiar ekranu
  88. for i, block in pairs(me.scan()) do
  89. if block.x > screenSize then
  90. screenSize = block.x
  91. end
  92. end
  93. print("screen size: " ..screenSize)
  94. sleep(1)
  95. print("starting scanning!")
  96. sleep(1)
  97.  
  98.  
  99. tempBlockID = ""
  100. while true do
  101. term.setBackgroundColor(colors.black)
  102. term.clear()
  103. for i, block in pairs(me.scan()) do
  104.  
  105. --evenevenlower
  106. tempBlockID = ""
  107. if block.name ~= "minecraft:air" and block.y == posY - 2 then
  108. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  109.  
  110. tempBlockID = ""
  111. for o, line in pairs(blockID) do
  112. if block.name == blockID[o] then
  113. tempBlockID = o
  114. end
  115. end
  116.  
  117. if tempBlockID ~= "" then
  118. term.setBackgroundColor(colors.black)
  119. term.setTextColor(charToColor(colorID[tempBlockID]))
  120. write("\127")
  121. end
  122.  
  123. end
  124.  
  125. --evelower
  126. tempBlockID = ""
  127. if block.name ~= "minecraft:air" and block.y == posY - 1 then
  128. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  129.  
  130. tempBlockID = ""
  131. for o, line in pairs(blockID) do
  132. if block.name == blockID[o] then
  133. tempBlockID = o
  134. end
  135. end
  136.  
  137. if tempBlockID ~= "" then
  138. term.setTextColor(colors.black)
  139. pixel(charToColor(colorID[tempBlockID]),"\127")
  140. else
  141. term.setBackgroundColor(colors.black)
  142. term.setTextColor(colors.red)
  143. write("\191")
  144. end
  145.  
  146. end
  147.  
  148. --floor
  149. tempBlockID = ""
  150. if block.name ~= "minecraft:air" and block.y == posY then
  151. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  152.  
  153.  
  154. for o, line in pairs(blockID) do
  155. if block.name == blockID[o] then
  156. tempBlockID = o
  157. end
  158. end
  159.  
  160. if tempBlockID ~= "" then
  161. term.setTextColor(colors.gray)
  162. pixel(charToColor(colorID[tempBlockID]),"\127")
  163. else
  164. term.setBackgroundColor(colors.black)
  165. term.setTextColor(colors.red)
  166. write("?")
  167. end
  168.  
  169. end
  170.  
  171. --walls
  172. tempBlockID = ""
  173. if block.name ~= "minecraft:air" and block.y == posY + 1 then
  174. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  175.  
  176. tempBlockID = ""
  177. for o, line in pairs(blockID) do
  178. if block.name == blockID[o] then
  179. tempBlockID = o
  180. end
  181. end
  182.  
  183. if tempBlockID ~= "" then
  184. term.setTextColor(colors.white)
  185. pixel(charToColor(colorID[tempBlockID]),"\127")
  186. else
  187. term.setBackgroundColor(colors.black)
  188. term.setTextColor(colors.red)
  189. write("X")
  190. end
  191.  
  192. end
  193.  
  194. --walls +1
  195. tempBlockID = ""
  196. if block.name ~= "minecraft:air" and block.y == posY + 2 then
  197. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  198.  
  199. tempBlockID = ""
  200. for o, line in pairs(blockID) do
  201. if block.name == blockID[o] then
  202. tempBlockID = o
  203. end
  204. end
  205.  
  206. if tempBlockID ~= "" then
  207. term.setTextColor(colors.black)
  208. pixel(charToColor(colorID[tempBlockID])," ")
  209. else
  210. term.setBackgroundColor(colors.black)
  211. term.setTextColor(colors.red)
  212. write("X")
  213. end
  214.  
  215. end
  216.  
  217. end
  218.  
  219. --pozycja gracza
  220. term.setCursorPos(screenSize,screenSize)
  221. term.setBackgroundColor(term.getBackgroundColor())
  222. term.setTextColor(colors.red)
  223. write("\2")
  224. sleep(0.2)
  225. end
  226.  
Add Comment
Please, Sign In to add comment