Advertisement
dacman9

Orefind

Aug 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. local a = peripheral.wrap('back')
  2. local sp = peripheral.find('speaker')
  3. local lastnum = 0
  4. local imp = {"minecraft:diamond_ore","minecraft:gold_ore"}
  5. while true do
  6. term.clear()
  7. local s = a.scan()
  8. local oretable = {}
  9. for i = 1,#s do
  10. if string.find(s[i].name,"ore") or string.find(s[i].name,"resource") then
  11. if not oretable[s[i].name] then
  12. oretable[s[i].name] = {}
  13. end
  14. oretable[s[i].name][table.maxn(oretable[s[i].name])+1] = s[i]
  15. local index = oretable[s[i].name][table.maxn(oretable[s[i].name])]
  16. if (not oretable[s[i].name].dist) or (math.abs(index.x)+math.abs(index.y)+math.abs(index.z) < oretable[s[i].name].dist) then
  17. oretable[s[i].name].dist = math.abs(index.x)+math.abs(index.y)+math.abs(index.z)
  18. oretable[s[i].name].index = table.maxn(oretable[s[i].name])
  19. end
  20. end
  21. end
  22. local i = 1
  23. local spec = false
  24. for k,v in pairs(oretable) do
  25. term.setCursorPos(1,i)
  26. term.write(k..": "..#v)
  27. for j = 1,#imp do
  28. if imp[j] == k then
  29. spec = true
  30. end
  31. end
  32. i = i+1
  33. end
  34. if sp and i > lastnum then
  35. sp.playNote("harp",1,6)
  36. sleep(0.1)
  37. sp.playNote("harp",1,10)
  38. sleep(0.1)
  39. sp.playNote("harp",1,13)
  40. elseif sp and i < lastnum then
  41. sp.playNote("harp",1,9)
  42. sleep(0.1)
  43. sp.playNote("harp",1,8)
  44. sleep(0.1)
  45. sp.playNote("harp",1,6)
  46. end
  47. if sp and spec then
  48. sp.playNote("harp",1,25)
  49. sleep(0.1)
  50. sp.playNote("harp",1,25)
  51. end
  52. lastnum = i
  53. os.startTimer(1)
  54. while true do
  55. local e,a,b,c = os.pullEvent()
  56. if e == "mouse_click" and #oretable <= c then
  57. local newtable = {}
  58. local i = 1
  59. for _,v in pairs(oretable) do
  60. newtable[i] = v
  61. i = i+1
  62. end
  63. term.clear()
  64. term.setCursorPos(1,1)
  65. local tbl = newtable[c][newtable[c].index]
  66. term.write("X: "..tbl.x.." Y: "..tbl.y.." Z: "..tbl.z)
  67. term.setCursorPos(1,2)
  68. term.write(tbl.name)
  69. sleep(0.5)
  70. os.pullEvent("mouse_click")
  71. break
  72. elseif e == "timer" then
  73. break
  74. end
  75. end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement