Advertisement
smk7758_twitter

CC_farm2.1_2017-03-30

Mar 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. --##################
  2. -- for 27x9 farm
  3. -- Author: smk7758
  4. --##################
  5. -- Please set your farm size.
  6. FARM_SIZE_A = 27
  7. FARM_SIZE_B = 9
  8. --##################
  9. SEED_SLOT = 1
  10.  
  11. function checkForJob()
  12.  print("Start check for job.")
  13.  
  14.  -- # checkFuel #
  15.  FARM_SIZE = FARM_SIZE_A * FARM_SIZE_B
  16.  print("FarmSizeA: " .. FARM_SIZE_A)
  17.  print("FarmSizeB: " .. FARM_SIZE_B)
  18.  print("FarmSize: " .. FARM_SIZE)
  19.  if turtle.getFuelLevel() >= FARM_SIZE then
  20.   print("Fuel: OK")
  21.  else
  22.   FUEL_SUPPLY = FARM_SIZE - turtle.getFuelLevel()
  23.   print("Fuel: Erorr")
  24.   print("Not enough fuel. Please supply fuel: " .. FUEL_SUPPLY .. "\(in coal: " .. FUEL_SUPPLY / 80 .. "\)")
  25.   print("Press any key to stop this program.")
  26.   os.pullEvent("key")
  27.   print("Reboot.")
  28.   os.reboot()
  29.  end
  30.  
  31.  -- # checkSeed #
  32.  SEED_HAVE = 0
  33.  for i=1, 16 do
  34.   turtle.select(i)
  35.   SEED_HAVE = SEED_HAVE + turtle.getItemCount()
  36.  end
  37.  if SEED_HAVE >= FARM_SIZE then
  38.   print("Seed: OK")
  39.  else
  40.   SEED_SUPPLY = FARM_SIZE - SEED_HAVE
  41.   print("Seed: Erorr")
  42.   print("Not enough seed. Please supply seed: " .. SEED_SUPPLY)
  43.   print("Press any key to move this program.")
  44.   os.pullEvent("key")
  45.   print("Continue.")
  46.  end
  47. end
  48.  
  49. -- SLOT Manage
  50. function selectSeed()
  51.  while turtle.getItemCount(SEED_SLOT) == 0 do
  52.   SEED_SLOT = SEED_SLOT + 1
  53.   -- Go to next SLOT
  54.   if SEED_SLOT > 16 then
  55.    os.reboot
  56.   end
  57.  end
  58.  turtle.select(SEED_SLOT)
  59. end
  60.  
  61. function checkSeed()
  62.  if not turtle.detectDown() then
  63.   -- if: nothing down
  64.   selectSeed()
  65.  else
  66.   print("The block is down.")
  67.  end
  68. end
  69.  
  70. -- get and put
  71. function both()
  72.  for i=1, FARM_SIZE_A - 1 do
  73.   -- get
  74.   SUCCESS, BLOCK_DATA = turtle.inspectDown()
  75.   if BLOCK_DATA.metadata == 7 then
  76.    turtle.digDown()
  77.   else
  78.    print("The plant is not glown.")
  79.   end
  80.   -- put
  81.   checkSeed()
  82.   isPut = turtle.placeDown()
  83.   if not isPut then
  84.    print("Can't plant.")
  85.   end
  86.   -- move {
  87.   turtle.forward()
  88.   -- move }
  89.  end
  90.  -- LastLine
  91.  -- get
  92.  SUCCESS, BLOCK_DATA = turtle.inspectDown()
  93.  if BLOCK_DATA.metadata == 7 then
  94.   turtle.digDown()
  95.  else
  96.   print("The plant is not glown.")
  97.  end
  98.  -- put
  99.  checkSeed()
  100.  isPut = turtle.placeDown()
  101.  if isPut then
  102.  SEED_COUNT = SEED_COUNT + 1
  103.  else
  104.   print("Can't plant.")
  105.  end
  106. end
  107.  
  108. function goRight()
  109.  turtle.turnRight()
  110.  turtle.forward()
  111.  turtle.turnRight()
  112. end
  113.  
  114. function goLeft()
  115.  turtle.turnLeft()
  116.  turtle.forward()
  117.  turtle.turnLeft()
  118. end
  119.  
  120. function returnHome()
  121.  turtle.turnRight()
  122.  for i=1, FARM_SIZE_B - 1 do
  123.   turtle.back()
  124.  end
  125.  turtle.turnLeft()
  126.  for i=1, FARM_SIZE_A do
  127.   turtle.back()
  128.  end
  129. end
  130.  
  131. -- #################
  132. -- Main
  133.  
  134. checkForJob()
  135. sleep(1)
  136. print("Start.")
  137. turtle.forward()
  138. both()
  139. goRight()
  140. both()
  141. goLeft()
  142. both()
  143. goRight()
  144. both()
  145. goLeft()
  146. both()
  147. goRight()
  148. both()
  149. goLeft()
  150. both()
  151. goRight()
  152. both()
  153. goLeft()
  154. both()
  155. --##################
  156. --Main_return
  157. returnHome()
  158. print("Complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement