Dimencia

Untitled

Mar 22nd, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. -- BaseBuilding Turtle
  2.  
  3. -- Digs out rooms 16x16x4, with a staircase spiraling along the edges
  4. -- Should always be started at the top-left corner of the area to dig...
  5.  
  6. -- No idea how I'm gonna get the stars to work, but the main part should be really easy
  7.  
  8. local startZ = nil
  9. local startX = nil
  10. local startY = nil
  11.  
  12. local cobbleSlot = 1
  13. local firstFuelSlot = 12
  14. local numFuelSlots = 4
  15.  
  16.  
  17. function refuel()
  18. -- Fix the inventory. Let's reserve the last 4 slots all for coal
  19. -- So first, check those 4 slots and if they have noncoal in them, drop them
  20. -- Then check all other slots, and if they have coal, try to put them in those 4 slots
  21. -- Also, discard all cobblestone except slot 1, stack it there
  22.  
  23. -- There are 16 slots, we want 12-16
  24. for i=firstFuelSlot,firstFuelSlot+numFuelSlots do
  25. local data = turtle.getItemDetail(i)
  26. if data ~= nil then
  27. print("Found in slot " .. i .. ": ", data.name)
  28. if data.name ~= "minecraft:coal" then
  29. turtle.select(i)
  30. turtle.drop()
  31. print("Dropping slot " .. i .. " because it's in the coal slot")
  32. end
  33. end
  34. end
  35. -- Now the rest
  36. for i=1,firstFuelSlot-1 do
  37. local data = turtle.getItemDetail(i)
  38. if data ~= nil then
  39. print("Found in slot " .. i .. ": ", data.name)
  40. if data.name == "minecraft:coal" then
  41. -- Just try them all
  42. turtle.select(i)
  43. print("Transferring coal to all fuel slots")
  44. for j=firstFuelSlot,firstFuelSlot+numFuelSlots do
  45. turtle.transferTo(j)
  46. end
  47. elseif data.name == "minecraft:cobblestone" then
  48. -- Try to transfer it to cobbleSlot
  49. turtle.select(i)
  50. turtle.transferTo(cobbleSlot)
  51. -- Drop any remainders
  52. turtle.drop()
  53. end
  54. end
  55. end
  56. -- And lastly, iterate the fuel slots and refuel
  57. for i=firstFuelSlot,firstFuelSlot+numFuelSlots do
  58. turtle.select(i)
  59. turtle.refuel()
  60. end
  61. end
  62.  
  63.  
  64. turtle.select(firstFuelSlot)
  65. turtle.refuel()
  66. turtle.select(cobbleSlot)
  67.  
  68. while(true) do
  69. for z=1,4 do
  70. if startZ then z = startZ startZ = nil end
  71. for x=1,16 do -- Same, always already in the first one
  72. if startX then x = startX startX = nil end
  73. for y=1,16 do -- We're always inside the first one
  74. if startY then y = startY startY = nil end
  75. turtle.dig()
  76. turtle.suck()
  77. turtle.forward()
  78. if not turtle.detectDown() and z == 4 then turtle.placeDown() end -- Make sure the floors are filled in
  79. if not turtle.detectUp() and z == 1 then turtle.placeUp() end -- And the ceilings, which are 1 below the floors
  80. end
  81. -- Reached the end on this side, turn (right/left)...
  82. if x < 16 then
  83. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  84. turtle.dig()
  85. turtle.forward()
  86. if x%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  87. end
  88. -- Ready to iterate again
  89. end
  90. -- We've cleared out a 16x16 area on this level.
  91. -- And we are currently in the last block we broke...
  92. -- So the staircase is to our left. But, for everything except z==1
  93. -- We need to do a 180 and go to the opening
  94. if z > 1 then
  95. turtle.turnLeft()
  96. turtle.turnLeft()
  97. for i=2,z do
  98. turtle.forward()
  99. end
  100. turtle.turnRight()
  101. turtle.forward() -- There should already be nothing there
  102. turtle.turnLeft()
  103. else
  104. turtle.turnLeft()
  105. turtle.dig()
  106. turtle.forward()
  107. turtle.turnLeft()
  108. end
  109. -- Both situations leave us facing to where we need to dig and go down
  110. turtle.dig()
  111. turtle.forward()
  112. turtle.digUp()
  113. turtle.digDown()
  114. turtle.down()
  115. if z < 4 then
  116. -- Figure out how to get back to our starting point.
  117. turtle.turnLeft()
  118. turtle.dig()
  119. turtle.forward()
  120. turtle.turnLeft()
  121. for temp=1,z do -- We will be [z] blocks from the edge on this side
  122. turtle.dig()
  123. turtle.forward()
  124. end
  125. turtle.turnRight()
  126. -- And a full 16 blocks from the next edge inclusive, but, we're inclusive on two points
  127. -- So up to 15
  128. for temp=1,15 do
  129. turtle.dig()
  130. turtle.forward()
  131. end
  132. turtle.turnRight() -- And it's ready to iterate again
  133. end
  134. end
  135. -- We have successfully dug 16x16x4
  136. -- And are on our stairwell area, on the 5th block into the stairwell
  137.  
  138. -- This is a good time to ditch items, since we don't pick things up on the stairwell and they won't fall
  139.  
  140. refuel()
  141.  
  142.  
  143. -- Continue the stairwell down to 8
  144. for temp=5,8 do -- This works for both halves
  145. turtle.dig()
  146. turtle.forward()
  147. turtle.digUp()
  148. turtle.digDown()
  149. turtle.down()
  150. end
  151. -- Get back to the starting position
  152. turtle.turnLeft()
  153. turtle.dig()
  154. turtle.forward()
  155. turtle.turnLeft()
  156. -- We are on block 8 and want to be on block 1
  157. for temp=8,1,-1 do
  158. turtle.dig()
  159. turtle.forward()
  160. end
  161. turtle.turnRight()
  162. -- And we're ready to iterate again
  163. end
Add Comment
Please, Sign In to add comment