Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --dofile("api.lua");
- local chesttname = "minecraft:chest";
- local pos = {};
- local function RefuelIfNessesary()
- local level = turtle.getFuelLevel();
- if level=="unlimited" then
- return true;
- elseif level < 1 then
- turtle.select(1);
- if not turtle.refuel() then
- return false, "unable to refuel, slot 1 not fuel or empty";
- end
- else
- return true;
- end
- end
- local function IsFacingBaseChest()
- local item = turtle.inspect();
- return type(item)=="table" and item.name==chesttname;
- end
- --Must be facing the chest for this to work
- local function GetFuelFromChest()
- turtle.select(1);
- if turtle.getItemCount() >= 64 then
- return true;
- elseif not IsFacingBaseChest() then
- return false, "Not facing base chest";
- elseif not turtle.suck(64) then
- return false, "base chest is empty";
- else
- return true;
- end
- end
- local function Calibrate()
- local foundchest = false;
- for n=1,4 do
- if IsFacingBaseChest() then
- foundchest = true;
- break;
- end
- turtle.turnRight();
- end
- if not foundchest then
- return false,"base chest not found, please place me next to the base chest";
- end
- --We're facing our base chest here
- local ok,msg = GetFuelFromChest();
- if not ok then
- return false,msg;
- elseif RefuelIfNessesary() then
- GetFuelFromChest(); -- get more
- end
- turtle.turnRight();
- local steps = 0;
- local blockf = turtle.inspect();
- local blockd = turtle.inspectDown();
- while not blockf and blockd do
- if turtle.forward() then
- steps = steps + 1;
- blockf = turtle.inspect();
- blockd = turtle.inspectDown();
- else
- return false,"Cannot move forwards (no fuel?)";
- end
- end
- pos.base = {x=steps,y=0,z=0};
- print("base is at X offset: "..tostring(steps));
- --we're now at _our_ 0,0,0 facing forwards
- --now turn and travel down the y axis
- turtle.turnRight();
- steps = 0;
- blockf = turtle.inspect();
- blockd = turtle.inspectDown();
- while not blockf and blockd do
- if turtle.forward() then
- steps = steps + 1;
- blockf = turtle.inspect();
- blockd = turtle.inspectDown();
- else
- return false,"Cannot move forwards (no fuel?)";
- end
- end
- local yMax = steps;
- print("Y Max: "..tostring(yMax));
- --now walk back
- turtle.turnRight();
- turtle.turnRight();
- for n=1,yMax do
- if not turtle.forward() then
- return false,"Cannot move forwards (no fuel?)";
- end
- end
- --Now we're at our 0,0,0 (in a courner)
- turtle.turnLeft();
- steps = 0;
- blockf = turtle.inspect();
- blockd = turtle.inspectDown();
- while not blockf and blockd do
- if turtle.forward() then
- steps = steps + 1;
- blockf = turtle.inspect();
- blockd = turtle.inspectDown();
- else
- return false,"Cannot move forwards (no fuel?)";
- end
- end
- --Now we've travled down x
- local xMax = steps;
- pos.grid = {x=xMax,y=yMax};
- print("X Max: "..tostring(xMax));
- --now walk back
- turtle.turnRight();
- turtle.turnRight();
- for n=1,yMax do
- if not turtle.forward() then
- return false,"Cannot move forwards (no fuel?)";
- end
- end
- print("I'm now home");
- pos.pos = {x=0,y=0,z=0,face="right"};
- return true;
- end
- local function Up()
- end
- local function Down()
- end
- local function Right()
- end
- local function Left()
- end
- local ok,msg=Calibrate();
- print(ok,msg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement