Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[main script for farming procedure]]
- --load functions responsible for positioning/repositioning/farming
- os.loadAPI("APIS/positioners");
- os.loadAPI("APIS/farmers");
- --action turtle start farming condition
- assert(positioners.check_start_pos(), "Could not initialise the turtle for the farming procedure\nCould not identify it's starting location\n(are there birch planks directly above and beneath it?");
- --check Netherrack can be found from start block, declare 'dir' also as local
- local init_result, dir = positioners.find_next_neth()
- assert(init_result, "Could not find the appropriate direction to travel in from\n the turtle starting position, is the farm set up correctly?");
- local loop_vars = {["count"] = 0, ["blockId"] = nil, ["dir"] = nil, ["prevManvr"] = nil, ["action"] = ""};
- --**input** assertion tests for required fuel level and seed requirements
- assert(turtle.getFuelLevel() > 50, "Fuel level is below required level to start farming, - terminating");
- --given 'result' == true can start farming
- turtle.forward();
- print("Gone forwards!");
- --open log file (overwrite) and save to io class handle
- log = io.open("logs/proc_log", "w");
- print("Opened log!");
- --start main farming process loop
- while turtle.getFuelLevel() > 0 do
- print("entered loop");
- --reset action variable
- loop_vars["action"] = "";
- --sort log variables
- loop_vars["count"] = loop_vars["count"] + 1;
- --identify the block above (returns inv slot(1-4) it matches with or false if it doesn't)
- loop_vars["blockId"] = positioners.id();
- if blockId == 1 then
- loop_vars["action"] = "Netherrack above ";
- if loop_vars["dir"] == nil then
- print("Netherrack found, planting");
- farmers.plant();
- --shift turtle forward such that it can evaluate a new block. Ensure that moves forward in case of obstruction
- assert(turtle.forward(), "The turtle is impeded from moving forwards in farming route");
- --log statement
- loop_vars["action"] = loop_vars["action"].."plant and move forward";
- else
- --initiate change in direction procedure
- assert(positioners.change_direction(loop_vars["dir"]), "Failed to complete turtle change direction procedure");
- --reset dir
- loop_vars["dir"] = nil;
- loop_vars["action"] = loop_vars["action"].." actioned 'positioners.change_position(dir)'.";
- end;
- elseif blockId == 3 then
- turtle.forward();
- --log statement
- loop_vars["action"] = "Proceeding past marble block";
- elseif blockId == false then
- print("Finding next Netherrack block.");
- --retrace back to the most recent 'legitimate' block");
- turtle.back();
- --call function to reposition turtle for next farming line
- result, loop_vars["dir"] = positioners.find_next_neth(loop_vars["prevMan"]);
- assert(result, "A new netherrack block could not be found in any direction.");
- --assign dir result to prevMan (information for next positioners.change_position() call
- loop_vars["prevMan"] = loop_vars["dir"];
- --log statement
- loop_vars["action"] = "No 'legitimate' block above, 'positioners.find_next_neth() successful,\nassigning dir accordingly.";
- else
- --log statement
- log.write("Unhandled exception in farm_proc main loop");
- log.close();
- error("positioners.find_next_neth() did not find an appropriate block above it.");
- end;
- print("farm_proc loop");
- --write current turn to log file
- --log.write("Turn no: "..loop_vars["count"].."\n Id()== "..tostring(loop_vars["blockId"]).."\n Action: "..loop_vars["action"].."\n Previous maneuver: "..loop_vars["prevMan"].."\n\n");
- end;
- --updating log
- log.write("Error - turtle ran out of fuel\n");
- log.close();
- error("Turtle ran out of fuel whilst planting - terminated");
Add Comment
Please, Sign In to add comment