Advertisement
mathiaas

landfill

May 18th, 2024 (edited)
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. local scriptName = "landfill"
  2. local args = {...}
  3.  
  4. if #args < 3 then
  5.     print("Usage: " .. scriptName .. " <width> <depth> <channel>")
  6.     return
  7. end
  8.  
  9. local WIDTH = tonumber(args[1])
  10. local DEPTH = tonumber(args[2])
  11. local CHANNEL = args[3]
  12.  
  13. dofile("turtle_bot")
  14.  
  15. if not COLOR_CHANNELS[CHANNEL] then
  16.     print(CHANNEL .. " is not a valid color channel.")
  17.     return
  18. end
  19.  
  20.  
  21. local t = TurtleBot.new(scriptName, "North")
  22. t:connect()
  23.  
  24. local function selectBlocks()
  25.     for _, v in pairs(t:inventory()) do
  26.         if v.name ~= ITEMS.enderChest.name then
  27.             turtle.select(v.slot)
  28.             break
  29.         end
  30.     end
  31. end
  32.  
  33.  
  34. local function place(direction)
  35.     local placeFunc = turtle.place
  36.     if direction == "up" then
  37.         placeFunc = turtle.placeUp
  38.     elseif direction == "down" then
  39.         placeFunc = turtle.placeDown
  40.     end
  41.  
  42.     selectBlocks()
  43.     placeFunc()
  44. end
  45.  
  46.  
  47. local function collectBlocks()
  48.     for i=1, 2 do
  49.         t:enderCollect(COLOR_CHANNELS[CHANNEL], 64)
  50.     end
  51.     t:dig("up")
  52. end
  53.  
  54.  
  55. local function fill()
  56.     local y = 0
  57.     while t:down() do
  58.         y = y + 1
  59.         sleep(.5)
  60.     end
  61.  
  62.     for _ = 1, y do
  63.         t:up()
  64.         place("down")
  65.     end
  66. end
  67.  
  68.  
  69. local function traverseRow(steps)
  70.     for _ = 1, steps do
  71.         local inventory = t:inventory()
  72.         if #inventory < 3 then
  73.             collectBlocks()
  74.         end
  75.         fill()
  76.         t:enderRefuel(2000, 5000, ITEMS.charcoal)
  77.         t:dig("up")
  78.         sleep(.5)
  79.         t:forward()
  80.     end
  81. end
  82.  
  83.  
  84. local function main()
  85.     for w = 1, WIDTH do
  86.         traverseRow(DEPTH - 1)
  87.         if w ~= WIDTH then
  88.             if w % 2 == 1 then
  89.                 t:right()
  90.                 traverseRow(1)
  91.                 t:right()
  92.             else
  93.                 t:left()
  94.                 traverseRow(1)
  95.                 t:left()
  96.             end
  97.         end
  98.     end
  99.     if WIDTH % 2 == 0 then
  100.         t:right()
  101.         t:right()
  102.         traverseRow(WIDTH - 1)
  103.         t:right()
  104.         t:right()
  105.     end
  106. end
  107.  
  108. t:execute(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement