Advertisement
NortWind

aWallBuilder

May 12th, 2024 (edited)
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.00 KB | Gaming | 0 0
  1. --{program="aWallBuilder",version="1.00",date="2024-05-12"}
  2. -- Pastebin "6RTnhS9M"
  3. ---------------------------------------
  4. -- Turtle-automated wall builder digger.
  5. -- based on aTreeFarm by Kaikaku
  6. -- v1.04b", date="2018-01-07
  7. -- Pastebin Qn008fPa
  8. ---------------------------------------
  9.  
  10. ---------------------------------------
  11. ---- PARAMETERS -----------------------
  12. ---------------------------------------
  13. local cVer       ="1.00"
  14. local cMaxFuel   = 20000
  15. local cMinFuel   = cMaxFuel * 0.2
  16. local cSleep     = 1         -- os.sleep value used to pace operation
  17. local cSlotStart = 1
  18. local cSlotLast  = 8
  19.  
  20. ---------------------------------------
  21. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  22. ---------------------------------------
  23.  
  24. -- calling with no parameter moves one block forward
  25. local function safeForward(n)
  26.   if n == nil
  27.   then
  28.     turtle.suck()
  29.     while not turtle.forward() do os.sleep(cSleep) end  
  30.   else
  31.     for i = 1, n do
  32.       turtle.suck()
  33.       while not turtle.forward() do os.sleep(cSleep) end    
  34.     end
  35.   end
  36. end
  37.  
  38. local function safeDig()     -- digs forward
  39.   turtle.suck()
  40.   os.sleep(cSleep)
  41.   while turtle.detect()      -- might be digging into multilayered sand or gravel
  42.   do
  43.     turtle.dig()
  44.     os.sleep(cSleep)         -- allow blocks to fall
  45.   end
  46. end
  47.  
  48. local function safeDigDown()
  49.   turtle.suckDown()          -- might be a sapling or stick
  50.   os.sleep(cSleep)
  51.   turtle.digDown()           -- might not be anything to dig
  52. end
  53.  
  54. local function safeDigUp()
  55.   turtle.suckUp()            -- remove drek on top
  56.   os.sleep(cSleep)
  57.   turtle.digUp()             -- might not be anything to dig
  58. end
  59.  
  60. local function turtleReverse()
  61.     turtle.turnRight()
  62.     turtle.turnRight()
  63. end
  64.  
  65. ---------------------------------------
  66. ---- functions ------------------------
  67. ---------------------------------------
  68. -- wait for enter to be pressed
  69. local function waitEnter()
  70.   write("Press enter to start:")
  71.   read()
  72. end
  73.  
  74. -- check fuel in turtle, attempt to replenish if low
  75. local function checkRefuel()  
  76.   if turtle.getFuelLevel() < cMaxFuel * 0.8
  77.   then
  78.       print("Fuel level is low, "..turtle.getFuelLevel()..".")
  79.     print("Use refuel all command.")
  80.       craftFuel()  
  81.   else
  82.     print("Fuel level ok, "..turtle.getFuelLevel()..".")
  83.   end
  84. end
  85.  
  86. local function oneBrick(brickSlot)
  87.     turtle.select(brickSlot)  
  88.     turtle.place()
  89. end
  90.  
  91. ---------------------------------------
  92. ---- Build a slice of the wall --------
  93. ---------------------------------------
  94. local function oneWall()
  95.     turtle.forward()               -- move to next wall and face building
  96.     turtleReverse()
  97.  
  98.     for i = 1, 5                   -- move to top of wall
  99.     do
  100.         turtle.up()
  101.     end
  102.     oneBrick(cSlotStart)           -- walkway
  103.     turtle.turnRight()          
  104.     turtle.forward()
  105.     turtle.turnLeft()
  106.  
  107.     turtle.up()                    -- rampart #1
  108.     turtle.select(cSlotLast + 1)
  109.     turtle.place()                 -- block to place against
  110.     turtle.down()
  111.     turtle.down()
  112.     turtle.forward()
  113.     turtle.turnLeft()    -- orient
  114.     turtle.select(cSlotStart + 1)
  115.     turtle.placeUp()                --rampart
  116.     turtle.turnRight()   -- orient
  117.     turtleReverse()
  118.     turtle.forward()
  119.     turtle.up()
  120.     turtle.turnRight()
  121.     turtle.forward()
  122.     turtle.forward()
  123.     turtle.turnRight()
  124.  
  125.     turtle.up()                        -- rampart #2
  126.     turtle.select(cSlotLast + 2)
  127.     turtle.place()                     -- block to place against
  128.     turtle.down()
  129.     turtle.down()
  130.     turtle.forward()
  131.     turtle.turnRight()   -- orient
  132.     turtle.select(cSlotStart + 2)
  133.     turtle.placeUp()                   --rampart
  134.     turtle.turnLeft()    -- orient
  135.     turtleReverse()
  136.     turtle.forward()
  137.     turtle.up()
  138.     turtle.turnLeft()
  139.     turtle.forward()
  140.     turtle.turnLeft()
  141.  
  142.     for i = cSlotStart + 3, cSlotLast
  143.     do
  144.         turtle.down()
  145.         oneBrick(i)
  146.     end
  147.  
  148.     turtleReverse()                    -- ready for next wall segment
  149. end
  150.  
  151. ---------------------------------------
  152. ---- main -----------------------------
  153. ---------------------------------------
  154. turtle.select(cSlotStart)
  155. term.clear()
  156. term.setCursorPos(1,1)
  157. if turtle.getFuelLevel() < cMinFuel
  158. then
  159.       print("Fuel level "..turtle.getFuelLevel().." is too low.")
  160.     print("Use command \"refuel all\" with 4 stacks of planks.")     -- need to add fuel
  161.     return
  162. end
  163.  
  164. print("+-------------------------------------+")
  165. print("| aWallBuilder "..cVer..", by NortWind        |")
  166. print("+-------------------------------------+")
  167. print("| Materials for auto set-up:          |")
  168. print("|   slot 1:    wood for walkway       |")
  169. print("|   slot 2,3:  starways for ramparts  |")
  170. print("|   slot 4-8:  blocks for walls       |")
  171. print("|   slot 9-10: fence for rampart tops | ")
  172. print("| slot 1 count determines wall lenght |")
  173. print("+-------------------------------------+")
  174. waitEnter()  
  175.  
  176. while turtle.getItemCount(cSlotStart) > 0
  177. do
  178.   oneWall()
  179.   os.sleep(cSleep)
  180. end
  181.  
Tags: minecraft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement