Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lightbarrow Farmbot
- // October 31, 2014
- //
- // This bot works with seedless crops: potato, carrot
- //
- // To-do:
- // -> Empty items to a chest.
- // -> Skip columns that are not dirt (the semi-auto farm edge levels)
- // ***********************************************************************
- // Settings — Change these to what you want to use.
- // ***********************************************************************
- &harvest_tool = diamond_axe;
- &repair_tool = stone_hoe;
- &food = carrot;
- // Starting coordinates at North-East corner of the field
- // The autofarm/tiered-fields should run in the North-South direction.
- // Test Field
- //#field_start_x = 14;
- //#field_start_z = 1;
- // Autofarm North-side
- #autofarm_north_start_x = 6957;
- #autofarm_north_start_z = -3019;
- #autofarm_north_num_rows = 7;
- #autofarm_north_num_cols = 35;
- #autofarm_north_num_levels = 5;
- &autofarm_north_crop = potato;
- // Autofarm South-side
- #autofarm_south_start_x = 6957;
- #autofarm_south_start_z = -2977;
- #autofarm_south_num_rows = 7;
- #autofarm_south_num_cols = 35;
- #autofarm_south_num_levels = 4;
- &autofarm_south_crop = potato;
- // North-west Carrot farm
- #carrot_farm_start_x = 6915;
- #carrot_farm_start_z = -3019;
- #carrot_farm_num_rows = 7;
- #carrot_farm_num_cols = 26;
- #carrot_farm_num_levels = 4;
- &carrot_farm_crop = carrot;
- // See if we are at the start of a field
- if( (%XPOS% = #autofarm_north_start_x) && (%ZPOS% = #autofarm_north_start_z));
- log("Starting work on the north-side of the autofarm.");
- #field_start_x = #autofarm_north_start_x;
- #field_start_z = #autofarm_north_start_z;
- #num_rows = #autofarm_north_num_rows;
- #num_cols = #autofarm_north_num_cols;
- #num_levels = #autofarm_north_num_levels;
- &crop = %&autofarm_north_crop%;
- elseif( (%XPOS% = #autofarm_south_start_x) && (%ZPOS% = #autofarm_south_start_z));
- log("Starting work on the south-side of the autofarm.");
- #field_start_x = #autofarm_south_start_x;
- #field_start_z = #autofarm_south_start_z;
- #num_rows = #autofarm_south_num_rows;
- #num_cols = #autofarm_south_num_cols;
- #num_levels = #autofarm_south_num_levels;
- &crop = %&autofarm_south_crop%;
- elseif( (%XPOS% = #carrot_farm_start_x) && (%ZPOS% = #carrot_farm_start_z));
- log("Starting work on the north-west carrot farm.");
- #field_start_x = #carrot_farm_start_x;
- #field_start_z = #carrot_farm_start_z;
- #num_rows = #carrot_farm_num_rows;
- #num_cols = #carrot_farm_num_cols;
- #num_levels = #carrot_farm_num_levels;
- &crop = %&carrot_farm_crop%;
- else;
- log("You are not at the start of a field. Move to North-east corner of a field.");
- stop();
- endif;
- log("Harvest tool = %&harvest_tool%");
- log("Repair tool = %&repair_tool%");
- log("Crop = %&crop%");
- // General Info:
- // look(0, 90), is facing north(0) and down(90)
- // look(180,90), is facing south(180) and down(90)
- // **********************************************************************
- // Algorithm
- // **********************************************************************
- // Make sure the bot starts at the correct spot (North-East corner of the field)
- IF( (%XPOS% != %#field_start_x%) || (%ZPOS% != %#field_start_z%));
- LOG("Unable to start bot. Move to X=%#field_start_x%, Z=%#field_start_z%");
- stop();
- endif;
- // ==============================
- // Loop over each level (of autofarm)
- // ==============================
- sprint;
- #even = 0;
- for(#levelnum, 1, %#num_levels%);
- &harvest_direction_z = "south";
- if(%#even% = 0);
- log("even = 0");
- // Start at the north-east corner
- #start_x = #field_start_x;
- #end_x = (%#start_x% - %#num_cols%) + 1;
- &harvest_direction_x = "west";
- else;
- log("even = 1");
- // Start at the north-west corner
- #start_x = (#field_start_x - #num_cols) + 1;
- #end_x = (#start_x + #num_cols) - 1;
- &harvest_direction_x = "east";
- endif;
- #start_z = #field_start_z + ((#levelnum - 1) * #num_rows);
- #end_z = (#start_z + #num_rows) - 1;
- log("field_start_x = %#field_start_x%");
- log("num_cols = %#num_cols%");
- log("start_x = %#start_x%");
- log("Start = (%#start_x%, %#start_z%)");
- log("End = (%#end_x%, %#end_z%)");
- // ======================================================
- // Loop over each column
- // ======================================================
- do(%#num_cols%);
- // ======================================================
- // Eat food
- // ======================================================
- do;
- log("Eating food. Hunger = %HUNGER%");
- pick(%&food%);
- if(%ITEM% != %&food%);
- log("Bot does not have food.");
- stop();
- endif;
- key(use);
- while(%HUNGER% < 20);
- // ======================================================
- // Harvest the crop
- // ======================================================
- log("Harvesting");
- // Select the harvesting tool
- pick(%&harvest_tool%);
- if(%ITEM% != %&harvest_tool%);
- log("Harvest tool unavailable. Stopping bot.");
- stop();
- endif;
- // Set up the end points
- if(%&harvest_direction_z% = "south");
- #dest_z = #end_z;
- else;
- #dest_z = #start_z;
- endif;
- // Walk and harvest a column
- do;
- if(%&harvest_direction_z% = "south");
- look(180,90);
- else;
- look(0,90);
- endif;
- keydown(forward);
- key(attack);
- while(%ZPOS% != %#dest_z%);
- keyup(forward);
- // ======================================================
- // Repair the soil
- // ======================================================
- log("Repairing");
- // Select the repair tool (hoe)
- pick(%&repair_tool%);
- if(%ITEM% != %&repair_tool%);
- log("Repair tool unavailable. Stopping bot.");
- stop();
- endif;
- // Setup the end points
- if(%&harvest_direction_z% = "south");
- #dest_z = #start_z;
- else;
- #dest_z = #end_z;
- endif;
- // Walk and repair a column
- do;
- if(%&harvest_direction_z% = "south");
- look(0,90);
- else;
- look(180,90);
- endif;
- keydown(forward);
- key(use);
- while(%ZPOS% != %#dest_z%);
- keyup(forward);
- // ======================================================
- // Plant the crop
- // ======================================================
- log("Planting");
- // Select the crop to plant
- pick(%&crop%);
- if(%ITEM% != %&crop%);
- log("Harvest tool unavailable. Stopping bot.");
- stop();
- endif;
- // Set up the end points
- if(%&harvest_direction_z% = "south");
- #dest_z = #end_z;
- else;
- #dest_z = #start_z;
- endif;
- // Walk and plant a column
- do;
- if(%&harvest_direction_z% = "south");
- look(180,90);
- else;
- look(0,90);
- endif;
- keydown(forward);
- key(use);
- while(%ZPOS% != %#dest_z%);
- keyup(forward);
- // ======================================================
- // Move to next column
- // ======================================================
- if(%XPOS% != %#end_x%);
- log("Moving to next column");
- if(%&harvest_direction_x% = "west");
- #dest_x = %XPOS%-1;
- else;
- #dest_x = %XPOS%+1;
- endif;
- do;
- if(%&harvest_direction_x% = "west");
- look(270,90);
- else;
- look(90,90);
- endif;
- keydown(forward);
- while(%XPOS% != %#dest_x%);
- keyup(forward);
- endif;
- log("At next column to process");
- // ======================================================
- // Change the harvesting direction
- // ======================================================
- if(%&harvest_direction_z% = "south");
- &harvest_direction_z = "north";
- else;
- &harvest_direction_z = "south";
- endif;
- // ======================================================
- // LOOP: END OF WORKING ON THE COLUMN. PROCEED TO NEXT.
- // ======================================================
- loop;
- // =============================
- // End of harvesting one level
- // =============================
- log("Bot is moving one column off field.");
- // Move one column off the field
- if(%&harvest_direction_x% = "west");
- #dest_x = %XPOS% - 1;
- else;
- #dest_x = %XPOS% + 1;
- endif;
- do;
- if(%&harvest_direction_x% = "west");
- look(270,90);
- else;
- look(90,90);
- endif;
- keydown(forward);
- while(%XPOS% != %#dest_x%);
- keyup(forward);
- log("Bot should be off-field by 1 column");
- // Now bot should be 1 column off the field, either on west or east side
- // Bot needs to move to the next starting location
- if(%#even% = 1);
- // Start at the north-east corner
- #dest_x = #field_start_x;
- else;
- // Start at the north-west corner
- #dest_x = (#field_start_x - #num_cols) + 1;
- endif;
- #dest_z = #field_start_z + ((#levelnum) * #num_rows);
- if(#levelnum != #num_levels);
- log("Moving to start of next level");
- if(%ZPOS% != %#dest_z%);
- // Move north-south direction
- do;
- look(180,90);
- keydown(forward);
- while(%ZPOS% != %#dest_z%);
- keyup(forward);
- endif;
- // Move east-west direction
- if(%XPOS% != %#dest_x%);
- do;
- if(#even = 0);
- look(90,90);
- else;
- look(270,90);
- endif;
- keydown(forward);
- while(%XPOS% != %#dest_x%);
- keyup(forward);
- endif;
- log("Bot should be at start of next level");
- // Verify
- if( (%XPOS% != %#dest_x%) || (%ZPOS% != %#dest_z%));
- log("Error. Bot went off-course. Stopping.");
- stop();
- endif;
- endif;
- toggle(#even);
- // Loop at the next level
- next;
- // ======================================================
- // End of harvesting the entire field.
- // Walk back to the start of the field.
- // ======================================================
- // East-West direction
- if(%XPOS% != (%#field_start_x%+1));
- log("Moving back to the start (East-West).);
- do;
- look(90,90);
- keydown(forward);
- while(%XPOS% != (%#field_start_x%+1));
- keyup(forward);
- endif;
- // North-South direction
- if(%ZPOS% != %#field_start_z%);
- log("Moving back to the start (North-South)");
- // move north
- do;
- look(0,90);
- keydown(forward);
- //log("z = %ZPOS%, and start_z = %#field_start_z%");
- while(%ZPOS% != %#field_start_z%);
- keyup(forward);
- endif;
- // Move one unit over to finish moving to the start
- do;
- look(270,90);
- keydown(forward);
- while(%XPOS% != %#field_start_x%);
- keyup(forward);
- unsprint;
- // ======================================================
- // Bot Checkup.
- // Bot should be back at the start of the field, if not
- // something went wrong.
- // ======================================================
- if( (%XPOS% != %#field_start_x%) || (%ZPOS% != %#field_start_z%) );
- log("Bot went off-course. Something strange happened. Stopping bot.”);
- stop();
- endif;
- // ======================================================
- // Success!
- // ======================================================
- log("Bot stopped successfully. Harvest complete.")
- stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement