Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local parameter = {numOfBranches, lengthOfBranch, skipBranches, numOfFinishedBranches};
- -- Function declaration
- local goBackToEnd;
- local skipBranches;
- local checkIfInventoryIsFull;
- local emptyInventory;
- local goBackToStart;
- local selectItemInInventory;
- local placeItem;
- local refuel;
- local dig;
- local digBranch;
- local digBranches;
- local setReady;
- local main;
- local reset;
- local pickUpItems;
- -- Fcuntion implementation
- main = function()
- if not pcall(function() os.loadAPI("move.lua") end ) then
- print("Move Api could not be loaded!");
- return --Exit programm
- end
- move.init();
- if #arg == 1 then
- if arg[1] == -1 then
- --Read file
- end
- end
- if #arg == 3 then
- lengthOfBranch = arg[1];
- numOfBranches = arg[2];
- skipBranches = arg[3];
- else
- print("How long should a branch be? (50)");
- lengthOfBranch = tonumber(io.read()) or 50;
- print("How many Branches? (-1 for infinite) (5)");
- numOfBranches = tonumber(io.read()) or 5;
- print("Skip Branches? (0)");
- skipBranches = tonumber(io.read()) or 0;
- end
- if move.getY() ~= 0 then
- goBackToStart();
- else
- setReady();
- skipBranches(skipBranches);
- digBranches(lengthOfBranch, numOfBranches);
- end
- end
- goBackToStart = function()
- move.turn(2);
- move.forward(math.abs(move.getPosX()));
- move.turnToDirection(2);
- move.setPosYOld(move.getPosY());
- move.forward(math.abs(move.getPosY()));
- move.down();
- end
- goBackToEnd = function()
- move.turnToDirection(0);
- if move.getPosZ() == 0 then
- move.Up();
- end
- move.forward(move.getPosYOld());
- end
- skipBranches = function(amount)
- amount = amount or 0;
- move.forward(amount*3)
- end
- checkIfInventoryIsFull = function()
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- return false;
- end
- end
- return true
- end
- emptyInventory = function()
- for i=1, 16 do
- local data = turtle.getItemDetail(i);
- if data and data.name ~= "minecraft:torch" and data.name ~="minecraft:coal" then
- turtle.select(i);
- turtle.drop();
- end
- end
- if checkIfInventoryIsFull() then
- os.reboot();
- end
- end
- selectItemInInventory = function(itemName)
- for i=1,16 do
- local data = turtle.getItemDetail(i);
- if data ~= nil then
- if data.name == itemName then
- turtle.select(i);
- return;
- end
- end
- end
- return -1;
- end
- placeItem = function(itemName)
- if selectItemInInventory(itemName) ~= -1 then
- turtle.placeUp();
- end
- end
- refuel = function(amount)
- for i=1, 16 do
- if turtle.getFuelLevel() > amount then
- break;
- else
- if selectItemInInventory("minecraft:coal") == -1 then
- reset();
- end
- turtle.refuel();
- end
- end
- if turtle.getFuelLevel() < amount then
- reset();
- end
- end
- dig = function(length)
- for i=1, length do
- turtle.dig();
- move.forward(1);
- turtle.digDown();
- local success, data = turtle.inspectUp()
- if success and data.name ~= "minecraft:wall_torch" then
- turtle.digUp();
- end
- end
- end
- digBranch = function(length)
- dig(length);
- placeItem("minecraft:torch");
- move.turn(2)
- local steps_10 = math.floor(length/10); -- Zehner Schritte
- local steps = math.fmod(length, 10); -- Einer Schritte
- for i=1, steps_10 do
- move.forward(10);
- placeItem("minecraft:torch");
- end
- move.forward(steps);
- refuel(length*2);
- end
- digBranches = function(length, amount)
- if amount == -1 then
- amount = 1e309;
- end
- for i=1, amount do
- move.turnToDirection(0);
- dig(3);
- move.turnToDirection(1);
- digBranch(length);
- if checkIfInventoryIsFull() then
- goBackToStart();
- emptyInventory();
- goBackToEnd();
- move.turnToDirection(1);
- pickUpItems(length);
- end
- move.turnToDirection(3);
- digBranch(length);
- if checkIfInventoryIsFull() then
- goBackToStart();
- emptyInventory();
- goBackToEnd();
- move.turnToDirection(3)
- pickUpItems(length);
- end
- end
- reset();
- end
- pickUpItems = function(length)
- for i=1, length do
- turtle.suckDown();
- move.forward(1);
- end
- move.turn(2);
- move.forward(length);
- end
- setReady = function()
- if move.getPosYOld() ~= 0 then
- goBackToEnd();
- elseif turtle.detectDown() then
- move.up();
- end
- end
- reset = function()
- goBackToStart();
- emptyInventory();
- turnToDirection(0);
- os.reboot();
- end
- main();
Add Comment
Please, Sign In to add comment