Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --2013: Ichabod Clay (Ichabod2032)
- --This script farms an 8 wide by 12 long area of wheat farmland. It discards all wheat
- -- and keeps seeds for chicken breeding. Currently, due to an overabundance of skeleton bones,
- -- it uses bonemeal on each and every patch of seeds. Also, due to this turtle being used in a Mindcrack
- -- mod pack, it is refueled at a charging station prior to farm activities and needs no fuel during farming.
- --
- --2 chests must be placed for the turtle to take bonemeal from and deposit seeds to. Diagram for chest placement
- -- is as follows: .=farmland 0=chest ^=turtle
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- -- ........
- --0 ^0
- --Chests and turtle must be positioned at the player's eye level (2 blocks above the farmland blocks) with the
- -- turtle starting facing toward the farm. Left chest will contain seeds after farming is done. Right chest
- -- must be preloaded with (lots) of bonemeal. Turtle must have at least 1 bonemeal, 1 wheat, and 1 seed in the
- -- 1st, 2nd, and 3rd slots respectively when starting. Turtle assumes a starting farmland with freshly planted
- -- crops.
- -----
- -----
- --Let's start this off right. Select the first slot of the turtle and get ready for an adventure!
- turtle.select(1);
- local curSlot = 1;
- --Function: getBonemeal()
- --Grabs exactly 2 stacks of bonemeal from the bonemeal chest.
- --Returns: nothing
- local function getBonemeal()
- if curSlot ~= 1 then
- turtle.select(1);
- curSlot = 1;
- end
- turtle.turnRight();
- turtle.suck();
- turtle.suck();
- turtle.select(5);
- curSlot = 5;
- turtle.drop();
- turtle.select(4);
- curSlot = 4;
- turtle.turnLeft();
- end
- --Helper Function: checkCount(itemType)
- --Checks the item count and type of the currently selected slot. If the item is not 'itemType', then
- -- it switches the slot to base slot for that type (slot 1 for bonemeal, 3 for seeds);
- --Returns: nothing
- local function checkCount(itemType)
- local itemSlot = 1;
- if itemType == "seeds" then
- itemSlot = 3;
- end
- if (not turtle.compareTo(itemSlot)) and (curSlot ~= itemSlot) then
- turtle.select(itemSlot);
- curSlot = itemSlot;
- end
- end
- --Function: boneNHarvest()
- --Bonemeals and harvests all crops then ends with the turtle next to the seed chest
- --Returns: nothing
- local function boneNHarvest()
- turtle.forward();
- if curSlot ~= 4 then
- turtle.select(4);
- curSlot = 4;
- end
- for i=1, 4 do
- for x=1, 12 do
- checkCount("bonemeal");
- turtle.placeDown();
- turtle.digDown();
- if x ~= 12 then
- turtle.forward();
- end
- end
- turtle.turnLeft();
- turtle.forward();
- turtle.turnLeft();
- for x=1, 12 do
- checkCount("bonemeal");
- turtle.placeDown();
- turtle.digDown();
- if x ~= 12 then
- turtle.forward();
- end
- end
- turtle.turnRight();
- turtle.forward();
- turtle.turnRight();
- end
- end
- --Helper Function: getItemTable(string dumpKind)
- --Creates a table of numbers that correspond to the slots that contain an item of type 'dumpKind' (wheat or seeds)
- --Returns: A table! yay!
- local function getItemTable(dumpKind)
- local itemTable = {3};
- local baseSlot = 3;
- local tableCounter = 2;
- if dumpKind == "wheat" then
- itemTable[1] = 2;
- baseSlot = 2;
- end
- for i=4, 13 do
- turtle.select(i);
- curSlot = i;
- if turtle.compareTo(baseSlot) then
- itemTable[tableCounter] = curSlot;
- tableCounter = tableCounter + 1;
- end
- end
- return itemTable;
- end
- --Helper Function: dump(string dumpKind)
- --Dumps all items in turtle's inventory based on the type of 'dumpKind' (wheat or seeds)
- --Returns: nothing
- local function dump(dumpKind)
- local tempTable = getItemTable(dumpKind);
- local kindSlot = 3;
- if dumpKind == "wheat" then
- kindSlot = 2;
- end
- for i=1, #tempTable do
- turtle.select(tempTable[i]);
- curSlot = tempTable[i];
- if curSlot == kindSlot then
- turtle.drop(turtle.getItemCount(curSlot) - 1);
- else
- turtle.drop();
- end
- end
- end
- --Helper Function: takeSeeds()
- --Takes exactly 94 seeds from chest.
- --Returns: nothing
- local function takeSeeds()
- turtle.select(3);
- curSlot = 3;
- turtle.suck();
- turtle.suck();
- turtle.select(5);
- curSlot = 5;
- turtle.drop();
- turtle.select(4);
- curSlot = 4;
- turtle.drop(32);
- end
- --Function: dumpNDeposit()
- --Dumps all seeds into chest and discards all wheat. Takes enough seeds for planting and sets turtle up for planting
- --Returns: nothing
- local function dumpNDeposit()
- turtle.turnLeft();
- dump("wheat");
- turtle.turnLeft();
- dump("seeds");
- takeSeeds();
- turtle.turnLeft();
- turtle.forward();
- turtle.turnLeft();
- end
- --Function: plantSeeds()
- --Plants seeds!
- --Returns: nothing
- local function plantSeeds()
- if curSlot ~= 4 then
- turtle.select(4);
- curSlot = 4;
- end
- for i=1, 4 do
- for x=1, 12 do
- checkCount("seeds");
- turtle.placeDown();
- if x ~= 12 then
- turtle.forward();
- end
- end
- turtle.turnRight();
- turtle.forward();
- turtle.turnRight();
- for x=1, 12 do
- checkCount("seeds");
- turtle.placeDown();
- if x ~= 12 then
- turtle.forward();
- end
- end
- turtle.turnLeft();
- turtle.forward();
- turtle.turnLeft();
- end
- end
- --Function: returnToStart()
- --Returns to starting position after planting new seeds.
- --Returns: nothing
- local function returnToStart()
- turtle.turnLeft();
- turtle.forward();
- turtle.turnLeft();
- turtle.forward();
- turtle.turnLeft();
- turtle.turnLeft();
- end
- --Function: isMealCountOK()
- --Checks count of bonemeal just before setting off.
- --Returns: False if bonemeal count is below 96, True otherwise.
- local function isMealCountOK()
- if (turtle.getItemCount(1) == 64) and (turtle.getItemCount(4) >= 34) then
- return true;
- end
- return false;
- end
- -- End function definitions
- -- Start main program
- while true do
- getBonemeal();
- if not isMealCountOK() then
- print("Stopping due to low bonemeal count");
- break;
- end
- boneNHarvest();
- dumpNDeposit();
- plantSeeds();
- returnToStart();
- end
- print("All farmed out!");
- return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement