Advertisement
Gorocker

scanner.lua

May 19th, 2024 (edited)
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. Filter = "allthemodium"
  2. Scanner = peripheral.wrap("back")
  3. Cswitch = 12
  4. local function len(x , y)
  5.     return math.sqrt(math.pow(x, 2) + math.pow(y, 2))
  6. end
  7.  
  8. local function pow(b)
  9.     return math.pow(b["x"], 2) + math.pow(b["y"], 2) + math.pow(b["z"],2)
  10. end
  11.  
  12. local function lenb(b)
  13.     local v = vector.new(b["x"], b["y"], b["z"])
  14.     return v:length()
  15. end
  16.  
  17. local function rot(x,y, a)
  18.     local xr =  math.cos(a) * x + math.sin(a) * y
  19.     local yr =  -math.sin(a) * x + math.cos(a) * y
  20.     return xr , yr
  21. end
  22.  
  23. local function norm(x,y)
  24.     local len = len(x,y)
  25.     return x / len, y / len
  26. end
  27.  
  28. local function div(x,y , amount)
  29.     return x / amount, y / amount
  30. end
  31.  
  32. local function mul(x, y, amount)
  33.     return x * amount, y * amount
  34. end
  35.  
  36. local function middle()
  37.     local width, height = term.getSize()
  38.     return width / 2, height / 2
  39. end
  40.  
  41. local function compass(x, y)
  42.     local ox, oy = middle()
  43.     local dis = len(x,y)
  44.     if dis < Cswitch then
  45.         print("normal")
  46.         paintutils.drawPixel(ox , oy, colors.white)
  47.         paintutils.drawPixel(ox + x, oy + y, colors.green)
  48.     else
  49.         print("zoomed out")
  50.         paintutils.drawPixel(ox , oy, colors.white)
  51.         local sx, sy = div(x,y,dis)
  52.         local sx, sy = mul(sx,sy,5)
  53.         paintutils.drawPixel(ox + sx, oy + sy, colors.red)
  54.     end
  55.     term.setBackgroundColor(colors.black)
  56. end
  57.  
  58.  
  59. local function findClose()
  60.     local minb = nil
  61.     local minlen = math.huge
  62.     for id, block in pairs(Blocks) do
  63.         if string.match(block["name"], Filter) then
  64.            local len =  pow(block)
  65.            if len < minlen then
  66.                 minlen = len
  67.                 minb = block
  68.            end
  69.         end
  70.     end
  71.     return minb
  72. end
  73.  
  74. while true do
  75.     term.clear()
  76.     term.setCursorPos(1, 1)
  77.     term.setBackgroundColor(colors.black)
  78.     Blocks, Err = Scanner.scan(16)
  79.     Found = false
  80.     local block = findClose()
  81.     if block ~= nil then
  82.         term.setTextColor(colors.green)
  83.         term.write(block["name"])
  84.         term.setTextColor(colors.white)
  85.         term.write(" at ")
  86.         term.setTextColor(colors.blue)
  87.         print(string.format("x:%d z:%d y:%d", block["x"], block["z"], block["y"]))
  88.         compass(block["x"], block["z"])
  89.     else
  90.         print(os.clock())
  91.         print("Nothing found")
  92.     end
  93.     sleep(5)
  94. end
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement