Advertisement
awesome8digger

ConcreteFarmCCraft

Oct 27th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.46 KB | None | 0 0
  1. blockState1Name = "BetterBuildings:BlockConcreteMix"
  2. blockState2Name = "BetterBuildings:BlockWetConcrete"
  3. blockState3Name = "BetterBuildings:BlockConcrete"
  4.  
  5. function makeOrFarm()
  6.     term.clear()
  7.     term.setCursorPos(1,1)
  8.     print("Press Enter To Make The Concrete Farm, Press RShift To Start/Resume Farming, Press H For How To Use/Help, Or Press Backspace To Cancel")
  9.     while true do
  10.         local event, key = os.pullEvent( "key" ) -- limit os.pullEvent to the 'key' event
  11.        
  12.         if key == keys.enter then -- if the key pressed was 'enter'
  13.             makeFarm()
  14.             break
  15.         end
  16.        
  17.         if key == keys.rightShift then -- if the key pressed was 'rightShift'
  18.             farm()
  19.             break
  20.         end
  21.        
  22.         if key == keys.h then -- if the key pressed was 'h'
  23.             term.clear()
  24.             term.setCursorPos(1,1)
  25.             helpPageOne()
  26.             break
  27.         end
  28.        
  29.         if key == keys.backspace then -- if the key pressed was 'backspace'
  30.             break
  31.         end
  32.     end
  33. end
  34.  
  35. function helpPageOne() -- Displays basic help information to the screen
  36.     print("---------------------------------------")
  37.     print("What Items Go In The Turtle, And Where?")
  38.     print("---------------------------------------")
  39.     print("Slot 1: Fuel Source (DON'T USE LAVA!)")
  40.     print("Slots 2-5: Concrete Mix")
  41.     print("Slots 6-9: Concrete will go here don't put anything here")
  42.     print("")
  43.     print("Press -> For Next Page, Or Backspace To Exit")
  44.     while true do
  45.         local event, key = os.pullEvent( "key" ) -- limit os.pullEvent to the 'key' event
  46.        
  47.         if key == keys.right then -- if the key pressed was '->'
  48.             term.clear()
  49.             term.setCursorPos(1,1)
  50.             helpPageTwo()
  51.             break
  52.         end
  53.        
  54.         if key == keys.backspace then -- if the key pressed was 'backspace'
  55.             term.clear()
  56.             term.setCursorPos(1,1)
  57.             makeOrFarm()
  58.             break
  59.         end
  60.     end
  61. end
  62.  
  63. function helpPageTwo()
  64.     print("For Building The Farm You Need The Following Items Plus The Previous Page")
  65.     print("Slot 14: 1 Water Bucket")
  66.     print("Slot 15: 1 Water Bucket")
  67.     print("Slot 16: 4 Chests (Modded Chests Also Work)")
  68.     print("")
  69.     print("Press -> For Next Page, Or Backspace To Exit")
  70.     while true do
  71.         local event, key = os.pullEvent( "key" ) -- limit os.pullEvent to the 'key' event
  72.        
  73.         if key == keys.right then -- if the key pressed was '->'
  74.             term.clear()
  75.             term.setCursorPos(1,1)
  76.             helpPageThree()
  77.             break
  78.         end
  79.        
  80.         if key == keys.backspace then -- if the key pressed was 'backspace'
  81.             term.clear()
  82.             term.setCursorPos(1,1)
  83.             makeOrFarm()
  84.             break
  85.         end
  86.     end
  87. end
  88.  
  89. function helpPageThree()
  90.     print("------------------------")
  91.     print("What Goes In What Chest?")
  92.     print("------------------------")
  93.     print("Chests Are Numbered From Left To Right Looking At The Backs Of The Chests.")
  94.     print("Chest 1: Concrete (Deposit Chest)")
  95.     print("Chest 2: Concrete Mix (Withdraw)")
  96.     print("Chest 3: Coal (Withdraw Chest)")
  97.     print("")
  98.     print("Press Backspace To Exit")
  99.     while true do
  100.         local event, key = os.pullEvent( "key" ) -- limit os.pullEvent to the 'key' event
  101.        
  102.         if key == keys.backspace then -- if the key pressed was 'backspace'
  103.             term.clear()
  104.             term.setCursorPos(1,1)
  105.             makeOrFarm()
  106.             break
  107.         end
  108.     end
  109. end
  110.  
  111. function makeFarm()
  112.     if turtle.getFuelLevel() < 800 then
  113.         refuel(800)
  114.     end
  115.     forward(1)
  116.     turtle.select(10)
  117.     turtle.digDown()
  118.     digArea(16)
  119.     turtle.turnLeft()
  120.     forward(7)
  121.     turtle.turnLeft()
  122.     forward(7)
  123.     turtle.select(14) -- select the 1st water bucket
  124.     turtle.placeDown() -- place the water bucket down
  125.     forward(1)
  126.     turtle.turnRight()
  127.     forward(1)
  128.     turtle.select(15) -- select the 2nd water bucket
  129.     turtle.placeDown() -- place the water bucket down
  130.     turtle.placeDown() -- grabs the water for the 1st bucket
  131.     os.sleep(3) -- give the water time to refill
  132.     turtle.select(14)
  133.     turtle.placeDown() -- grabs the water for the 2nd bucket
  134.     forward(7)
  135.     turtle.turnLeft()
  136.     forward(7)
  137.     turtle.select(14)
  138.     turtle.placeDown()
  139.     turtle.turnLeft()
  140.     forward(15)
  141.     turtle.select(15)
  142.     turtle.placeDown()
  143.     turtle.turnLeft()
  144.     forward(7)
  145.     turtle.turnLeft()
  146.     forward(7)
  147.     turtle.select(14)
  148.     turtle.placeDown()
  149.     turtle.select(15)
  150.     turtle.placeDown()
  151.     turtle.turnRight()
  152.     forward(1)
  153.     turtle.turnRight()
  154.     forward(7)
  155.     turtle.turnLeft()
  156.     forward(7)
  157.     turtle.select(14)
  158.     turtle.placeDown()
  159.     turtle.turnLeft()
  160.     forward(15)
  161.     turtle.select(15)
  162.     turtle.placeDown()
  163.     turtle.turnRight()
  164.     forward(2)
  165.     turtle.select(16) -- selects the chests
  166.     turtle.place() -- places a large chest for coal
  167.     turtle.back()
  168.     turtle.place()
  169.     turtle.turnRight()
  170.     forward(2)
  171.     turtle.turnLeft()
  172.     forward(1)
  173.     turtle.place() -- places the next large chest for concrete mix
  174.     turtle.back()
  175.     turtle.place()
  176.     turtle.turnRight()
  177.     forward(2)
  178.     turtle.turnLeft()
  179.     forward(1)
  180.     turtle.place() -- places the next large chest for concrete
  181.     turtle.back()
  182.     turtle.place()
  183.     turtle.turnLeft()
  184.     forward(4) -- returns to home
  185.     turtle.turnLeft()
  186.     for s=10, 16 do -- clear all building materials from inventory
  187.         turtle.select(s)
  188.         turtle.drop()
  189.     end
  190.     farm()
  191. end
  192.  
  193. function farm()
  194.     local success, data = turtle.inspect()
  195.    
  196.     if turtle.getFuelLevel() < 800 then
  197.         refuel(800)
  198.     end
  199.    
  200.     if success == true then
  201.         if data.name == BlockState1Name then
  202.             harvestConcrete()
  203.         else
  204.             waitToDry()
  205.         end
  206.     else
  207.         placeConcreteMix()
  208.     end
  209. end
  210.  
  211. function placeConcreteMix()
  212.     turtle.select(1)
  213.     if turtle.getItemSpace(1) >= 0 then -- take fuel from the chest
  214.         turtle.turnLeft()
  215.         turtle.turnLeft()
  216.         turtle.suck(turtle.getItemSpace(1))
  217.         turtle.turnRight()
  218.         turtle.turnRight()
  219.     end
  220.     if turtle.getFuelLevel() < 800 then -- refuel with that fuel
  221.         refuel(800)
  222.     end
  223.     if turtle.getItemSpace(1) >= 0 then -- get more fuel from the chest
  224.         turtle.turnLeft()
  225.         turtle.turnLeft()
  226.         turtle.suck(turtle.getItemSpace(1))
  227.         turtle.turnRight()
  228.         turtle.turnRight()
  229.     end
  230.     turtle.turnLeft()
  231.     forward(2)
  232.     turtle.turnLeft()
  233.     for s=2, 5 do -- get concrete mix from the chest
  234.         turtle.select(s)
  235.         turtle.suck(turtle.getItemSpace(s))
  236.     end
  237.     turtle.turnLeft()
  238.     forward(2)
  239.     turtle.turnLeft()
  240.     turtle.up()
  241.     forward(1)
  242.     turtle.select(2)
  243.     placeTwoLines()
  244.     placeTwoLines()
  245.     turtle.select(3)
  246.     placeTwoLines()
  247.     placeTwoLines()
  248.     turtle.select(4)
  249.     placeTwoLines()
  250.     placeTwoLines()
  251.     turtle.select(5)
  252.     placeTwoLines()
  253.     placeTwoLines()
  254.     turtle.turnLeft()
  255.     turtle.turnLeft()
  256.     forward(1)
  257.     turtle.down()
  258.     turtle.turnLeft()
  259.     forward(16)
  260.     turtle.turnLeft()
  261.     waitToDry()
  262. end
  263.  
  264. function placeTwoLines()
  265.     for p=1, 15 do
  266.         turtle.placeDown()
  267.         forward(1)
  268.     end
  269.     turtle.placeDown()
  270.     turtle.turnLeft()
  271.     forward(1)
  272.     turtle.turnLeft()
  273.     for p=1, 15 do
  274.         turtle.placeDown()
  275.         forward(1)
  276.     end
  277.     turtle.placeDown()
  278.     turtle.turnRight()
  279.     forward(1)
  280.     turtle.turnRight()
  281. end
  282.  
  283. function isBlockDry()
  284.     local success, data = turtle.inspect()
  285.     if success then
  286.         if data.name == blockState3Name then
  287.             return true
  288.         else
  289.             return false
  290.         end
  291.     end
  292.     return false
  293. end
  294.  
  295. function waitToDry()
  296.     while isBlockDry() == false do
  297.         os.sleep(30)
  298.     end
  299.     harvestConcrete()
  300. end
  301.  
  302. function harvestConcrete()
  303.     turtle.select(6)
  304.     for l=1, 16 do
  305.         turtle.dig()
  306.         forward(1)
  307.     end
  308.     turtle.turnLeft()
  309.     turtle.dig()
  310.     forward(1)
  311.     turtle.turnLeft()
  312.     for l=1, 15 do
  313.         turtle.dig()
  314.         forward(1)
  315.     end
  316.     turtle.turnRight()
  317.     turtle.dig()
  318.     forward(1)
  319.     turtle.turnRight()
  320.     for l=1, 15 do
  321.         turtle.dig()
  322.         forward(1)
  323.     end
  324.     turtle.turnLeft()
  325.     turtle.dig()
  326.     forward(1)
  327.     turtle.turnLeft()
  328.     for l=1, 15 do
  329.         turtle.dig()
  330.         forward(1)
  331.     end
  332.     turtle.select(7)
  333.     turtle.turnRight()
  334.     turtle.dig()
  335.     forward(1)
  336.     turtle.turnRight()
  337.    
  338.     harvestSection()
  339.    
  340.     turtle.select(8)
  341.     turtle.turnRight()
  342.     turtle.dig()
  343.     forward(1)
  344.     turtle.turnRight()
  345.    
  346.     harvestSection()
  347.    
  348.     turtle.select(9)
  349.     turtle.turnRight()
  350.     turtle.dig()
  351.     forward(1)
  352.     turtle.turnRight()
  353.    
  354.     harvestSection()
  355.    
  356.     forward(1)
  357.     turtle.turnLeft() -- head back to home
  358.     forward(11)
  359.     turtle.turnRight()
  360.     for s=6, 9 do -- deposit all concrete
  361.         turtle.select(s)
  362.         turtle.drop()
  363.     end
  364.     turtle.turnLeft()
  365.     forward(4)
  366.     turtle.turnLeft()
  367.     farm()
  368. end
  369.  
  370. function harvestSection()
  371.     for l=1, 15 do
  372.         turtle.dig()
  373.         forward(1)
  374.     end
  375.     turtle.turnLeft()
  376.     turtle.dig()
  377.     forward(1)
  378.     turtle.turnLeft()
  379.     for l=1, 15 do
  380.         turtle.dig()
  381.         forward(1)
  382.     end
  383.     turtle.turnRight()
  384.     turtle.dig()
  385.     forward(1)
  386.     turtle.turnRight()
  387.     for l=1, 15 do
  388.         turtle.dig()
  389.         forward(1)
  390.     end
  391.     turtle.turnLeft()
  392.     turtle.dig()
  393.     forward(1)
  394.     turtle.turnLeft()
  395.     for l=1, 15 do
  396.         turtle.dig()
  397.         forward(1)
  398.     end
  399. end
  400.  
  401. function digLine(l)
  402.     for d=1, l do
  403.         turtle.dig()
  404.         forward(1)
  405.         turtle.digDown()
  406.         turtle.drop()
  407.     end
  408. end
  409.  
  410. function digArea(a)
  411.     for f=1, a do
  412.         digLine(a-1)
  413.         if f == a then
  414.             return
  415.         elseif f % 2 == 1 then
  416.             turtle.turnLeft()
  417.             digLine(1)
  418.             turtle.turnLeft()
  419.         elseif f % 2 == 0 then
  420.             turtle.turnRight()
  421.             digLine(1)
  422.             turtle.turnRight()
  423.         end
  424.     end
  425. end
  426.  
  427. function forward(l)
  428.     for i=1, l do
  429.         for f=1, 3 do
  430.             if turtle.forward() == false then
  431.                 if turtle.getFuelLevel() <= 0 then
  432.                     refuel(300)
  433.                 else
  434.                     turtle.dig()
  435.                     turtle.attack()
  436.                     term.clear()
  437.                     term.setCursorPos(1,1)
  438.                     print("Unable to move forward... Is something in the way?")
  439.                 end
  440.             else
  441.                 break
  442.             end
  443.         end
  444.     end
  445. end
  446.  
  447. function refuel(l)
  448.     turtle.select(1)
  449.     while turtle.getFuelLevel() < l do
  450.         if turtle.getItemCount(1) > 0 then
  451.             turtle.refuel(1)
  452.         else
  453.             term.clear()
  454.             term.setCursorPos(1,1)
  455.             print("Please insert more fuel into slot 1...")
  456.             os.sleep(10)
  457.         end
  458.     end
  459. end
  460.  
  461. makeOrFarm()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement