Advertisement
Ichabod2032

Minecraft - Turtle Seed Farmer

Apr 8th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | None | 0 0
  1. --2013: Ichabod Clay (Ichabod2032)
  2. --This script farms an 8 wide by 12 long area of wheat farmland. It discards all wheat
  3. -- and keeps seeds for chicken breeding. Currently, due to an overabundance of skeleton bones,
  4. -- it uses bonemeal on each and every patch of seeds. Also, due to this turtle being used in a Mindcrack
  5. -- mod pack, it is refueled at a charging station prior to farm activities and needs no fuel during farming.
  6. --
  7. --2 chests must be placed for the turtle to take bonemeal from and deposit seeds to. Diagram for chest placement
  8. -- is as follows: .=farmland  0=chest  ^=turtle
  9. -- ........
  10. -- ........
  11. -- ........
  12. -- ........
  13. -- ........
  14. -- ........
  15. -- ........
  16. -- ........
  17. -- ........
  18. -- ........
  19. -- ........
  20. -- ........
  21. --0       ^0
  22.  
  23. --Chests and turtle must be positioned at the player's eye level (2 blocks above the farmland blocks) with the
  24. -- turtle starting facing toward the farm. Left chest will contain seeds after farming is done. Right chest
  25. -- must be preloaded with (lots) of bonemeal. Turtle must have at least 1 bonemeal, 1 wheat, and 1 seed in the
  26. -- 1st, 2nd, and 3rd slots respectively when starting. Turtle assumes a starting farmland with freshly planted
  27. -- crops.
  28. -----
  29. -----
  30. --Let's start this off right. Select the first slot of the turtle and get ready for an adventure!
  31. turtle.select(1);
  32. local curSlot = 1;
  33.  
  34. --Function: getBonemeal()
  35. --Grabs exactly 2 stacks of bonemeal from the bonemeal chest.
  36. --Returns: nothing
  37. local function getBonemeal()
  38.   if curSlot ~= 1 then
  39.     turtle.select(1);
  40.     curSlot = 1;
  41.   end
  42.  
  43.   turtle.turnRight();
  44.   turtle.suck();
  45.   turtle.suck();
  46.   turtle.select(5);
  47.   curSlot = 5;
  48.   turtle.drop();
  49.   turtle.select(4);
  50.   curSlot = 4;
  51.   turtle.turnLeft();
  52. end
  53.  
  54. --Helper Function: checkCount(itemType)
  55. --Checks the item count and type of the currently selected slot. If the item is not 'itemType', then
  56. -- it switches the slot to base slot for that type (slot 1 for bonemeal, 3 for seeds);
  57. --Returns: nothing
  58. local function checkCount(itemType)
  59.   local itemSlot = 1;
  60.   if itemType == "seeds" then
  61.     itemSlot = 3;
  62.   end
  63.  
  64.   if (not turtle.compareTo(itemSlot)) and (curSlot ~= itemSlot) then
  65.     turtle.select(itemSlot);
  66.     curSlot = itemSlot;
  67.   end
  68. end
  69.  
  70. --Function: boneNHarvest()
  71. --Bonemeals and harvests all crops then ends with the turtle next to the seed chest
  72. --Returns: nothing
  73. local function boneNHarvest()
  74.   turtle.forward();
  75.   if curSlot ~= 4 then
  76.     turtle.select(4);
  77.     curSlot = 4;
  78.   end
  79.  
  80.   for i=1, 4 do
  81.     for x=1, 12 do
  82.       checkCount("bonemeal");
  83.       turtle.placeDown();
  84.       turtle.digDown();
  85.       if x ~= 12 then
  86.         turtle.forward();
  87.       end
  88.     end
  89.  
  90.     turtle.turnLeft();
  91.     turtle.forward();
  92.     turtle.turnLeft();
  93.  
  94.     for x=1, 12 do
  95.       checkCount("bonemeal");
  96.       turtle.placeDown();
  97.       turtle.digDown();
  98.       if x ~= 12 then
  99.         turtle.forward();
  100.       end
  101.     end
  102.    
  103.     turtle.turnRight();
  104.     turtle.forward();
  105.     turtle.turnRight();
  106.   end
  107. end
  108.  
  109. --Helper Function: getItemTable(string dumpKind)
  110. --Creates a table of numbers that correspond to the slots that contain an item of type 'dumpKind' (wheat or seeds)
  111. --Returns: A table! yay!
  112. local function getItemTable(dumpKind)
  113.   local itemTable = {3};
  114.   local baseSlot = 3;
  115.   local tableCounter = 2;
  116.  
  117.   if dumpKind == "wheat" then
  118.     itemTable[1] = 2;
  119.     baseSlot = 2;
  120.   end
  121.  
  122.   for i=4, 13 do
  123.     turtle.select(i);
  124.     curSlot = i;
  125.  
  126.     if turtle.compareTo(baseSlot) then
  127.       itemTable[tableCounter] = curSlot;
  128.       tableCounter = tableCounter + 1;
  129.     end
  130.   end
  131.  
  132.   return itemTable;
  133. end
  134.  
  135. --Helper Function: dump(string dumpKind)
  136. --Dumps all items in turtle's inventory based on the type of 'dumpKind' (wheat or seeds)
  137. --Returns: nothing
  138. local function dump(dumpKind)
  139.   local tempTable = getItemTable(dumpKind);
  140.   local kindSlot = 3;
  141.   if dumpKind == "wheat" then
  142.     kindSlot = 2;
  143.   end
  144.  
  145.   for i=1, #tempTable do
  146.     turtle.select(tempTable[i]);
  147.     curSlot = tempTable[i];
  148.  
  149.     if curSlot == kindSlot then
  150.       turtle.drop(turtle.getItemCount(curSlot) - 1);
  151.     else
  152.       turtle.drop();
  153.     end
  154.  
  155.   end
  156. end
  157.  
  158. --Helper Function: takeSeeds()
  159. --Takes exactly 94 seeds from chest.
  160. --Returns: nothing
  161. local function takeSeeds()
  162.   turtle.select(3);
  163.   curSlot = 3;
  164.   turtle.suck();
  165.   turtle.suck();
  166.   turtle.select(5);
  167.   curSlot = 5;
  168.   turtle.drop();
  169.   turtle.select(4);
  170.   curSlot = 4;
  171.   turtle.drop(32);
  172. end
  173.  
  174. --Function: dumpNDeposit()
  175. --Dumps all seeds into chest and discards all wheat. Takes enough seeds for planting and sets turtle up for planting
  176. --Returns: nothing
  177. local function dumpNDeposit()
  178.   turtle.turnLeft();
  179.   dump("wheat");
  180.   turtle.turnLeft();
  181.   dump("seeds");
  182.   takeSeeds();
  183.   turtle.turnLeft();
  184.   turtle.forward();
  185.   turtle.turnLeft();
  186. end
  187.  
  188. --Function: plantSeeds()
  189. --Plants seeds!
  190. --Returns: nothing
  191. local function plantSeeds()
  192.   if curSlot ~= 4 then
  193.     turtle.select(4);
  194.     curSlot = 4;
  195.   end
  196.  
  197.   for i=1, 4 do
  198.     for x=1, 12 do
  199.       checkCount("seeds");
  200.       turtle.placeDown();
  201.       if x ~= 12 then
  202.         turtle.forward();
  203.       end
  204.     end
  205.  
  206.     turtle.turnRight();
  207.     turtle.forward();
  208.     turtle.turnRight();
  209.  
  210.     for x=1, 12 do
  211.       checkCount("seeds");
  212.       turtle.placeDown();
  213.       if x ~= 12 then
  214.         turtle.forward();
  215.       end
  216.     end
  217.    
  218.     turtle.turnLeft();
  219.     turtle.forward();
  220.     turtle.turnLeft();
  221.   end
  222. end
  223.  
  224. --Function: returnToStart()
  225. --Returns to starting position after planting new seeds.
  226. --Returns: nothing
  227. local function returnToStart()
  228.   turtle.turnLeft();
  229.   turtle.forward();
  230.   turtle.turnLeft();
  231.   turtle.forward();
  232.   turtle.turnLeft();
  233.   turtle.turnLeft();
  234. end
  235.  
  236. --Function: isMealCountOK()
  237. --Checks count of bonemeal just before setting off.
  238. --Returns: False if bonemeal count is below 96, True otherwise.
  239. local function isMealCountOK()
  240.   if (turtle.getItemCount(1) == 64) and (turtle.getItemCount(4) >= 34) then
  241.     return true;
  242.   end
  243.   return false;
  244. end
  245.  
  246. -- End function definitions
  247. -- Start main program
  248.  
  249. while true do
  250.   getBonemeal();
  251.     if not isMealCountOK() then
  252.       print("Stopping due to low bonemeal count");
  253.       break;
  254.     end
  255.   boneNHarvest();
  256.   dumpNDeposit();
  257.   plantSeeds();
  258.   returnToStart();
  259. end
  260.  
  261. print("All farmed out!");
  262. return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement