Advertisement
Lanzr

geo_new

Dec 13th, 2022 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local win_main = window.create(term.current(),0,0,27,18)
  2. local win_menu = window.create(term.current(),0,18,27,3)
  3. local goe = peripheral.wrap("back")
  4. local x,y,z
  5. local edgex = 26
  6. local edgey = 20
  7.  
  8. local centerx = 13
  9. local centerz = 9
  10. local fontColor = "0"
  11.  
  12. win_main.setBackgroundColor(colors.white)
  13. win_main.clear()
  14. win_menu.setBackgroundColor(colors.black)
  15. win_menu.clear()
  16.  
  17. -- 只需要在这里注册方块信息即可
  18. local items = {
  19.     ["gold"] = "4",
  20.     ["iron"] = "c",
  21.     ["diamond"] = "3",
  22.     ["zinc"] = "8",
  23.     ["copper"] = "1",
  24.     ["redstone"] = "e",
  25.     ["lapis"] = "b",
  26.     ["emerald"] = "d",
  27.     ["debris"] = "7"
  28. }
  29.  
  30. local locks = {}
  31. for i,j in pairs(items) do
  32.     table.insert(locks,true)
  33. end
  34.  
  35. local function resetlock(state)
  36.     local cal = 1
  37.     for i,j in pairs(locks) do
  38.         locks[cal] = state
  39.         cal = cal+1
  40.     end
  41. end
  42.  
  43.  
  44. term.setCursorPos(1,edgey)
  45. for i,j in pairs(items) do
  46.     term.blit(" ",fontColor,j)
  47.     term.blit(" ",fontColor,j)
  48. end
  49. local pic_resetbtn = paintutils.loadImage("geodetect/pic/rsb.nfp")
  50. paintutils.drawImage(pic_resetbtn,24,19)
  51.  
  52. local function mainloop()
  53. while 1 do
  54.     win_main.clear()
  55.     paintutils.drawPixel(centerx,centerz,colors.pink)
  56.    
  57.     local res = goe.scan(8)
  58.     for i,j in pairs(res) do
  59.         local target
  60.         if (string.find(j["name"],"ore") or string.find(j["name"],"debris")) then
  61.             local cal = 1;
  62.             for k,l in pairs(items) do
  63.                 -- print(i)
  64.                 if (locks[cal] and string.find(j["name"], k)) then
  65.                     target = l
  66.                     break
  67.                 end
  68.                 cal = cal+1
  69.             end
  70.         end
  71.        
  72.         if(target ~= NULL ) then
  73.             x = j["x"]
  74.             y = j["y"]
  75.             z = j["z"]
  76.             local chd  = " "
  77.             if(y < 0) then
  78.                 chd = string.char(25)
  79.             elseif (y > 0) then
  80.                 chd = string.char(24)
  81.             end
  82.             term.setCursorPos(centerx + x,centerz + z)
  83.             term.blit(chd,fontColor,target)
  84.         end
  85.     end
  86.     os.sleep(4)
  87. end
  88. end
  89.  
  90. local function clickMonitor()
  91. while 1 do
  92.     local event, button, mx, my = os.pullEvent("mouse_click")
  93.     if (event ~= nil) then
  94.         if(my > 19 and (mx <19 or mx >23)) then
  95.             resetlock(false)
  96.             local cal = 1
  97.             if(mx > 23) then
  98.                 resetlock(true)
  99.             else
  100.                 for i,j in pairs(items) do
  101.                     if (mx < cal*2 + 1) then
  102.                         locks[cal] = true
  103.                         break
  104.                     end
  105.                     cal = cal + 1
  106.                 end
  107.             end
  108.  
  109.         end
  110.     end
  111. end
  112. end
  113.  
  114. parallel.waitForAll(mainloop, clickMonitor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement