andrelisboa1

platprog_mc

Dec 29th, 2023 (edited)
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. function refuel()
  2.     if turtle.getFuelLevel() == 0 then
  3.         turtle.select(1)
  4.         turtle.refuel(1)
  5.         if turtle.getFuelLevel() == 0 then
  6.             error("Out of fuel.")
  7.         end
  8.     end
  9. end
  10.  
  11. function selectFirstFullSlot()
  12.     for i = 2, 16 do
  13.         if turtle.getItemCount(i) > 0 then
  14.             turtle.select(i)
  15.             return
  16.         end
  17.     end
  18. end
  19.  
  20. function placeFirstAvailableBlock()
  21.     selectFirstFullSlot()
  22.     refuel()
  23.     turtle.placeDown()
  24. end
  25.  
  26. -- Program that builds a platform of size w by h
  27. -- and then returns to the starting position.
  28.  
  29. print("Enter width and height:")
  30. local w = 10
  31. local h = 10
  32.  
  33. -- Read the width and height.
  34. w = tonumber(io.read())
  35. h = tonumber(io.read())
  36.  
  37. -- Build the platform.
  38. for i = 1, w do
  39.     for j = 1, h do
  40.         placeFirstAvailableBlock()
  41.         turtle.forward()
  42.     end
  43.     for j = 1, h do
  44.         turtle.back()
  45.     end
  46.     if i < w then
  47.         turtle.turnRight()
  48.         turtle.forward()
  49.         turtle.turnLeft()
  50.     end
  51. end
  52.  
  53. -- Return to the starting position.
  54. turtle.turnLeft()
  55. for i = 1, w do
  56.     turtle.forward()
  57. end
  58. turtle.turnLeft()
  59.  
Advertisement
Add Comment
Please, Sign In to add comment