Advertisement
maxsar

Untitled

Dec 21st, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 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.  
  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. net.open(port)
  92. event, side, port1, port2, msg = os.pullEvent( "modem_message" )
  93. for i, block in pairs(msg) do
  94. if block.x > screenSize then
  95. screenSize = block.x
  96. end
  97. end
  98. print("screen size: " ..screenSize)
  99. sleep(1)
  100. print("starting scanning!")
  101. sleep(1)
  102.  
  103.  
  104. tempBlockID = ""
  105. while true do
  106. event, side, port1, port2, msg = os.pullEvent( "modem_message" )
  107. term.setBackgroundColor(colors.black)
  108. term.clear()
  109. for i, block in pairs(msg) do
  110.  
  111. if block.name ~= "minecraft:air" and block.y == posY + 2 then --walls +1
  112. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  113.  
  114. tempBlockID = ""
  115. for o, line in pairs(blockID) do
  116. if block.name == blockID[o] then
  117. tempBlockID = o
  118. end
  119. end
  120.  
  121. if tempBlockID ~= "" then
  122. term.setTextColor(colors.black)
  123. pixel(charToColor(colorID[tempBlockID])," ")
  124. else
  125. term.setBackgroundColor(colors.black)
  126. term.setTextColor(colors.red)
  127. write("X")
  128. end
  129.  
  130. elseif block.name ~= "minecraft:air" and block.y == posY + 1 then --walls
  131. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  132.  
  133. tempBlockID = ""
  134. for o, line in pairs(blockID) do
  135. if block.name == blockID[o] then
  136. tempBlockID = o
  137. end
  138. end
  139.  
  140. if tempBlockID ~= "" then
  141. term.setTextColor(colors.white)
  142. pixel(charToColor(colorID[tempBlockID]),"\127")
  143. else
  144. term.setBackgroundColor(colors.black)
  145. term.setTextColor(colors.red)
  146. write("X")
  147. end
  148.  
  149. elseif block.name ~= "minecraft:air" and block.y == posY then --floor
  150. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  151.  
  152.  
  153. for o, line in pairs(blockID) do
  154. if block.name == blockID[o] then
  155. tempBlockID = o
  156. end
  157. end
  158.  
  159. if tempBlockID ~= "" then
  160. term.setTextColor(colors.gray)
  161. pixel(charToColor(colorID[tempBlockID]),"\127")
  162. else
  163. term.setBackgroundColor(colors.black)
  164. term.setTextColor(colors.red)
  165. write("?")
  166. end
  167.  
  168. elseif block.name ~= "minecraft:air" and block.y == posY - 1 then --evelower
  169. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  170.  
  171. tempBlockID = ""
  172. for o, line in pairs(blockID) do
  173. if block.name == blockID[o] then
  174. tempBlockID = o
  175. end
  176. end
  177.  
  178. if tempBlockID ~= "" then
  179. term.setTextColor(colors.black)
  180. pixel(charToColor(colorID[tempBlockID]),"\127")
  181. else
  182. term.setBackgroundColor(colors.black)
  183. term.setTextColor(colors.red)
  184. write("\191")
  185. end
  186.  
  187. elseif block.name ~= "minecraft:air" and block.y == posY - 2 then --evenevenlower
  188. term.setCursorPos(block.x + screenSize,block.z + screenSize)
  189.  
  190. tempBlockID = ""
  191. for o, line in pairs(blockID) do
  192. if block.name == blockID[o] then
  193. tempBlockID = o
  194. end
  195. end
  196.  
  197. if tempBlockID ~= "" then
  198. term.setBackgroundColor(colors.black)
  199. term.setTextColor(charToColor(colorID[tempBlockID]))
  200. write("\127")
  201. end
  202.  
  203. end
  204.  
  205. end --koniec fora
  206.  
  207. --pozycja gracza
  208. term.setCursorPos(screenSize,screenSize)
  209. term.setBackgroundColor(term.getBackgroundColor())
  210. term.setTextColor(colors.red)
  211. write("\2")
  212. sleep(0.2)
  213. end
  214.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement