Advertisement
PinSeventy

Turtle-Made/Run Cobble Farm

Jul 9th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.45 KB | None | 0 0
  1. --******************************--
  2. --Self-Operating Cobbleston Farm--
  3. --******************************--
  4.  
  5. --Variable Declarations
  6. local inventoryFull = false
  7. local chestFull = false
  8. local ready = 0
  9. local runningTotal = 0
  10. local makeFarm = true
  11. local normCobble = 0
  12. local compCobble = 0
  13. local firstDeposit = false
  14.  
  15.  
  16. --Function Declarations
  17.  
  18. function decideToMake()
  19.     print("-------------------------------------")
  20.     print("------- Auto Cobblestone Farm -------")
  21.     print("-------------------------------------")
  22.     print("Are you resuming an operation (y/n)?")
  23.     local userInput = "nil"
  24.     local cont = false
  25.     while cont == false do
  26.         userInput = read()
  27.         if userInput == "y" then
  28.             makeFarm = false
  29.             cont = true
  30.         elseif userInput == "n" then
  31.             makeFarm = true
  32.             cont = true
  33.         else
  34.             print("Invalid input, please try again.")
  35.         end
  36.     end
  37. end
  38.  
  39.  
  40. function setup()    --Prepares to build farm
  41.     print("Place the following in the inventory:")
  42.     print("-------------------------------------")
  43.     print("> 13 misc. building blocks....slot 01")
  44.     print("> 1 lava bucket...............slot 02")
  45.     print("> 1 water bucket..............slot 03")
  46.     print("> 3 chests....................slot 04")
  47.     print("> 1 redstone lamp/torch.......slot 05")
  48.     print("> 1 coal......................slot 06")
  49.     print("Hit  <Enter>  when ready!")
  50.     local input = "nil"
  51.     while input == "nil" do
  52.         input = read()
  53.     end
  54.    
  55.     print("Now ready to construct cobble farm.")
  56. end
  57.  
  58. function fillUp()       --Fill 'er up!
  59.     turtle.select(6)
  60.     turtle.refuel()
  61. end
  62.  
  63. function place(blocks)      --Moves forward & places block beneath
  64.     for i=1,blocks,1 do
  65.         turtle.forward()
  66.         turtle.placeDown()
  67.     end
  68. end
  69.  
  70. function dig(blocks)        --Digs forward; can deal with cobble/sand
  71.     for i=1,blocks,1 do
  72.         while turtle.detect() do
  73.             turtle.dig()
  74.         end
  75.         turtle.forward()
  76.         while turtle.detectUp() do
  77.             turtle.digUp()
  78.         end
  79.     end
  80. end
  81.  
  82. function deposit()      --Deposits cobble when inventory is full
  83.     print("Inventory full.  Depositing cobble.")
  84.     for slot=1,16,1 do
  85.         turtle.select(slot)
  86.         if turtle.getItemCount(slot) ~= 0 then
  87.             chestFull = not turtle.dropDown()
  88.         end
  89.     end
  90.     turtle.select(1)
  91.     print("Cobble Mined: "..runningTotal)
  92. end
  93.  
  94. function compressCobble()       --Compresses cobble from below chest
  95.  
  96.     print("Beginning compression process.")
  97.     turtle.turnRight()
  98.     turtle.turnRight()
  99.     for stack=1,3,1 do
  100.         print("Building recipie for compressed cobble")
  101.         print("Stack "..stack.." of 3.")
  102.         for slot=1,3,1 do
  103.             turtle.select(slot)
  104.             turtle.suckDown()
  105.         end
  106.         for slot=5,7,1 do
  107.             turtle.select(slot)
  108.             turtle.suckDown()
  109.         end
  110.         for slot=9,11,1 do
  111.             turtle.select(slot)
  112.             turtle.suckDown()
  113.         end
  114.  
  115.         turtle.craft(64)
  116.         print("Compressed cobble crafted.")
  117.         print("Depositing compressed cobble.")
  118.         turtle.select(11)
  119.         turtle.drop()
  120.     end
  121.     turtle.turnRight()
  122.     turtle.turnRight()
  123.     print("Resuming mining.")
  124. end
  125.  
  126. function constructFarm()    --Builds farm
  127.     fillUp()
  128.     print("Now building structure.")
  129.  
  130.     --Clearing area
  131.     turtle.turnLeft()
  132.     dig(2)
  133.     turtle.turnRight()
  134.     turtle.turnRight()
  135.     dig(5)
  136.     turtle.turnLeft()
  137.     dig(1)
  138.     turtle.turnLeft()
  139.     dig(5)
  140.     turtle.turnRight()
  141.     dig(1)
  142.     turtle.turnRight()
  143.     dig(5)
  144.     turtle.turnRight()
  145.     dig(2)
  146.     turtle.turnRight()
  147.     dig(3)
  148.     turtle.turnLeft()
  149.     dig(1)
  150.     turtle.turnRight()
  151.     dig(1)
  152.     turtle.back()
  153.     turtle.turnRight()
  154.     turtle.forward()
  155.  
  156.     --Building outline
  157.     turtle.up()
  158.     turtle.select(1)
  159.     turtle.turnLeft()
  160.     place(2)
  161.     turtle.turnRight()
  162.     place(2)
  163.     turtle.turnRight()
  164.     place(5)
  165.     turtle.turnRight()
  166.     place(2)
  167.     turtle.turnRight()
  168.     place(3)
  169.     turtle.turnRight()
  170.     turtle.down()
  171.  
  172.     --Placing non-compressed cobble chest
  173.     turtle.digDown()
  174.     turtle.select(4)
  175.     turtle.placeDown()
  176.  
  177.  
  178.     --Placing Water and then Lava
  179.     turtle.forward()
  180.     turtle.turnRight()
  181.     turtle.forward()
  182.     turtle.digDown()
  183.     turtle.select(3)    --Water
  184.     turtle.place()
  185.     turtle.turnRight()
  186.     turtle.turnRight()
  187.     turtle.forward()
  188.     turtle.select(2)    --Lava
  189.     turtle.place()
  190.     turtle.turnRight()
  191.     turtle.back()
  192.  
  193.     --Placing Chest for compressed cobble
  194.     turtle.back()
  195.     turtle.turnLeft()
  196.     turtle.select(4)
  197.     turtle.place()
  198.     turtle.turnLeft()
  199.     turtle.back()
  200.     turtle.place()
  201.  
  202.     --Placing redstone torch
  203.     turtle.turnRight()
  204.     turtle.up()
  205.     turtle.select(5)
  206.     turtle.place()
  207.     turtle.turnRight()
  208.     turtle.down()
  209.  
  210.     print("Construction complete.")
  211.     print("Now depositing building materials.")
  212.  
  213.     --Depositing all  items
  214.     turtle.turnRight()
  215.     turtle.turnRight()
  216.     for i=1,16,1 do
  217.         turtle.select(i)
  218.         turtle.drop()
  219.     end
  220.     turtle.select(1)
  221.     turtle.turnRight()
  222.     turtle.turnRight()
  223.  
  224.     print("Now beginning mining.")
  225. end
  226.  
  227. function mineCobble()       --As long as Slot 16 is not full, continues to mine Cobble
  228.     rs.setOutput("left", false)
  229.     while chestFull == false do
  230.         turtle.select(1)
  231.         if turtle.dig() then
  232.             runningTotal = runningTotal + 1
  233.         end
  234.         if firstDeposit == false then
  235.             if turtle.getItemCount(16) == 64 then
  236.                 deposit()
  237.                 firstDeposit = true
  238.             end
  239.         elseif firstDeposit == true then
  240.             if turtle.getItemCount(11) == 64 then
  241.                 deposit()
  242.                 compressCobble()
  243.                 firstDeposit = false
  244.             end
  245.         end
  246.     end
  247. end
  248.  
  249. function run()      --All commands are executed in this function
  250.     shell.run("clear")
  251.     decideToMake()
  252.     if makeFarm == true then
  253.         setup()
  254.         constructFarm()
  255.     end
  256.     shell.run("clear")
  257.     print("MINING LOG:")
  258.     print("-------------------------------------")
  259.     mineCobble()
  260.     print("Chest is full!  Done mining.")
  261.     rs.setOutput("left", true)
  262. end
  263.  
  264. --Execution
  265. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement