TechManDylan

QuartzFinder

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×