Advertisement
NortWind

aLivingStone

Mar 27th, 2024 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | Gaming | 0 0
  1. --{program="aLivingStone",version="1.00",date="2024-03-27"}
  2. -- Pastebin "DAFFkuV6"
  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. local function moveLeft()
  15.     turtle.turnLeft()
  16.     turtle.forward()
  17.     turtle.turnRight()
  18. end
  19.  
  20.  
  21. --------------------------------------
  22. ---- put stone into slot 1 -----------
  23. --------------------------------------
  24. local function repackInventory()
  25.     -- store away stuff
  26.     turtle.select(cSlotChest)
  27.     while not turtle.placeUp()         -- put chest on top of turtle
  28.     do
  29.         print("Failed to place chest.")
  30.         os.sleep(1)
  31.     end  
  32.     for i = 2, 15 do                   -- leave stone in cSlotStone
  33.         turtle.select(i)
  34.         turtle.dropUp()                -- put entire stack from slot into chest
  35.     end
  36.     turtle.select(cSlotStone)          -- replace contents
  37.     while turtle.suckUp() do end       -- take all from chest
  38.     turtle.select(cSlotChest)          -- retrieve the chest
  39.     turtle.digUp()
  40.     turtle.select(cSlotStone)
  41. end
  42.  
  43. -- empty slot gets a stone
  44. local function placeStone()
  45.     turtle.select(cSlotStone)
  46.     if not turtle.detect() and turtle.getItemCount(cSlotStone) > 1
  47.     then
  48.         turtle.place()
  49.     end
  50. end
  51.  
  52. -- take care of spot in front of turtle
  53. local function service()
  54.     placeStone()
  55.     turtle.select(cSlotStone)
  56.     if not turtle.compare()            -- slot with living stone gets mined
  57.     then
  58.         turtle.dig()
  59.         placeStone()
  60.     end
  61. end
  62.  
  63. -- take care of one corner, two blocks.
  64. local function oneCorner()
  65.     service()                          -- center block
  66.     moveLeft()
  67.     service()                          -- left side block
  68.     moveLeft()
  69.     turtle.forward()
  70.     turtle.forward()
  71.     turtle.turnRight()
  72. end
  73.  
  74. -- move to next daisy
  75. local function oneRun()
  76.     service()
  77.     moveLeft()
  78.     service()
  79.     turtle.turnLeft()
  80.     turtle.forward()
  81.     turtle.forward()
  82.     turtle.forward()
  83.     turtle.turnRight()
  84.  
  85. end
  86.  
  87. -- do 8 sites of the 32 sites along the cloverleaf path
  88. local function oneQuarter()
  89.     oneCorner()
  90.     oneCorner()
  91.     oneRun()
  92.     oneCorner()
  93. end
  94.  
  95. -- harvest without restock
  96. local function cleanUp()
  97.     for i = 1, 5                       -- may be a partial that needs to be cleaned.
  98.     do
  99.         oneQuarter()
  100.     end
  101. end
  102.  
  103. -- run loop until stone is used up
  104. local function processAll()
  105.     while turtle.getItemCount(cSlotStone) > 8
  106.     do
  107.         while turtle.getItemCount(cSlotStone) > 8  --
  108.         do
  109.             oneQuarter()
  110.         end
  111.         if turtle.getItemCount(cSlotStone) <= 8
  112.         then
  113.             repackInventory()
  114.         end
  115.     end
  116.     cleanUp()
  117. end
  118.  
  119. --------------------------------------
  120. ---- aLivingStone --------------------
  121. --------------------------------------
  122. turtle.select(cSlotStone)
  123. print("+-------------------------------------+")
  124. print("| aLivingStone "..cVer..", by NortWind      |")
  125. print("+-------------------------------------+")
  126. print("|   slot    1: stone     (2 to 64)    |")
  127. print("|   slot 2-14: stone     (0 to 64)    |")
  128. print("|   slot   15: empty                  |")
  129. print("|   slot   16: chest      1           |")
  130. print("| Set-up: Place turtle one square     |")
  131. print("|   from pure daisy, facing daisy.    |")
  132. print("|   Logs will work as well as stone.  |")
  133. print("+-------------------------------------+")
  134. waitEnter("Press enter for layout:")
  135.  
  136. print("+-------------------------------------+")
  137. print("|  .........                          |")
  138. print("|  .### ###.                          |")
  139. print("|  .#P#.#P#.    P = Pure Daisy        |")
  140. print("|  .###.###.                          |")
  141. print("|  .........    . = Clear space       |")
  142. print("|  .###.###.                          |")
  143. print("|  .#P#.#P#.    # = conversion site   |")
  144. print("|  .###.###.                          |")
  145. print("|  ..T......    T = Mining Turtle     |")
  146. print("+-------------------------------------+")
  147. waitEnter("Press enter to start:")
  148.  
  149. if turtle.getItemCount(1)<2 or turtle.getItemCount(15)~=0 or turtle.getItemCount(16)~=1
  150.   then
  151.     print("Inventory is not correct.")
  152.   else
  153.     processAll()
  154.   end
  155.  
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement