Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[
- --]
- local args = { ... }
- local top = false
- local length = 40
- if args[1] ~= nil then
- if args[1] == 'top' then
- top = true
- elseif args[1] == 'bottom' then
- top = false
- else
- print('Wrong argument ' .. args[1])
- print('Usage: bridge [top/bottom]')
- do return end
- end
- else
- print('Usage: bridge [top/bottom]')
- print('First 8 slots must be filled with building blocks')
- do return end
- end
- if args[2] ~= nil then
- arg2 = tonumber(args[2])
- if arg2 ~= nil then
- length = arg2
- end
- end
- local placeT =
- {
- ['up'] = turtle.placeUp,
- ['front'] = turtle.place,
- ['down'] = turtle.placeDown,
- }
- local digT =
- {
- ['up'] = turtle.digUp,
- ['front'] = turtle.dig,
- ['down'] = turtle.digDown,
- }
- local cur_slot = 1
- function ensure_blocks()
- if turtle.getItemCount(cur_slot) < 1 then
- for slot_num = 1, 8, 1 do
- if turtle.getItemCount(slot_num) > 0 then
- turtle.select(slot_num)
- cur_slot = slot_num
- return
- end
- end
- print('No blocks for building!')
- do return end
- end
- end
- function replace_block(direction)
- ensure_blocks()
- digT[direction]()
- placeT[direction]()
- end
- function build_one()
- if top then
- replace_block('up')
- else
- replace_block('down')
- end
- turtle.turnLeft()
- replace_block('front')
- turtle.turnRight()
- turtle.turnRight()
- replace_block('front')
- turtle.turnLeft()
- end
- function forward()
- if turtle.getFuelLevel() < 1 then
- print('Not enough fuel!')
- do return end
- end
- ensure_blocks()
- turtle.dig()
- turtle.forward()
- end
- function main()
- print('Start building with top=' .. tostring(top) .. ' and length=' .. tostring(length))
- turtle.select(cur_slot)
- for slot_num = 1, length, 1 do
- forward()
- build_one()
- end
- end
- main()
Add Comment
Please, Sign In to add comment