Tbonetomtom

scanner

Dec 27th, 2023 (edited)
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. local geoScan = peripheral.find("geoScanner")
  2.  
  3. function isNeighbor(block1, block2)
  4.  return math.abs(block1.x - block2.x) <= 1 and
  5.       math.abs(block1.y - block2.y) <= 1 and
  6.       math.abs(block1.z - block2.z) <= 1
  7. end
  8.  
  9. function scanForDiamondOre()
  10.   local blocks = geoScan.scan(10)
  11.   sleep(1)
  12.   if type(blocks) ~= "table" then
  13.     print("Error: geoScanner.scan() did not return a table.".. type(blocks))
  14.   else
  15.     local groups = {}
  16.     for _, block in pairs(blocks) do
  17.       if block.name == "minecraft:diamond_ore" or block.name == "minecraft:deepslate_diamond_ore" then
  18.         local groupExists = false
  19.         for _, group in pairs(groups) do
  20.           for _, groupBlock in pairs(group) do
  21.             if isNeighbor(block, groupBlock) then
  22.               table.insert(group, block)
  23.               groupExists = true
  24.               break
  25.             end
  26.           end
  27.           if groupExists then
  28.             break
  29.           end
  30.         end
  31.         if not groupExists then
  32.           table.insert(groups, {block})
  33.         end
  34.       end
  35.     end
  36.     for _, group in pairs(groups) do
  37.       local output = "Found diamond ore group with " .. #group .. " blocks at (" .. group[1].x .. ", " .. group[1].y .. ", " .. group[1].z .. ")"
  38.       io.write(output .. "\n")
  39.       while true do
  40.         local event, key = os.pullEvent('key')
  41.         if event == 'key' then
  42.           break
  43.         end
  44.       end
  45.     end
  46.   end
  47.  end
  48.  
  49. scanForDiamondOre()
Advertisement
Add Comment
Please, Sign In to add comment