Advertisement
Guest User

farm

a guest
Feb 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. local length = 27
  2. local width = 27
  3. local seedType = "potato"
  4. local goods = "potato"
  5. local timeOut = 600
  6. local holding = 64
  7. local fuel = {"coal","log"}
  8.    
  9. function forward()
  10.  if not turtle.forward() then
  11.   turtle.attack()
  12.   turtle.dig()
  13.   forward()
  14.  end
  15. end
  16. function backward()
  17.  if not turtle.back() then
  18.   turtle.turnLeft()
  19.   turtle.turnLeft()
  20.   forward()
  21.   turtle.turnRight()
  22.   turtle.turnRight()
  23.  end
  24. end
  25. function isGrown()
  26.  s,d =  turtle.inspectDown()
  27.  if s then
  28.   if d.state.age == 7 then
  29.     return 2
  30.   else
  31.    return 1
  32.   end
  33.  else
  34.   return 0
  35.  end
  36. end
  37. function selectSeed()
  38.  for slot=1,16 do
  39.   turtle.select(tonumber(slot))
  40.   if turtle.getItemCount() ~= 0 then
  41.    if turtle.getItemDetail().name == "minecraft:"..seedType then
  42.     return
  43.    end
  44.   end
  45.  end
  46. end
  47. function farmCrop()
  48.  g = isGrown()
  49.  if g==2 then
  50.   turtle.digDown()
  51.   selectSeed()
  52.   turtle.placeDown()
  53.  elseif g==0 then
  54.   selectSeed()
  55.   turtle.placeDown()
  56.  end
  57. end
  58. function farmLine()
  59.  farmCrop()
  60.  for i=2,length do
  61.   forward()
  62.   farmCrop()
  63.  end
  64.  for i=2,length do
  65.   backward()
  66.  end
  67. end
  68. function farmDoubleLine()
  69.  farmCrop()
  70.  for i=2,length do
  71.   forward()
  72.   farmCrop()
  73.  end
  74.  turtle.turnLeft()
  75.  forward()
  76.  turtle.turnRight()
  77.  farmCrop()
  78.  for i=2,length do
  79.   backward()
  80.   farmCrop()
  81.  end
  82. end
  83. function farmAll()
  84.  x = 1
  85.  while true do
  86.   if width-x == 0 then
  87.    farmLine()
  88.    x=x+1
  89.    break
  90.   else
  91.    farmDoubleLine()
  92.    x=x+2
  93.   end
  94.   turtle.turnLeft()
  95.   forward()
  96.   turtle.turnRight()
  97.  end
  98.  turtle.turnLeft()
  99.  for i=2,width do
  100.    backward()
  101.  end
  102.  turtle.turnRight()
  103. end
  104. function selectGood()
  105.  for slot=1,16 do
  106.   turtle.select(slot)
  107.   if turtle.getItemCount() ~= 0 then
  108.    if turtle.getItemDetail().name == "minecraft:"..goods then
  109.     return true
  110.    end
  111.   end
  112.  end
  113.  return false
  114. end
  115. function storeGoods()
  116.  backward()
  117.  h = 0
  118.  while selectGood() do
  119.   h = h + turtle.getItemCount()
  120.   if h > holding then
  121.    turtle.dropDown()
  122.   end
  123.  end
  124.  print("goods stored")
  125.  forward()
  126. end
  127. local fuelPerRotation = width*length + length +width +2
  128. function isFuel()
  129.  if turtle.getItemCount() ~= 0 then
  130.   item = turtle.getItemDetail().name
  131.   for i=1,#fuel do
  132.    if item == "minecraft:"..fuel[i] then
  133.     return true
  134.    end
  135.   end
  136.  end
  137.  return false
  138. end
  139. function refuel()
  140.  if turtle.getFuelLevel() > fuelPerRotation then
  141.   return true
  142.  end
  143.  print("refueling")
  144.  for slot=1,16 do
  145.   turtle.select(slot)
  146.   if isFuel() then
  147.    c = turtle.getItemCount()
  148.    for i=1,c do
  149.     if turtle.getFuelLevel() > fuelPerRotation then
  150.      return
  151.     end
  152.     turtle.refuel(1)
  153.    end
  154.   end
  155.  end
  156.  out = turtle.getFuelLevel() > fuelPerRotation
  157.  return out
  158. end
  159. --MAINLOOP--
  160. while true do
  161.  refuel()
  162.  farmAll()
  163.  storeGoods()
  164.  print("waiting")
  165.  sleep(timeOut)
  166. end
  167.  
  168. print("FarmingProgram-Ended")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement