Tander

Untitled

Feb 25th, 2025
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1.  --[
  2.  
  3. --]
  4. local args = { ... }
  5. local top = false
  6. local length = 40
  7. if args[1] ~= nil then
  8.     if args[1] == 'top' then
  9.         top = true
  10.     elseif args[1] == 'bottom' then
  11.         top = false
  12.     else
  13.         print('Wrong argument ' .. args[1])
  14.         print('Usage: bridge [top/bottom]')
  15.         do return end
  16.     end
  17. else
  18.     print('Usage: bridge [top/bottom]')
  19.     print('First 8 slots must be filled with building blocks')
  20.     do return end
  21. end
  22.  
  23. if args[2] ~= nil then
  24.     arg2 = tonumber(args[2])
  25.     if arg2 ~= nil then
  26.         length = arg2
  27.     end
  28. end
  29.    
  30.  
  31. local placeT =
  32. {
  33.     ['up'] = turtle.placeUp,
  34.     ['front'] = turtle.place,
  35.     ['down'] = turtle.placeDown,
  36. }
  37.  
  38. local digT =
  39. {
  40.     ['up'] = turtle.digUp,
  41.     ['front'] = turtle.dig,
  42.     ['down'] = turtle.digDown,
  43. }
  44.  
  45. local cur_slot = 1
  46.  
  47. function ensure_blocks()
  48.     if turtle.getItemCount(cur_slot) < 1 then
  49.         for slot_num = 1, 8, 1 do
  50.             if turtle.getItemCount(slot_num) > 0 then
  51.                 turtle.select(slot_num)
  52.                 cur_slot = slot_num
  53.                 return
  54.             end
  55.         end
  56.         print('No blocks for building!')
  57.         do return end
  58.     end
  59. end
  60.  
  61.  
  62. function replace_block(direction)
  63.     ensure_blocks()
  64.     digT[direction]()
  65.     placeT[direction]()
  66. end
  67.  
  68. function build_one()
  69.     if top then
  70.         replace_block('up')
  71.     else
  72.         replace_block('down')
  73.     end
  74.     turtle.turnLeft()
  75.     replace_block('front')
  76.     turtle.turnRight()
  77.     turtle.turnRight()
  78.     replace_block('front')
  79.     turtle.turnLeft()
  80. end
  81.  
  82. function forward()
  83.     if turtle.getFuelLevel() < 1 then
  84.         print('Not enough fuel!')
  85.         do return end
  86.     end
  87.     ensure_blocks()
  88.     turtle.dig()
  89.     turtle.forward()
  90. end
  91.  
  92.  
  93. function main()
  94.     print('Start building with top=' .. tostring(top) .. ' and length=' .. tostring(length))
  95.     turtle.select(cur_slot)
  96.     for slot_num = 1, length, 1 do
  97.         forward()
  98.         build_one()
  99.     end
  100. end
  101.  
  102. main()
  103.  
Add Comment
Please, Sign In to add comment