Advertisement
mathiaas

excavator

May 18th, 2024 (edited)
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local scriptName = "excavator"
  2. local args = {...}
  3.  
  4. if #args < 4 then
  5.     print("Usage: " .. scriptName .. " <width> <depth> <height> <start>")
  6.     print("<start> should be 'top' or 'bottom'")
  7.     return
  8. end
  9.  
  10. dofile("turtle_bot")
  11. local t = TurtleBot.new(scriptName, "North")
  12. t:connect()
  13.  
  14.  
  15. local WIDTH = tonumber(args[1])
  16. local DEPTH = tonumber(args[2])
  17. local HEIGHT = tonumber(args[3])
  18. local START = args[4]
  19.  
  20. if not inList(START, {"top", "bottom"}) then
  21.     print("Invalid start option. Use 'top' or 'bottom'.")
  22.     return
  23. end
  24.  
  25.  
  26. local function mineRow(steps)
  27.     for _ = 1, steps do
  28.         while turtle.detect() do
  29.             t:dig()
  30.  
  31.             local inventory = t:inventory()
  32.             if #inventory > 10 then
  33.                 t:enderDeposit(COLOR_CHANNELS.miningDepot, {})
  34.                 t:dig("up")
  35.             end
  36.  
  37.             t:enderRefuel(2000, 5000, ITEMS.charcoal)
  38.             t:dig("up")
  39.             sleep(.5)
  40.         end
  41.         t:forward()
  42.     end
  43. end
  44.  
  45.  
  46. local function mineLayer(width, depth)
  47.     for w = 1, width do
  48.         mineRow(depth - 1)
  49.         if w ~= width then
  50.             if w % 2 == 1 then
  51.                 t:right()
  52.                 mineRow(1)
  53.                 t:right()
  54.             else
  55.                 t:left()
  56.                 mineRow(1)
  57.                 t:left()
  58.             end
  59.         end
  60.     end
  61.     if width % 2 == 0 then
  62.         t:right()
  63.         t:right()
  64.         mineRow(width - 1)
  65.         t:right()
  66.         t:right()
  67.     end
  68. end
  69.  
  70.  
  71. local function main()
  72.     for h = 1, HEIGHT do
  73.         mineLayer(WIDTH, DEPTH)
  74.         if h ~= HEIGHT then
  75.             if START == "top" then
  76.                 t:dig("down")
  77.                 t:down()
  78.             else
  79.                 t:dig("up")
  80.                 t:up()
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. t:execute(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement