Schmille

Computercraft Netherbridge

Jan 21st, 2023 (edited)
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | Gaming | 0 0
  1. -- Minecraft Computercraft Netherbridge Program
  2. -- Creates a 2 x 2 roofed tunnel with 1 block railing
  3. fuelLimit = 500
  4. args = {...}
  5.  
  6. function forceDig(detectFunc, digFunc)
  7.     while detectFunc() do
  8.         digFunc()
  9.     end
  10. end
  11.  
  12. function fDig()
  13.     forceDig(turtle.detect, turtle.dig)
  14. end
  15.  
  16. function fDigUp()
  17.     forceDig(turtle.detectUp, turtle.digUp)
  18. end
  19.  
  20. function fDigDown()
  21.     forceDig(turtle.detectDown, turtle.digDown)
  22. end
  23.  
  24. function forcePlacement(detectFunc, digFunc, placeFunc)
  25.     forceDig(detectFunc, digFunc)
  26.  
  27.     if turtle.getItemCount(turtle.getSelectedSlot()) > 0 and placeFunc() then
  28.         return
  29.     end
  30.  
  31.     for i = 1, 16, 1 do
  32.         turtle.select(i)
  33.         if turtle.getItemCount(i) > 0 then
  34.             if placeFunc() then
  35.                 return
  36.             end
  37.         end
  38.     end
  39.     error("No more placeable blocks")
  40. end
  41.  
  42. function fPlace()
  43.     forcePlacement(turtle.detect, turtle.dig, turtle.place)
  44. end
  45.  
  46. function fPlaceUp()
  47.     forcePlacement(turtle.detectUp, turtle.digUp, turtle.placeUp)
  48. end
  49.  
  50. function fPlaceDown()
  51.     forcePlacement(turtle.detectDown, turtle.digDown, turtle.placeDown)
  52. end
  53.  
  54. function fuel()
  55.     local selectedSlot = turtle.getSelectedSlot()
  56.     if turtle.getFuelLevel() <= fuelLimit then
  57.         for i = 1, 16, 1 do
  58.             turtle.select(i)
  59.             turtle.refuel(64)
  60.             if turtle.getFuelLevel() > fuelLimit then
  61.                 break
  62.             end
  63.         end
  64.     end
  65.     turtle.select(selectedSlot)
  66. end
  67.  
  68. function main()
  69.     -- Mine left corridor
  70.     turtle.turnLeft()
  71.     fDig()
  72.     turtle.forward()
  73.  
  74.     fPlaceDown()
  75.     fPlace()
  76.  
  77.     fDigUp()
  78.     turtle.up()
  79.     fPlaceUp()
  80.  
  81.     -- Back To starting position
  82.     turtle.down()
  83.     turtle.back()
  84.     turtle.turnRight()
  85.  
  86.     -- Mine main block
  87.     fPlaceDown()
  88.     turtle.turnRight()
  89.     fPlace()
  90.     turtle.turnLeft()
  91.     fDigUp()
  92.     turtle.up()
  93.     fPlaceUp()
  94.     turtle.down()
  95.     fDig()
  96.     turtle.forward()
  97.     fuel()
  98. end
  99.  
  100. -- Arg 1 can be used to set tunnel length
  101. if #(args) < 1 then
  102.     while true do
  103.         main()
  104.     end
  105. else
  106.     for i=0,args[1],1 do
  107.         main()
  108.     end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment