Advertisement
theinsekt

orefinder2

Nov 21st, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. --should dig forward until finds the wanted ores
  2. --not finished
  3. --experimental
  4. --pastebin get iiRX8ezE theinsekt/orefinder2
  5.  
  6. --get installer: pastebin run fjSV9kHj
  7. --install: installer installfile FK87RwJ3
  8.  
  9.  
  10. os.loadAPI("theinsektAPIs/poz3")
  11. os.loadAPI("theinsektAPIs/poz3a")
  12.  
  13.  
  14. --return code: 0=blocked, -1=no_fuel, -2=reached_limit,  1< = found something
  15. function searchDigLoop(ores,limit)
  16.         if(limit==nil) then limit=10000 end
  17.     for i=0, limit do
  18.         local name,direction=inspectOreFUD(ores)
  19.                 if name~=nil then return 1,name,direction end
  20.         poz3a.detectDig("u")
  21.         poz3a.detectDig("d")
  22.         if(not poz3a.detectDigGo2("n",true)) then
  23.             if turtle.getFuelLevel()==0 then
  24.                 return -1--no fuel
  25.             end
  26.             return 0--blocked
  27.         end
  28.     end
  29.         return -2
  30.  
  31. end
  32.  
  33. function inspectOreFUD(ores)
  34.  local name=nil
  35.  local direction=nil
  36.  direction="n"
  37.  name = checkIfOre(ores,direction)
  38.  if name~=nil then return name, direction end
  39.  direction="u"
  40.  name = checkIfOre(ores,direction)
  41.  if name~=nil then return name, direction end
  42.  direction="d"
  43.  name = checkIfOre(ores,direction)
  44.  if name~=nil then return name, direction end
  45.  return nil
  46. end
  47.  
  48. function checkIfOre(ores,direction)
  49.  
  50.  local success,data = poz3.inspect(direction)
  51.  --print("checking: ",direction," ",success)
  52.  if success then
  53.   local name=data["name"]
  54.   --print("found: ",name)
  55.   if name ~= nil and ores[name] ~=nil then
  56.    return name
  57.   end
  58.  end
  59.  return nil
  60. end
  61.  
  62.  
  63.  
  64.  
  65. function parseArguments(args,defaultLimit)
  66.  local limit=nil
  67.  local ores={}
  68.  
  69.  for k,v in ipairs(args) do
  70.  
  71.   local number=tonumber(v)
  72.   if type(number)=="number" then
  73.    if limit~=nil then
  74.     error("Error: only the last argument should be a number")
  75.    end
  76.    limit=number
  77.   else--it should be a string
  78.    ores[v]=true
  79.   end
  80.  end
  81.  
  82.  if limit==nil then limit=defaultLimit end
  83.  
  84.  return limit,ores
  85. end
  86.  
  87.  
  88.  
  89.  
  90. args={...}
  91.  
  92. if(#args<1) then
  93.     print("Usage: orefinder2 <oreName1> <oreName2> ... <limit>")
  94.         print("Will dig 3 high tunnel forward until it finds one of the ores")
  95.     return
  96. end
  97. local ore
  98. local defaultLimit=10000
  99. local limit, ores=parseArguments(args,defaultLimit)
  100.  
  101. for k,v in pairs(ores) do
  102.  print("ore: ",k)
  103. end
  104. print("limit: ",limit)
  105.  
  106. --print("ore: ",inspectOreFUD(ores))
  107.  
  108. res=2
  109. local res,name,direction=searchDigLoop(ores,limit) --commented out
  110.  
  111. --local res=1
  112. --local direction="f"
  113. --local name= checkIfOre(ores,direction)
  114.  
  115.  
  116. print(res)
  117.  
  118. if res>0 then
  119. print("Found!")
  120. print("direction: ",direction)
  121. print("ore: ",name)
  122. end
  123.  
  124. if res==0 then print("Blocked!") end
  125. if res==-1 then print("Out of fuel!") end
  126. if res==-2 then print("At limit!") end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement