RandomShovel

[CC][Semi-Automated] Farm v.2.1

Jun 5th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.14 KB | None | 0 0
  1. --[[  Tables  ]]--
  2.  
  3. local tArgs = { ... }
  4.  
  5.  
  6. --[[  Functions  ]]--
  7.  
  8. function cs()
  9.  term.clear()
  10.  term.setCursorPos(1, 1)
  11. end
  12.  
  13. function returnToStart(psize)
  14.  if psize % 2 == 1 then
  15.   turtle.turnLeft()
  16.   for i=1, psize-1 do
  17.    turtle.forward()
  18.   end
  19.   turtle.turnLeft()
  20.   for i=1, psize-1 do
  21.    turtle.forward()
  22.   end
  23.   turtle.turnRight()
  24.   turtle.turnRight()
  25.  else
  26.   turtle.turnRight()
  27.   for i=1, psize-1 do
  28.    turtle.forward()
  29.   end
  30.   turtle.turnRight()
  31.  end
  32. end
  33.  
  34. function centerT(text)
  35.  local mx, my = term.getSize()
  36.  local cx, cy = term.getCursorPos()
  37.  term.setCursorPos(math.floor((mx-string.len(text))/2), cy)
  38.  print(text)
  39. end
  40.  
  41. function checkFuel()
  42.  if turtle.getFuelLevel() < 50 then
  43.   cs()
  44.   print("I needz somez foodz bruh!")
  45.   repeat
  46.    for i=1, 16 do
  47.     if turtle.getItemCount(i) > 0 then
  48.      if turtle.refuel(1) then
  49.       repeat
  50.        turtle.refuel(1)
  51.       until turtle.getFuelLevel > 100
  52.      end
  53.     end
  54.    end
  55.   until turtle.getFuelLevel > 100
  56.  end
  57. end
  58.  
  59. function plantRow(psize, pslot)
  60.  for i=1, psize do
  61.   turtle.select(pslot)
  62.   if turtle.getItemCount(pslot) == 1 then
  63.    cs()
  64.    print("It appears I am running out of supplies...")
  65.    print("I will now scan my inventory for more supplies...")
  66.    textutils.slowPrint("Scanning...")
  67.    
  68.    for a=1, 16 do
  69.     if a ~= pslot then
  70.      if turtle.getItemCount(a) > 0 then
  71.       turtle.select(a)
  72.       if turtle.compareTo(pslot) then
  73.        turtle.transferTo(pslot)
  74.        turtle.select(pslot)
  75.        break
  76.       end
  77.      end
  78.     end
  79.    end
  80.   end
  81.   turtle.placeDown()
  82.   if i < psize then
  83.    turtle.forward()
  84.   end
  85.  end
  86. end
  87.  
  88. function plantFarm(psize, pslot)
  89.  for i=1, psize do
  90.   plantRow(psize, pslot)
  91.   if bit.band(i,1) == 1 and i < psize then
  92.    turtle.turnRight()
  93.    turtle.forward()
  94.    turtle.turnRight()
  95.   elseif bit.band(i,1) == 0 and i < psize then
  96.    turtle.turnLeft()
  97.    turtle.forward()
  98.    turtle.turnLeft()
  99.   end
  100.  end
  101. end
  102.  
  103. function tillRow(psize)
  104.  for i=1, psize do
  105.   turtle.digDown()
  106.   if i < psize then
  107.    turtle.forward()
  108.   end
  109.  end
  110. end
  111.  
  112. function tillFarm(psize)
  113.  for i=1, psize do
  114.   tillRow(psize)
  115.   if bit.band(i,1) == 1 and i < psize then
  116.    turtle.turnRight()
  117.    turtle.forward()
  118.    turtle.turnRight()
  119.   elseif bit.band(i,1) == 0 and i < psize then
  120.    turtle.turnLeft()
  121.    turtle.forward()
  122.    turtle.turnLeft()
  123.   end
  124.  end
  125. end
  126.  
  127. function harvestRow(psize)
  128.  for i=1, psize do
  129.   turtle.digDown()
  130.   if i < psize then
  131.    turtle.forward()
  132.   end
  133.  end
  134. end
  135.  
  136. function harvestFarm(psize)
  137.  for i=1, psize do
  138.   harvestRow(psize)
  139.   if bit.band(i,1) == 1 and i < psize then
  140.    turtle.turnRight()
  141.    turtle.forward()
  142.    turtle.turnRight()
  143.   elseif bit.band(i, 1) == 0 and i < psize then
  144.    turtle.turnLeft()
  145.    turtle.forward()
  146.    turtle.turnLeft()
  147.   end
  148.  end
  149. end
  150.  
  151. function menu()
  152.  cs()
  153.  centerT("What is the size of this farm?")
  154.  centerT("Please remember, this is size^2")
  155.  write("> ")
  156.  local psize = tonumber(read())
  157.  cs()
  158.  centerT("Which slot shall be my supply slot?")
  159.  write("> ")
  160.  local pslot = tonumber(read())
  161.  cs()
  162.  centerT("The last thing I need is:")
  163.  print("Am I 1 block above the soil?")
  164.  print("(Y/N)")
  165.  write("> ")
  166.  local soil = read()
  167.  
  168.  if string.lower(soil) == "n" then
  169.   turtle.up()
  170.  end
  171.  
  172.  cs()
  173.  print("Thank you for giving me my necessary information!")
  174.  sleep(2)
  175.  while true do
  176.   cs()
  177.   centerT("Random Industrial Farming Inc.")
  178.   centerT("Made by RandomShovel")
  179.   centerT("-------")
  180.   term.setCursorPos(1, 5)
  181.   print("1) Till Farm")
  182.   print("2) Plant Crops")
  183.   print("3) Harvest Crops")
  184.   print("4) Exit")
  185.   print("")
  186.   write("> ")
  187.   local response = tonumber(read())  
  188.   if response == 1 then
  189.    tillFarm(psize)
  190.    returnToStart(psize)
  191.   elseif response == 2 then
  192.    plantFarm(psize, pslot)
  193.    returnToStart(psize)
  194.   elseif response == 3 then
  195.    harvestFarm(psize)
  196.    turtle.turnLeft()
  197.    turtle.turnLeft()
  198.    plantFarm(psize, pslot)
  199.    turtle.turnLeft()
  200.    turtle.turnLeft()
  201.   elseif response == 4 then
  202.    cs()
  203.    textutils.slowPrint("Exiting FarmSimulator 2014...")
  204.    sleep(1)
  205.    cs()
  206.    break
  207.   end
  208.   sleep(0.1)
  209.  end
  210. end
  211.  
  212. --[[  Main  ]]--
  213.  
  214. menu()
Advertisement
Add Comment
Please, Sign In to add comment