Advertisement
towwey

roomdig

Jun 6th, 2024
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | Gaming | 0 0
  1. -- Minecraft Turtle Program to Dig Out a Room
  2.  
  3. -- Function to display the menu and get user input
  4. function displayMenu()
  5.     print("Enter the dimensions of the room to dig out:")
  6.     io.write("Width: ")
  7.     local width = tonumber(io.read())
  8.     io.write("Length: ")
  9.     local length = tonumber(io.read())
  10.     io.write("Height: ")
  11.     local height = tonumber(io.read())
  12.     return width, length, height
  13. end
  14.  
  15. -- Function to dig a line of blocks
  16. function digLine(length)
  17.     for i = 1, length do
  18.         if i < length then
  19.             turtle.dig()
  20.             turtle.forward()
  21.         end
  22.     end
  23. end
  24.  
  25. -- Function to dig a layer of the room
  26. function digLayer(width, length)
  27.     for w = 1, width do
  28.         digLine(length)
  29.         if w < width then
  30.             if w % 2 == 1 then
  31.                 turtle.turnRight()
  32.                 turtle.dig()
  33.                 turtle.forward()
  34.                 turtle.turnRight()
  35.             else
  36.                 turtle.turnLeft()
  37.                 turtle.dig()
  38.                 turtle.forward()
  39.                 turtle.turnLeft()
  40.             end
  41.         end
  42.     end
  43. end
  44.  
  45. -- Function to dig the room
  46. function digRoom(width, length, height)
  47.     for h = 1, height do
  48.         digLayer(width, length)
  49.         if h < height then
  50.             turtle.digDown()
  51.             turtle.down()
  52.             if width % 2 == 0 then
  53.                 -- If width is even, turtle ends up facing the right direction
  54.                 -- but needs to move to the next starting position
  55.                 turtle.turnRight()
  56.                 turtle.turnRight()
  57.                 for i = 1, length - 1 do
  58.                     turtle.forward()
  59.                 end
  60.             end
  61.             -- Turn around to face the right direction for the next layer
  62.             turtle.turnRight()
  63.             turtle.turnRight()
  64.         end
  65.     end
  66. end
  67.  
  68. -- Main program
  69. local width, length, height = displayMenu()
  70. print("Starting to dig a room of size " .. width .. "x" .. length .. "x" .. height)
  71. digRoom(width, length, height)
  72. print("Room dug out successfully!")
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement