psychedelixx

Minecraft Turtle: Spiral stairs

Nov 20th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. 2016 (c) psychedelixx
  3. Minecraft Spiralstairs (robust)
  4. 2016-10-14
  5.  
  6. Mines a 3x3 spiral stairs (downwards)
  7.  
  8. Robust API:
  9. http://computercraft.info/wiki/Robust_Turtle_API
  10.  
  11. Usage:
  12.     - use turtle and type "label set <name>"
  13.       (to give your turtle an unique name so it remembers its programs)
  14.     - type "pastebin get hYABpV27 spiralstairs"
  15.     - type "spiralstairs <removeCenter 0|1>"
  16. - place chests in slot 15
  17. - place torches in slot 16
  18. ]]
  19.  
  20. chestSlot = 15
  21. torchSlot = 16
  22. centerRemoved = false
  23.  
  24. function placeChestIfFull()
  25.     empty = 0      
  26.     for slot = 1, 14 do
  27.         if turtle.getItemCount(slot) == 0 then
  28.             empty = 1
  29.             break
  30.         end
  31.     end
  32.  
  33.     --[[ if turtle is full, turn around, place chest, move items into it, turn around and continue ]]--
  34.     if empty == 0 then    
  35.         t.up()
  36.         t.turnAround()
  37.         t.dig()
  38.  
  39.         if turtle.getItemCount(chestSlot) == 0 then
  40.             print("Please put chests in slot 15 and press enter to continue")
  41.             read()
  42.         end
  43.    
  44.         turtle.select(chestSlot)
  45.         turtle.place()
  46.        
  47.         for slot = 1, 14 do
  48.             turtle.select(slot)
  49.             turtle.drop()
  50.         end
  51.            
  52.         t.turnAround()
  53.         t.down()
  54.     end
  55. end
  56.  
  57. local args = { ... }
  58.  
  59. if #args ~= 1 then
  60.     print("Usage: spiralstairs <removeCenter 0|1>")
  61.     print("place chests in slot 15")
  62.     print("place torches in slot 16")
  63.     error()
  64. end
  65.  
  66. if tonumber(args[1]) == 1 then
  67.     removeCenter = true
  68. else
  69.     removeCenter = false
  70. end
  71.  
  72. function removeCenterIfNeeded(x)
  73.    
  74.     if x%2 == 1 and removeCenter and not centerRemoved then
  75.         t.left()
  76.         t.dig()
  77.         t.right()
  78.        
  79.         centerRemoved = true
  80.     end
  81. end
  82.  
  83. function placeTorchIfNeeded(x)
  84.    
  85.     if (x+1)%14 == 0 and turtle.getItemCount(torchSlot) > 0 then
  86.         oldSlot = turtle.getSelectedSlot()
  87.        
  88.         t.right()
  89.         t.place(torchSlot)
  90.         t.left()
  91.        
  92.         turtle.select(oldSlot)
  93.     end
  94. end
  95.  
  96. print("======== 2016 (c) psychedelixx ========")
  97. print("Let's go!")
  98. print("Mining spiral stairs...")
  99.  
  100. if turtle.getItemCount(chestSlot) == 0 then
  101.     print("")
  102.     print("Warning: no chests found in slot 15. Press enter to continue")
  103.     read()
  104. end
  105.  
  106. if turtle.getItemCount(torchSlot) == 0 then
  107.     print("")
  108.     print("Warning: no torches found in slot 16. Press enter to continue")
  109.     read()
  110. end
  111.  
  112. x = 0
  113. done = false
  114.  
  115. t.digDown()
  116. t.down()
  117.  
  118. repeat
  119.     t.dig()
  120.     placeChestIfFull()
  121.     t.forward()
  122.     x = x + 1
  123.    
  124.     removeCenterIfNeeded(x)
  125.    
  126.     placeTorchIfNeeded(x)
  127.  
  128.     if x%2 == 0 then
  129.         t.left()
  130.     end
  131.    
  132.     if x%7 == 0 then
  133.         turtle.place()
  134.        
  135.         if turtle.detectDown() then
  136.             if t.digDown() then
  137.                 placeChestIfFull()
  138.             end
  139.         end
  140.         if not t.down() then
  141.             done = true
  142.         end
  143.        
  144.         centerRemoved = false
  145.     end
  146. until done
Advertisement
Add Comment
Please, Sign In to add comment