daily pastebin goal
50%
SHARE
TWEET

Untitled

EphemeralKap Dec 7th, 2017 59 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. local status = 0
  2. -- 0 = Returning, 1 = Maintenance, 2 = Farming, 3 = Critical
  3. local n = 0
  4. local j = 0
  5.  
  6. --todo fix return, fix farm
  7.  
  8. -- Refuels the turtle if fuel levels are low
  9. function Refuel() --fin?
  10.     print("Refueling..")
  11.     turtle.select(1)
  12.     if not turtle.refuel(3) then
  13.         print("Fuel reserves low.. Returning home")
  14.         status = 0
  15.     end
  16. end
  17.  
  18. -- Grabs fuel from fuelchest above the turtle, drops anything in slot 1 if it's not coal
  19. function GrabFuel() --fin?
  20.     if turtle.getItemCount(1) > 0 then
  21.         if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  22.             print("That's not fuel.. Ew!")
  23.             turtle.select(1)
  24.             turtle.drop()
  25.         end
  26.     end
  27.     if turtle.getItemCount(1) < 16 and status == 1 then
  28.         print("Grabbing Fuel..")
  29.         turtle.select(1)
  30.         turtle.suckUp()
  31.     end
  32. end
  33.  
  34. -- Makes sure it has seeds in inventory, then dumps everything else
  35. function DropOff() --fin?
  36.     for i = 2, 16 do
  37.         if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name ~= "minecraft:seed" then
  38.             turtle.select(i)
  39.             turtle.dropDown()
  40.         end
  41.     end
  42.    
  43.     turtle.turnLeft()
  44.    
  45.     for i = 2, 16 do
  46.         if turtle.getItemCount(i) > 0 then
  47.             turtle.select(i)
  48.             turtle.drop()
  49.         end
  50.     end
  51.    
  52.     turtle.suck()
  53.     turtle.suck()
  54.     turtle.turnRight()
  55. end
  56.  
  57. -- Inspects the block infront, above or below the turtle.
  58. function GetBlock(side) -- fin
  59.     if side == 1 then
  60.         local s, d = turtle.inspect()
  61.         if s then return d else return false end
  62.     elseif side == 2 then
  63.         local s, d = turtle.inspectUp()
  64.         if s then return d else return false end
  65.     elseif side == 3 then
  66.         local s, d = turtle.inspectDown()
  67.         if s then return d else return false end
  68.     end
  69. end
  70.  
  71. -- Returns the turtle to the station
  72. function Return() --fin?
  73.     if status == 0 then
  74.         local front = GetBlock(1)
  75.         if front and front.name == "immersiveengineering:metal_decoration1" then
  76.             turtle.turnLeft()
  77.         elseif front and front.name == "minecraft:hardened_clay" then
  78.                 turtle.turnLeft()
  79.                 turtle.forward()
  80.         elseif front and front.name == "minecraft:chest" then
  81.             turtle.turnLeft()
  82.             turtle.forward()
  83.             turtle.turnRight()
  84.             turtle.forward()
  85.             turtle.turnLeft()
  86.             turtle.down()
  87.             turtle.back()
  88.             status = 1
  89.         else
  90.             turtle.forward()
  91.         end
  92.     end
  93. end
  94.  
  95. function GetSeedCount()
  96.     return turtle.getItemCount(2), turtle.getItemCount(3)
  97. end
  98.  
  99. function Replant()
  100.     local seed1, seed2 = GetSeedCount()
  101.     for i=2,3 do
  102.         if seed1 > 0 then
  103.             print("Found seed1")
  104.             turtle.select(2)
  105.             turtle.placeDown()
  106.         elseif seed2 > 0 then
  107.             print("Found seed2")
  108.             turtle.select(3)
  109.             turtle.placeDown()
  110.         end
  111.     end
  112. end
  113.  
  114. -- Checks if plant is ready to be harvested, or if soil needs retilling/replanting
  115. function CheckPlant()
  116.     print("Inspecting farmland..")
  117.     local under = GetBlock(3)
  118.     if not under then
  119.         print("Retilling..")
  120.         turtle.digDown()
  121.         Replant()
  122.     elseif under.name == "minecraft:wheat" and under.metadata == 7 then
  123.         print("Found mature plant, harvesting..")
  124.         turtle.placeDown()
  125.         turtle.sleep(0.1)
  126.         turtle.suckDown()
  127.     end
  128. end
  129.  
  130. function Farm()
  131.     -- Are we full yet?
  132.     local front = GetBlock(1)
  133.     if turtle.getItemCount(16) > 0 then
  134.         status = 0
  135.     elseif not front then
  136.         turtle.forward()
  137.         CheckPlant()
  138.     elseif front.name == "immersiveengineering:metal_decoration1"
  139.                             or front.name == "minecraft:hardened_clay" then
  140.         CheckPlant()
  141.         if j == 0 then
  142.             j = 1
  143.             turtle.turnLeft()
  144.             turtle.forward()
  145.             CheckPlant()
  146.             turtle.turnLeft()
  147.         elseif j == 1 then
  148.             j = 0
  149.             turtle.turnRight()
  150.             if front.name == "immersiveengineering:metal_decoration1"
  151.                                 and front.name == "minecraft:hardened_clay" then
  152.                 status = 0
  153.                 n = n + 1
  154.             else
  155.                 turtle.forward()
  156.                 CheckPlant()
  157.                 turtle.turnRight()
  158.             end
  159.         end
  160.     end
  161. end
  162.  
  163. -- Main Loop
  164. while true do
  165.     if turtle.getFuelLevel() < 10 then
  166.         Refuel()
  167.     end
  168.     if status == 0 then
  169.         print("Finding home..")
  170.         Return()
  171.     end
  172.     if status == 1 then
  173.         print("Refueling.. Storing.. Polishing..")
  174.         DropOff()
  175.         GrabFuel()
  176.         print("Maintenance completed!")
  177.         turtle.forward()
  178.         turtle.up()
  179.         status = 2
  180.         if n % 2 == 0 and n > 0 then
  181.             for i = 1,5 do
  182.                 print("Waiting: " .. 5-i .. " seconds for the plants to grow..")
  183.                 sleep(1)
  184.             end
  185.             n = 1
  186.         end
  187.     end
  188.     if status == 2 then
  189.         print("Farming..")
  190.         Farm()
  191.     end
  192. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top