psychedelixx

Untitled

Nov 30th, 2021 (edited)
515
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 spiral stairs (downwards left)
  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 0gCW6AMP spiralstairs"
  15.     - type "spiralstairs <size>"
  16. - place stairs in slot 14    
  17. - place chests in slot 15
  18. - place torches in slot 16
  19. ]]
  20. stairsSlot = 14
  21. chestSlot = 15
  22. torchSlot = 16
  23.  
  24. function placeChestIfFull()
  25.     empty = 0      
  26.     for slot = 1, 13 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, 13 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 <size>")
  61.     print("place stairs in slot 14")
  62.     print("place chests in slot 15")
  63.     print("place torches in slot 16")
  64.     error()
  65. end
  66.  
  67. function placeTorchIfNeeded(x)
  68.    
  69.     if (x+1)%13 == 0 and turtle.getItemCount(torchSlot) > 0 then
  70.         oldSlot = turtle.getSelectedSlot()
  71.        
  72.         t.left()
  73.         t.place(torchSlot)
  74.         t.right()
  75.        
  76.         turtle.select(oldSlot)
  77.     end
  78. end
  79.  
  80. print("======== 2016 (c) psychedelixx ========")
  81. print("Let's go!")
  82. print("Mining spiral stairs...")
  83.  
  84. if turtle.getItemCount(chestSlot) == 0 then
  85.     print("")
  86.     print("Warning: no chests found in slot 15. Press enter to continue")
  87.     read()
  88. end
  89.  
  90. if turtle.getItemCount(torchSlot) == 0 then
  91.     print("")
  92.     print("Warning: no torches found in slot 16. Press enter to continue")
  93.     read()
  94. end
  95.  
  96. x = 0
  97. done = false
  98.  
  99. repeat
  100.     t.dig()
  101.     t.forward()
  102.     placeChestIfFull()
  103.    
  104.     t.digUp()
  105.     t.up()    
  106.     t.placeDown(stairsSlot)
  107.    
  108.     x = x + 1
  109.    
  110.     placeTorchIfNeeded(x)
  111.  
  112.     if x%(tonumber(args[1])-1) == 0 then
  113.         t.right()
  114.     end
  115. until done
RAW Paste Data