TechManDylan

GIScan

May 7th, 2021 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. local scanInterval = 0.2
  2. local renderInterval = 0.05
  3. local scannerRange = 8
  4. local scannerWidth = scannerRange * 2 + 1
  5.  
  6. local size = 0.5
  7. local cellSize = 16
  8. local offsetX = 75
  9. local offsetY = 75
  10.  
  11. local ores = {
  12.     ["fp:erze:4"] = 10,
  13.     ["minecraft:gold_ore"] = 8,
  14.     ["minecraft:iron_ore"] = 2
  15. }
  16.  
  17. local colours = {
  18.     ["minecraft:iron_ore"] = { 255, 150, 50 },
  19.     ["fp:erze:4"] = { 255, 170, 70 },
  20.     ["minecraft:gold_ore"] = { 255, 255, 0 }
  21. }
  22.  
  23. local modules = peripheral.find("neuralInterface")
  24. if not modules then error("Must have a neural interface", 0) end
  25. if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end
  26. if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end
  27.  
  28. local canvas = modules.canvas()
  29. canvas.clear()
  30.  
  31. local block_text = {}
  32. local blocks = {}
  33. for x = -scannerRange, scannerRange, 1 do
  34.     block_text[x] = {}
  35.     blocks[x] = {}
  36.  
  37.     for z = -scannerRange, scannerRange, 1 do
  38.         block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)
  39.         blocks[x][z] = { y = nil, block = nil }
  40.     end
  41. end
  42.  
  43. canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)
  44.  
  45. local function scan()
  46.     while true do
  47.         local scanned_blocks = modules.scan()
  48.  
  49.         for x = -scannerRange, scannerRange do
  50.             for z = -scannerRange, scannerRange do
  51.                 local best_score, best_block, best_y = -1
  52.                 for y = -scannerRange, scannerRange do
  53.                
  54.                     local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
  55.                    
  56.                     if scanned then
  57.                         local new_score = ores[scanned.name]
  58.                         if new_score and new_score > best_score then
  59.                             best_block = scanned.name
  60.                             best_score = new_score
  61.                             best_y = y
  62.                         end
  63.                     end
  64.                 end
  65.  
  66.                 -- Update our block table with this information.
  67.                 blocks[x][z].block = best_block
  68.                 blocks[x][z].y = best_y
  69.             end
  70.         end
  71.        
  72.         sleep(scanInterval)
  73.     end
  74. end
  75.  
  76. local function render()
  77.     while true do
  78.  
  79.         local meta = modules.getMetaOwner and modules.getMetaOwner()
  80.         local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
  81.        
  82.         for x = -scannerRange, scannerRange do
  83.             for z = -scannerRange, scannerRange do
  84.                 local text = block_text[x][z]
  85.                 local block = blocks[x][z]
  86.  
  87.                 if block.block then
  88.                
  89.                     local px = math.cos(angle) * -x - math.sin(angle) * -z
  90.                     local py = math.sin(angle) * -x + math.cos(angle) * -z
  91.  
  92.                     local sx = math.floor(px * size * cellSize)
  93.                     local sy = math.floor(py * size * cellSize)
  94.                     text.setPosition(offsetX + sx, offsetY + sy)
  95.                    
  96.                     text.setText(tostring(block.y))
  97.                     text.setColor(table.unpack(colours[block.block]))
  98.                 else
  99.                
  100.                     text.setText(" ")
  101.                 end
  102.             end
  103.         end
  104.  
  105.         sleep(renderInterval)
  106.     end
  107. end
  108.  
  109. parallel.waitForAll(render, scan)
  110.  
Add Comment
Please, Sign In to add comment