Advertisement
mathiaas

mason

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