Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- depth, width, height, h_offset = ...
- if depth == nil then
- depth = 2
- end
- if width == nil then
- width = 2
- end
- if height == nil then
- height = 2
- end
- if h_offset == nil then
- h_offset = 0
- end
- width_dir = 'r'
- timesHorizontal = depth*width
- turnAgain = false
- height_dir = 'u'
- height_traveled = 0
- facing = 'f'
- num_moves = 0
- function refuel()
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- end
- function forward()
- if height_traveled < 2 then
- while not turtle.forward() do --this loop runs as long as turtle.forward() return false
- turtle.dig() --dig its way through
- sleep(0.8) --i think this is falling time of gravel
- end
- else
- turtle.dig()
- turtle.forward()
- end
- num_moves = num_moves + 1
- if turtle.getFuelLevel() < 500 then
- refuel()
- end
- end
- function right()
- turtle.turnRight()
- if facing == 'f' then
- facing = 'r'
- elseif facing == 'r' then
- facing = 'b'
- elseif facing == 'b' then
- facing = 'l'
- elseif facing == 'l' then
- facing = 'f'
- end
- end
- function left()
- turtle.turnLeft()
- if facing == 'f' then
- facing = 'l'
- elseif facing == 'l' then
- facing = 'b'
- elseif facing == 'b' then
- facing = 'r'
- elseif facing == 'r' then
- facing = 'f'
- end
- end
- function horizontal(start)
- for i = start, timesHorizontal do
- forward()
- if turnAgain == true then
- if width_dir == 'r' then
- right()
- width_dir = 'l'
- else
- left()
- width_dir = 'r'
- end
- turnAgain = false
- end
- if i % depth == 0 and i < timesHorizontal then
- if width_dir == 'r' then
- right()
- else
- left()
- end
- turnAgain = true
- end
- end
- end
- function vertical()
- for i = 1, height do
- height_traveled = height_traveled + 1
- if i == 1 then
- horizontal(1)
- else
- right()
- right()
- turtle.digDown()
- turtle.down()
- horizontal(2)
- end
- end
- end
- function home()
- start = 1
- for i = 2, height do
- turtle.up()
- end
- if facing == 'f' then
- left()
- for i = 2, width do
- forward()
- end
- left()
- elseif facing == 'r' then
- left()
- left()
- for i = 2, width do
- forward()
- end
- left()
- elseif facing == 'l' then
- left()
- elseif facing == 'b' then
- start = 2
- end
- for i = start, depth do
- forward()
- end
- end
- function drop()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function init()
- refuel()
- vertical()
- -- home()
- -- drop()
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement