Advertisement
osmarks

Orescan

Dec 14th, 2019
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1. -- Original concept by
  2. --   HydroNitrogen (a.k.a. GoogleTech, Wendelstein7)
  3. --   Bram S. (a.k.a ThatBram0101, bram0101)
  4. -- see: https://energetic.pw/computercraft/ore3d/assets/ore3d.lua
  5. -- From https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/neural/ores.lua
  6. -- Modified by gollark
  7.  
  8. -- Updated to use new(ish) canvas3d by kepler155c
  9.  
  10. local gps        = _G.gps
  11. local keys       = _G.keys
  12. local os         = _G.os
  13. local parallel   = _G.parallel
  14. local peripheral = _G.peripheral
  15. local tableconcat = table.concat
  16. local mathabs = math.abs
  17. local mathfloor = math.floor
  18.  
  19. local function showRequirements(missing)
  20.     print([[A neural interface is required containing:
  21.  * Overlay glasses
  22.  * Scanner
  23.  * Modem
  24. ]])
  25.     error('Missing: ' .. missing)
  26. end
  27.  
  28. local modules = peripheral.find('neuralInterface')
  29. if not modules then
  30.     showRequirements('Neural interface')
  31. elseif not modules.canvas then
  32.     showRequirements('Overlay glasses')
  33. elseif not modules.scan then
  34.     showRequirements('Scanner module')
  35. end
  36.  
  37. -- size of displayed block
  38. local BLOCK_SIZE = .5
  39.  
  40. local function getPoint()
  41.     local pt = { gps.locate() }
  42.     if pt[1] then
  43.         return {
  44.             x = pt[1],
  45.             y = pt[2],
  46.             z = pt[3],
  47.         }
  48.     end
  49. end
  50.  
  51. local targets = {
  52.     ["minecraft:emerald_ore"]      = { "minecraft:emerald_ore", 0 },
  53.     ["minecraft:diamond_ore"]      = { "minecraft:diamond_ore", 0 },
  54.     ["minecraft:gold_ore"]         = { "minecraft:gold_ore", 0 },
  55.     ["minecraft:redstone_ore"]     = { "minecraft:redstone_ore", 0 },
  56.     ["minecraft:lit_redstone_ore"] = { "minecraft:redstone_ore", 0 },
  57.     ["minecraft:iron_ore"]         = { "minecraft:iron_ore", 0 },
  58.     ["minecraft:lapis_ore"]        = { "minecraft:lapis_ore", 0 },
  59.     ["minecraft:coal_ore"]         = { "minecraft:coal_ore", 0 },
  60.     ["minecraft:quartz_ore"]       = { "minecraft:quartz_ore", 0 },
  61.     ["minecraft:glowstone"]        = { "minecraft:glowstone", 0 },
  62.     ["projectred-exploration:ore"] = { "projectred-exploration:ore", 0 },
  63.     ["projectred-exploration:ore:1"] = { "projectred-exploration:ore", 1 },
  64.     ["projectred-exploration:ore:2"] = { "projectred-exploration:ore", 2 },
  65.     ["projectred-exploration:ore:3"] = { "projectred-exploration:ore", 3 },
  66.     ["projectred-exploration:ore:4"] = { "projectred-exploration:ore", 4 },
  67.     ["projectred-exploration:ore:5"] = { "projectred-exploration:ore", 5 },
  68.     ["projectred-exploration:ore:6"] = { "projectred-exploration:ore", 6 },
  69.     ["quark:biotite_ore"] = { "quark:biotite_ore", 0 },
  70. }
  71.  
  72. local projecting = { }
  73. local offset = getPoint() or showRequirements('GPS')
  74. local canvas = modules.canvas3d().create({
  75.     -(offset.x % 1) + .5,
  76.     -(offset.y % 1) + .5,
  77.     -(offset.z % 1) + .5 })
  78.  
  79. local function update()
  80.     while true do
  81.         -- order matters
  82.         local scanned = modules.scan()
  83.         local pos = getPoint()
  84.  
  85.         if pos then
  86.             if mathabs(pos.x - offset.x) +
  87.                  mathabs(pos.y - offset.y) +
  88.                  mathabs(pos.z - offset.z) > 64 then
  89.                 for _, b in pairs(projecting) do
  90.                     b.box.remove()
  91.                 end
  92.                 projecting = { }
  93.                 offset = pos
  94.                 canvas.recenter({
  95.                     -(offset.x % 1) + .5,
  96.                     -(offset.y % 1) + .5,
  97.                     -(offset.z % 1) + .5 })
  98.             end
  99.  
  100.             local blocks = { }
  101.             for _, b in pairs(scanned) do
  102.                 if targets[b.name..(b.metadata ~= 0 and ":"..b.metadata or "")] then
  103.                     -- track block's world position
  104.                     b.id = tableconcat({
  105.                         math.floor(pos.x + b.x),
  106.                         math.floor(pos.y + b.y),
  107.                         math.floor(pos.z + b.z) }, ':')
  108.                     blocks[b.id] = b
  109.                 end
  110.             end
  111.  
  112.             for _, b in pairs(blocks) do
  113.                 if not projecting[b.id] then
  114.                     projecting[b.id] = b
  115.  
  116.                     local target = targets[b.name..(b.metadata ~= 0 and ":"..b.metadata or "")]
  117.  
  118.                     local x = b.x - mathfloor(offset.x) + mathfloor(pos.x)
  119.                     local y = b.y - mathfloor(offset.y) + mathfloor(pos.y)
  120.                     local z = b.z - mathfloor(offset.z) + mathfloor(pos.z)
  121.  
  122.                     --[[
  123.                     b.box = canvas.addFrame({ x, y, z })
  124.                     b.box.setDepthTested(false)
  125.                     b.box.addItem({ .25, .25 }, target[1], target[2], 2)
  126.                     --]]
  127.  
  128.                     b.box = canvas.addItem({ x, y, z }, target[1], target[2], BLOCK_SIZE)
  129.                     b.box.setDepthTested(false)
  130.                 end
  131.             end
  132.  
  133.             for _, b in pairs(projecting) do
  134.                 if not blocks[b.id] then
  135.                     b.box.remove()
  136.                     projecting[b.id] = nil
  137.                 end
  138.             end
  139.         end
  140.  
  141.         os.sleep(.5)
  142.     end
  143. end
  144.  
  145. parallel.waitForAny(
  146.     function()
  147.         print('Ore visualization started')
  148.         print('Press enter to exit')
  149.         while true do
  150.             local e, key = os.pullEventRaw('key')
  151.             if key == keys.enter or e == 'terminate' then
  152.                 break
  153.             end
  154.         end
  155.     end,
  156.     update
  157. )
  158.  
  159. canvas.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement