Advertisement
NortWind

aDaisyFarm

Apr 5th, 2024 (edited)
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 KB | Gaming | 0 0
  1. --{program="aDaisyFarm",version="1.00",date="2024-09-27"}
  2. -- Pastebin "CCwjQMZH"
  3.  
  4. local cVer = "1.00"
  5. local cSlotStone =  1
  6. local cSlotChest = 16
  7.  
  8. -- wait for enter to be pressed
  9. local function waitEnter(prompt)
  10.     write(prompt)
  11.     read()
  12. end
  13.  
  14. -- reverse turtle direction
  15. local function aboutFace()
  16.     turtle.turnLeft()
  17.     turtle.turnLeft()
  18. end
  19.  
  20. --------------------------------------
  21. ---- put stone into slot 1 -----------
  22. --------------------------------------
  23. local function repackInventory()
  24.     -- store away stuff
  25.     turtle.select(cSlotChest)
  26.     while not turtle.placeUp()         -- put chest on top of turtle
  27.     do
  28.         print("Failed to place chest.")
  29.         os.sleep(1)
  30.     end  
  31.     for i = 2, 15 do                   -- leave stone in cSlotStone
  32.         turtle.select(i)
  33.         turtle.dropUp()                -- put entire stack from slot into chest
  34.     end
  35.     turtle.select(cSlotStone)          -- replace contents
  36.     while turtle.suckUp() do end       -- take all from chest
  37.     turtle.select(cSlotChest)          -- retrieve the chest
  38.     turtle.digUp()
  39.     turtle.select(cSlotStone)
  40. end
  41.  
  42. -- empty site gets a stone
  43. local function placeStone()
  44.     turtle.select(cSlotStone)
  45.     if not turtle.detect() and turtle.getItemCount(cSlotStone) > 1
  46.     then
  47.         turtle.place()
  48.     end
  49. end
  50.  
  51. -- put a stone where you were
  52. local function oneSite()
  53.     turtle.dig()
  54.     turtle.forward()         -- move off of target
  55.     aboutFace()
  56.     placeStone()             -- place while facing backwards
  57. end
  58.  
  59. -- take care of one corner, place two blocks.
  60. local function oneCorner()
  61.     oneSite()                -- place mid square
  62.     turtle.turnLeft()
  63.     oneSite()                -- place in corner
  64.     aboutFace()
  65.     os.sleep(1)              -- waste a bit of time to let conversion keep up
  66. end
  67.  
  68. -- move to next daisy
  69. local function oneRun()
  70.     oneSite()                -- place mid square
  71.     aboutFace()
  72.     oneSite()                -- place in old daisy corner
  73.     aboutFace()
  74.     turtle.dig()
  75.     turtle.forward()         -- move onto next daisy mid
  76. end
  77.  
  78. -- do 8 sites of the 32 sites along the cloverleaf path
  79. local function oneQuarter()
  80.     oneCorner()
  81.     oneCorner()
  82.     oneRun()
  83.     oneCorner()
  84. end
  85.  
  86. -- harvest without restock
  87. local function cleanUp()
  88.     for i = 1, 5                       -- may be a partial that needs to be cleaned.
  89.     do
  90.         oneQuarter()
  91.     end
  92. end
  93.  
  94. -- run loop until stone is used up
  95. local function processAll()
  96.     turtle.turnLeft()                 -- face initial direction
  97.  
  98.     while turtle.getItemCount(cSlotStone) > 8
  99.     do
  100.         while turtle.getItemCount(cSlotStone) >= 8  --
  101.         do
  102.             oneQuarter()
  103.         end
  104.         if turtle.getItemCount(cSlotStone) < 8
  105.         then
  106.             repackInventory()          -- move more stones into cSlotStone
  107.         end
  108.     end
  109.     cleanUp()
  110. end
  111.  
  112. --------------------------------------
  113. ---- aLivingStone --------------------
  114. --------------------------------------
  115. turtle.select(cSlotStone)
  116. print("+-------------------------------------+") --
  117. print("| aDaisyFarm "..cVer..", by NortWind        |")
  118. print("+-------------------------------------+")
  119. print("|   slot    1: stone     (2 to 64)    |")
  120. print("|   slot 2-14: stone     (0 to 64)    |")
  121. print("|   slot   15: empty                  |")
  122. print("|   slot   16: chest      1           |")
  123. print("| Set-up: Place turtle facing daisy.  |")
  124. print("|   Logs will work as well as stone.  |")
  125. print("+-------------------------------------+")
  126. waitEnter("Press enter for layout:")
  127.  
  128. print("+-------------------------------------+")
  129. print("|   Layout with turtle facing daisy.  |")
  130. print("+-------------------------------------+")
  131. print("|   +-++-+                            |")
  132. print("|   |D||D|     D = Pure Daisy         |")
  133. print("|   +-++-+                            |")
  134. print("|   +-++-+                            |")
  135. print("|   |D||D|                            |")
  136. print("|   -T++-+     T = Mining Turtle      |")
  137. print("+-------------------------------------+")
  138. waitEnter("Press enter to start:")
  139.  
  140. if turtle.getItemCount(1)<2 or turtle.getItemCount(15)~=0 or turtle.getItemCount(16)~=1
  141. then
  142.     print("Inventory is not correct.")
  143. elseif turtle.getFuelLevel() < 1000 then
  144.     print("Fuel level "..turtle.getFuelLevel().." is too low.")
  145. else    
  146.     processAll()
  147. end
  148.  
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement