Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***********************************************************************
- // Settings
- // ***********************************************************************
- &crop = sugar_cane;
- &harvest_tool = minecart;
- &food = carrot;
- // Starting coordinates at North-West corner of the field
- #start_x = 8566
- #start_z = -3100
- // Field Dimensions
- // row number is changed by z, increases moving south
- #num_rows = 103
- // 103
- // column number is changed by x, decreases moving west
- #num_cols = 47
- // 47
- // look(0, 90), is facing north(0) and down(90)
- // look(180,90), is facing south(180) and down(90)
- // **********************************************************************
- // Bot State
- // **********************************************************************
- #end_x = (#start_x + #num_cols) - 1
- #end_z = (#start_z + #num_rows) + 1
- // **********************************************************************
- // Algorithm
- // **********************************************************************
- // harvest field
- do;
- #offset = 1;
- // Make sure the bot starts at the correct spot
- IF( (%XPOS% != %#start_x%) || (%ZPOS% != %#start_z%));
- LOG("Bot not at starting position. Move to X=%#start_x%, Z=%#start_z%");
- stop();
- endif;
- // The bot is at the starting spot
- &harvest_direction = "south";
- // Harvest a column
- do(%#num_cols%);
- // Eat the chosen food so that we dont
- // end up leaving spaces in the field
- // when if we eat the crop
- do;
- log("Eating food. Hunger = %HUNGER%");
- pick(%&food%);
- if(%ITEM% != %&food%);
- log("Bot does not have enough food.");
- disconnect();
- endif;
- key(use);
- while(%HUNGER% <= 16);
- sprint();
- // =======================================================
- // Harvest
- // =======================================================
- log("Harvesting");
- pick(%&harvest_tool%);
- if(%ITEM% != %&harvest_tool%);
- log("Harvest tool unavailable. Stopping bot.");
- endif;
- if(%&harvest_direction% = "south");
- #dest_z = #end_z;
- else;
- #dest_z = #start_z;
- endif;
- do;
- if(%&harvest_direction% = "south");
- // look south
- look(180,0);
- else;
- // look north
- look(0,0);
- endif;
- keydown(forward);
- key(attack);
- while(%ZPOS% != %#dest_z%);
- keyup(forward);
- unsprint();
- // =========================================
- // Move #"offset" columns towards the east
- // =========================================
- if(%XPOS% != %#end_x%);
- log("Moving east to next column");
- #dest_x = %XPOS%+%#offset%;
- do;
- look(90,0);
- keydown(forward);
- while(%XPOS% != %#dest_x%);
- keyup(forward);
- endif;
- if(%#offset% = 1);
- // make it 2
- #offset = #offset + 1;
- else;
- #offset = 1;
- endif;
- // Change the harvest direction
- if(%&harvest_direction% = "south");
- &harvest_direction = "north";
- else;
- &harvest_direction = "south";
- endif;
- // end of harvesting one column and ready for next
- loop;
- log("End of harvesting the sugar cane field");
- // ================================================
- // Walk back to the start (North-West corner)
- // ================================================
- if(%XPOS% != %#start_x%);
- log("Moving back to the start of the field.");
- // move west
- do;
- look(270,0);
- keydown(forward);
- //log("x = %XPOS%, and start_x = %#start_x%");
- while(%XPOS% != %#start_x%);
- keyup(forward);
- endif;
- // walk back to the start (north-south) direction
- if(%ZPOS% != %#start_z%);
- log("Moving back to the start of the field.");
- // move north
- do;
- look(0,90);
- keydown(forward);
- //log("z = %ZPOS%, and start_z = %#start_z%");
- while(%ZPOS% != %#start_z%);
- keyup(forward);
- endif;
- // Bot should be at the start again.
- // if not something went wrong.
- if( (%XPOS% != %#start_x%) || (%ZPOS% != %#start_z%) );
- log("Bot went off-course. Stopping.");
- stop();
- endif;
- log("Back at the start.");
- // main loop
- loop;
- log("Bot stopped successfully. Harvest complete.")
- stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement