Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --should dig forward until finds the wanted ores
- --not finished
- --experimental
- --pastebin get iiRX8ezE theinsekt/orefinder2
- --get installer: pastebin run fjSV9kHj
- --install: installer installfile FK87RwJ3
- os.loadAPI("theinsektAPIs/poz3")
- os.loadAPI("theinsektAPIs/poz3a")
- --return code: 0=blocked, -1=no_fuel, -2=reached_limit, 1< = found something
- function searchDigLoop(ores,limit)
- if(limit==nil) then limit=10000 end
- for i=0, limit do
- local name,direction=inspectOreFUD(ores)
- if name~=nil then return 1,name,direction end
- poz3a.detectDig("u")
- poz3a.detectDig("d")
- if(not poz3a.detectDigGo2("n",true)) then
- if turtle.getFuelLevel()==0 then
- return -1--no fuel
- end
- return 0--blocked
- end
- end
- return -2
- end
- function inspectOreFUD(ores)
- local name=nil
- local direction=nil
- direction="n"
- name = checkIfOre(ores,direction)
- if name~=nil then return name, direction end
- direction="u"
- name = checkIfOre(ores,direction)
- if name~=nil then return name, direction end
- direction="d"
- name = checkIfOre(ores,direction)
- if name~=nil then return name, direction end
- return nil
- end
- function checkIfOre(ores,direction)
- local success,data = poz3.inspect(direction)
- --print("checking: ",direction," ",success)
- if success then
- local name=data["name"]
- --print("found: ",name)
- if name ~= nil and ores[name] ~=nil then
- return name
- end
- end
- return nil
- end
- function parseArguments(args,defaultLimit)
- local limit=nil
- local ores={}
- for k,v in ipairs(args) do
- local number=tonumber(v)
- if type(number)=="number" then
- if limit~=nil then
- error("Error: only the last argument should be a number")
- end
- limit=number
- else--it should be a string
- ores[v]=true
- end
- end
- if limit==nil then limit=defaultLimit end
- return limit,ores
- end
- args={...}
- if(#args<1) then
- print("Usage: orefinder2 <oreName1> <oreName2> ... <limit>")
- print("Will dig 3 high tunnel forward until it finds one of the ores")
- return
- end
- local ore
- local defaultLimit=10000
- local limit, ores=parseArguments(args,defaultLimit)
- for k,v in pairs(ores) do
- print("ore: ",k)
- end
- print("limit: ",limit)
- --print("ore: ",inspectOreFUD(ores))
- res=2
- local res,name,direction=searchDigLoop(ores,limit) --commented out
- --local res=1
- --local direction="f"
- --local name= checkIfOre(ores,direction)
- print(res)
- if res>0 then
- print("Found!")
- print("direction: ",direction)
- print("ore: ",name)
- end
- if res==0 then print("Blocked!") end
- if res==-1 then print("Out of fuel!") end
- if res==-2 then print("At limit!") end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement