Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin run yBYLz3q4 2 1 2
- -- pastebin run yBYLz3q4 3 3 3
- -- 1: width
- -- 2: height
- -- 3: depth
- args = {...}
- --[[
- MOVEMENT
- ]]
- -- 1: forward
- -- 2: right
- -- 3: backwards
- -- 4: left
- pos = { x = 0, y = 0, z = 0, direction = 1 }
- function move(amount)
- if(pos.direction == 1) then
- pos.z = pos.z + amount
- elseif(pos.direction == 2) then
- pos.x = pos.x + amount
- elseif(pos.direction == 3) then
- pos.z = pos.z + (amount * -1)
- elseif(pos.direction == 4) then
- pos.x = pos.x + (amount * -1)
- end
- end
- function refuel()
- if(turtle.getFuelLevel() < 2) then
- while not(turtle.refuel(1)) do
- print("Out of fuel! Waiting for resupply...")
- end
- end
- end
- function forward()
- refuel()
- if(turtle.forward()) then
- move(1)
- end
- end
- function back()
- refuel()
- if(turtle.back()) then
- move(-1)
- end
- end
- function right()
- refuel()
- if(turtle.turnRight()) then
- pos.direction = pos.direction + 1
- if(pos.direction > 4) then
- pos.direction = 1
- end
- end
- end
- function left()
- refuel()
- if(turtle.turnLeft()) then
- pos.direction = pos.direction - 1
- if(pos.direction < 1) then
- pos.direction = 4
- end
- end
- end
- function down()
- refuel()
- if(turtle.down()) then
- pos.y = pos.y - 1
- end
- end
- function up()
- refuel()
- if(turtle.up()) then
- pos.y = pos.y + 1
- end
- end
- function orient(direction)
- while not(pos.direction == direction) do
- --print("ORIENT: ", pos.direction, " : ", direction, " : ", pos.direction == direction)
- right()
- --[[if(pos.direction > direction and pos.direction > 2) then
- left()
- elseif(pos.direction > direction and pos.direction < 2) then
- right()
- elseif(pos.direction < direction and pos.direction < 2) then
- left()
- else
- right()
- end]]
- end
- end
- function goto(x,y,z)
- while not(pos.x == x and pos.z == z and pos.y == y) do
- if( pos.x > x and not(turtle.detect()) ) then
- orient(4)
- forward()
- elseif( pos.x < x and not(turtle.detect()) ) then
- orient(2)
- forward()
- elseif( pos.z < z and not(turtle.detect()) ) then
- orient(1)
- forward()
- elseif( pos.z > z and not(turtle.detect()) ) then
- orient(3)
- forward()
- elseif( pos.y > y ) then
- down()
- elseif( pos.y < y ) then
- up()
- else
- return
- end
- end
- end
- --[[
- INVENTORY
- ]]
- function getItems()
- stacks = 0
- list = {}
- for i = 1, 16 do
- list[table.getn(list)] = turtle.getItemDetail(i)
- if(not(turtle.getItemDetail(i) == nil)) then
- stacks = stacks + 1
- end
- end
- output = {}
- output["list"] = list
- output["stacks"] = stacks
- return output
- end
- -- Program Logic
- function goRefuel(startX, startZ, startDir)
- goto(1,pos.y,0)
- end
- -- Actual running logic
- function queryTurn(direction, x, w)
- if(direction) then
- right()
- if(x < w -1) then
- turtle.dig()
- forward()
- end
- right()
- else
- left()
- if(x < w -1) then
- turtle.dig()
- forward()
- end
- left()
- end
- end
- function query(w,d,h)
- miningForward = false
- items = getItems()
- for y=0, d - 1 do
- for x=0, w - 1 do
- for z=0, h - 1 do
- -- print("X: ", x, " Y: ", y, " Z: ", z, " W: ", w -1, " H: ", h - 1, " Z: ", z - 1)
- items = getItems()
- while items.stacks == 16 do
- items = getItems()
- print("FULL, returning to drop off")
- goto(0, -1, -1)
- end
- if(z < h - 1) then
- turtle.dig()
- forward()
- end
- end
- if(x < w - 1) then
- queryTurn(miningForward, x, w)
- end
- miningForward = not(miningForward)
- end
- --miningForward = not(miningForward)
- -- print("MINDIR: ", miningForward)
- if( w % 2 > 0 ) then
- left()
- left()
- miningForward = not(miningForward)
- else
- right()
- right()
- right()
- end
- if( y < d - 1) then
- turtle.digDown()
- down()
- end
- end
- end
- -- Setup
- math.randomseed(os.time())
- refuel()
- turtle.up()
- turtle.dig()
- turtle.forward()
- print("X: ", args[1], " Y: ", args[2], " Z: ", args[3])
- query(args[1],args[2],args[3])
- -- goto(pos.x,5,pos.z)
- goto(0,-1,-1)
- orient(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement