Advertisement
theinsekt

orefinder

Sep 13th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. os.loadAPI("theinsektAPIs/poz3")
  2. os.loadAPI("theinsektAPIs/poz3a")
  3.  
  4.  
  5. --return code: 0=blocked, -1=no_fuel, -2=reached_limit,  1< = found something
  6. function searchDigLoop(slots,limit)
  7.         if(limit==nil) then limit=10000 end
  8.         if(slots<1 or slots>16) then
  9.         error("Error: slots have to be a number between 1 and 16 (inclusive).")
  10.     end
  11.     for slotNum = 1, slots do
  12.         if(turtle.getItemCount(slotNum)==0) then
  13.             error("Error: One of the given slots are empty")
  14.         end
  15.     end
  16.     for i=0, limit do
  17.         local slotNum=getSlotNumFUD(slots)
  18.                 if slotNum~=0 then return slotNum end
  19.         poz3a.detectDig("u")
  20.         poz3a.detectDig("d")
  21.         if(not poz3a.detectDigGo2("f",true)) then
  22.             if turtle.getFuelLevel()==0 then
  23.                 return -1--no fuel
  24.             end
  25.             return 0--blocked
  26.         end
  27.     end
  28.         return -2
  29.  
  30. end
  31.  
  32. function getSlotNumFUD(slots)
  33.     local slotNum=getSlotNum("f", slots)
  34.     --print("FUD: ",slotNum)
  35.     if(slotNum~=0) then return slotNum end
  36.     local slotNum=getSlotNum("u", slots)
  37.     --print("FUD: ",slotNum)
  38.     if(slotNum~=0) then return slotNum end
  39.     local slotNum=getSlotNum("d", slots)
  40.     --print("FUD: ",slotNum)
  41.     if(slotNum~=0) then return slotNum end
  42.     --print("FUD r: ",0)
  43.     return 0
  44. end
  45.  
  46.  
  47. function getSlotNum(direction, slots)
  48.         --print(direction)
  49.     if(poz3.detect(direction)) then
  50.                 --print("detected")
  51.         for slotNum = 1, slots do
  52.             --print("compare with: ",slotNum)
  53.             turtle.select(slotNum)
  54.             if poz3.compare(direction) then
  55.                 --print("match: ",slotNum)
  56.                 return slotNum
  57.             end
  58.         end
  59.     end
  60.     return 0
  61. end
  62.  
  63.  
  64. args={...}
  65.  
  66. if(#args<1) then
  67.     print("Usage: orefinder <slotNum> <optional_limit>")
  68.         print("Will dig 3 high tunnel forward until finds one of the blocks in slots 1 to slotNum.")
  69.     return
  70. end
  71. local slots=tonumber(args[1])
  72. local limit=10000
  73. if args[2]~=nil then
  74.  limit=tonumber(args[2])
  75. end
  76. local res=searchDigLoop(slots,limit)
  77. --local res=getSlotNumFUD(slots)
  78. --local res=getSlotNum("d",slots)
  79. print(res)
  80. if res>0 then print("Found a match with slotNum ",res) end
  81. if res==0 then print("Blocked!") end
  82. if res==-1 then print("Out of fuel!") end
  83. if res==-2 then print("At limit!") end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement