Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides={[0]="north",[1]="east",[2]="south",[3]="west",[4]="up",[5]="down"}
- local move_vect={[0]=vector.new(0,0,-1),[1]=vector.new(1,0,0),[2]=vector.new(0,0,1),[3]=vector.new(-1,0,0),[4]=vector.new(0,1,0),[5]=vector.new(0,-1,0)}
- local facing=0
- local mining={vector.new(0,0,0)}
- local junkslots={1,2,3,4}
- local function left()
- if turtle.turnLeft() then
- facing=(facing-1)%4
- return true
- else
- return false
- end
- end
- local function right()
- if turtle.turnRight() then
- facing=(facing+1)%4
- return true
- else
- return false
- end
- end
- local function turnTo(side)
- local diff=(side-facing)%4
- local turn=right
- if diff>2 then
- turn=left
- diff=4-diff
- end
- for i=1,diff do
- turn()
- end
- end
- local function compareBlock(side)
- local compare=turtle.compare
- local detect=turtle.detect
- if side<4 then
- turnTo(side)
- elseif side==4 then
- compare=turtle.compareUp
- detect=turtle.detectUp
- else
- compare=turtle.compareDown
- detect=turtle.detectDown
- end
- if detect then
- for i,j in pairs(junkslots) do
- turn.select(j)
- if compare() then return false end
- end
- return true
- else
- return false
- end
- end
- local function scanSides()
- for i,j in pairs(sides) do
- if compareBlock(i) then return i end
- end
- return "no ore"
- end
- local function whichWay(here,there)
- local move=there:sub(here)
- for i,j in ipairs(move_vect)
- if move==j then return i end
- end
- end
- local function go(direction)
- if go<4 then
- turnTo(go)
- turtle.dig()
- return turtle.forward()
- elseif go==4 then
- turtle.digUp()
- return turtle.up()
- else
- turtle.digDown()
- return turtle.down()
- end
- end
- local function notRecursive
- repeat
- local mine=scanSides()
- if move_vect[mine] == nil then --#if no ore found
- if #mining>1 then --#if not at start
- if go(whichWay(mining[#mining],mining[#mining-1]) then --#try to go back 1
- table.remove(mining) --#remove where we came from if successful
- else
- --#something has gone wrong
- end
- end
- else --#if ore found
- if go(mine) then --#dig it and move there
- table.insert(mining,mining[#mining]:add(move_vect[mine])) --#update position
- else
- --#something has gone wrong, possibly gravel, haven't put and handling in for that
- end
- end
- until #mining==1
- end
Advertisement
Add Comment
Please, Sign In to add comment