Advertisement
Guest User

farm

a guest
Dec 17th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.92 KB | None | 0 0
  1. local blockX = 1
  2. local blocksX = 16
  3. local blocksXSkip = {1,8,9,10}
  4. local blockY = 1
  5. local blocksY = 37
  6.  
  7. local slotsRef = {14,15,16}
  8. local slotsRefDump = {14}
  9. local slotsSeed = {15,16}
  10. local slotsDump = {5,6,7,8,9,10,11,12,13}
  11.  
  12. local dirAway = true
  13.  
  14. local function organizeSpace()
  15.  for countA=1,13 do
  16.   if turtle.getItemCount(countA) > 0 and turtle.getItemCount(countA) < 64 then
  17.    turtle.select(countA)
  18.    for countB=1,countA do
  19.     turtle.transferTo(countB)
  20.    end
  21.   end
  22.  end
  23. end
  24.  
  25. local function checkSpace()
  26.  local spaceAvail = 0
  27.  for count=1,16 do
  28.   spaceAvail = spaceAvail + turtle.getItemSpace(count)
  29.  end
  30.  return spaceAvail
  31. end
  32.  
  33. local function moveForward()
  34.  if turtle.getFuelLevel() > 0 then
  35.   if turtle.forward() == false then
  36.    os.sleep(5)
  37.    moveForward()
  38.   end
  39.  else
  40.   while turtle.getFuelLevel() == 0 do
  41.     os.sleep(30)
  42.   end
  43.  
  44.   if turtle.forward() == false then
  45.    os.sleep(5)
  46.    moveForward()
  47.   end
  48.  end
  49. end
  50.  
  51. local function isBlockPlantable()
  52.  local isPlantable = true
  53.  for i=1,#blocksXSkip do
  54.   if blockX==blocksXSkip[i] then
  55.    isPlantable=false
  56.   end
  57.  end
  58.  return isPlantable
  59. end
  60.  
  61. local function selectSlot(slotRef)
  62.  turtle.select(slotRef)
  63.  for count=13,1,-1 do
  64.   if turtle.compareTo(count) == true then
  65.    turtle.select(count)
  66.    return
  67.   end
  68.  end
  69. end
  70.  
  71. local function plantItem()
  72.  if isBlockPlantable(blockX) then
  73.   turtle.digDown()
  74.   if blockX % 2 == 0 then
  75.    selectSlot(slotsSeed[1])
  76.   else
  77.    selectSlot(slotsSeed[2])
  78.   end
  79.   turtle.placeDown()
  80.  end
  81. end
  82.  
  83. local function turnRight()
  84.  turtle.turnRight()
  85.  moveForward()
  86.  turtle.turnRight()
  87. end
  88.  
  89. local function turnLeft()
  90.  turtle.turnLeft()
  91.  moveForward()
  92.  turtle.turnLeft()
  93. end
  94.  
  95. local function dropItems()
  96.  turtle.down()
  97.  for i=1,#slotsRefDump do
  98.   turtle.select(slotsRefDump[i])
  99.   for j=1,13 do
  100.    if turtle.compareTo(j) then
  101.     turtle.select(j)
  102.     turtle.dropDown()
  103.    end
  104.   end
  105.  end
  106.  
  107.  organizeSpace()
  108.  
  109.  for i=1,#slotsDump do
  110.   turtle.select(slotsDump[i])
  111.   turtle.dropDown()
  112.  end
  113.  turtle.up()
  114. end
  115.  
  116. local function returnToStart()
  117.  if (blockX == 1) and (blockY == 1) then
  118.   dropItems()
  119.  else
  120.   if dirAway == true then
  121.    if blockX > 2 then
  122.     turtle.turnRight()
  123.     turtle.turnRight()
  124.     for count=1,blockX - 1 do
  125.      moveForward()
  126.     end
  127.    end
  128.  
  129.    if blockY > 1 then
  130.     turtle.turnRight()
  131.     for count=1,blockY - 1 do
  132.      moveForward()
  133.     end
  134.     turtle.turnRight()
  135.    else
  136.     turtle.turnRight()
  137.     turtle.turnRight()
  138.    end
  139.   else
  140.    if blockX > 2 then
  141.     for count=1,blockX - 1 do
  142.      moveForward()
  143.     end
  144.    end
  145.  
  146.    if blockY > 1 then
  147.     turtle.turnRight()
  148.     for count=1,blockY - 1 do
  149.      moveForward()
  150.     end
  151.     turtle.turnRight()
  152.    else
  153.     turtle.turnRight()
  154.     turtle.turnRight()
  155.    end
  156.   end
  157.   dropItems()
  158.  end
  159. end
  160.  
  161. local function returnToBlock()
  162.  if blockY==1 then
  163.   if blockX > 1 then
  164.    for count=1, blockX - 1 do
  165.     moveForward()
  166.    end
  167.   end
  168.  else
  169.   turtle.turnRight()
  170.   for count=1, blockY - 1 do
  171.    moveForward()
  172.   end
  173.   turtle.turnLeft()
  174.  
  175.   if blockX > 1 then
  176.    for count=1, blockX - 1 do
  177.     moveForward()
  178.    end
  179.  
  180.    if dirAway == false then
  181.     turtle.turnRight()
  182.     turtle.turnRight()
  183.    end
  184.   end
  185.  end
  186. end
  187.  
  188. local function start()
  189.  for countY=1, blocksY do
  190.   blockY = countY
  191.   for countX=1, blocksX - 1 do
  192.    local spaceAvail = checkSpace()
  193.    if spaceAvail < 128 then
  194.     returnToStart()
  195.     returnToBlock()
  196.    end
  197.  
  198.    plantItem()
  199.  
  200.    moveForward()
  201.  
  202.    if dirAway == true then
  203.     blockX = blockX + 1
  204.    else
  205.     blockX = blockX - 1
  206.    end
  207.   end
  208.  
  209.   plantItem()
  210.  
  211.   if blockY == blocksY then
  212.    returnToStart()
  213.   else
  214.    organizeSpace()
  215.  
  216.    if dirAway == true then
  217.     turnRight()
  218.     dirAway = false  
  219.    else
  220.     turnLeft()
  221.     dirAway = true
  222.    end
  223.   end
  224.  end
  225. end
  226.  
  227. while true == true do
  228.  blockX = 1
  229.  blockY = 1
  230.  dirAway = true
  231.  
  232.  start()
  233.  os.sleep(60*30)
  234. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement