Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- --- Basic Farm ----
- 1. Refuel turtle with at least 8 coal only one time
- 2. Put any amount of seeds you want in the turtle inventory
- 3. Put 2 chest behind the turtle one on top of the other (Top chest has coal, bottom chest saves crops)
- 4. Place water base on the dimension size and clear the area from blocks ( farming turtles cant remove blocks, only flowers/grass/etc )
- 5. Run the program [ default args [1]FirstTime = true ]
- --]]
- local DIMENSION = {x = 9, y = 9};
- local SEEDS = {"minecraft:carrot", "minecraft:potato", "minecraft:wheat_seeds"} -- Put any seed you want
- -- DO NOT TOUCH
- local args = {...};
- local routes = 1;
- local firstTime = true;
- function refuel()
- local fueled = turtle.getFuelLevel() > 160;
- if not fueled then
- turtle.turnRight();
- turtle.turnRight();
- turtle.up();
- if turtle.suck(32) then
- print("Sarching for fuel...");
- for i = 2, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- fueled = true;
- turtle.refuel(32);
- break
- end
- end
- end
- turtle.down();
- turtle.turnRight();
- turtle.turnRight();
- end
- turtle.select(1);
- print('Fuel Level -> ' .. turtle.getFuelLevel());
- return fueled;
- end
- function forceForward()
- while turtle.detect() do turtle.dig(); end
- turtle.forward();
- end
- function traversePath(onTraverse)
- for x = 1, DIMENSION.x do
- for y = 1, DIMENSION.y do onTraverse(x, y) end
- forceForward();
- if (x % 2 == 0) then
- turtle.turnRight();
- forceForward();
- turtle.turnRight();
- else
- turtle.turnLeft();
- forceForward();
- turtle.turnLeft();
- end
- end
- end
- function goBackHome()
- turtle.forward();
- if DIMENSION.x % 2 == 0 then
- turtle.turnRight();
- forceForward();
- turtle.turnRight();
- forceForward();
- turtle.turnLeft();
- for x = 1, DIMENSION.x - 1 do forceForward(); end
- else
- for x = 1, DIMENSION.x do forceForward(); end
- turtle.turnLeft();
- for y = 1, DIMENSION.y do forceForward(); end
- end
- turtle.turnLeft();
- turtle.down();
- end
- function clearPath()
- function clear(row, column)
- forceForward();
- if turtle.detectUp() then turtle.digUp(); end
- end
- traversePath(clear)
- goBackHome();
- end
- function plantCrops()
- local planted = false;
- for i = 1, 16 do
- local item = turtle.getItemDetail(i);
- if item ~= nil then
- for x = 1, #SEEDS do
- if item.name == SEEDS[x] then
- turtle.select(i);
- planted = turtle.placeDown();
- end
- end
- end
- end
- return planted;
- end
- function checkCrops()
- print("Checking crops...");
- turtle.up();
- function check(row, column)
- forceForward();
- local success, item = turtle.inspectDown();
- if (success and item.state.age == 7) then
- turtle.digDown();
- plantCrops();
- elseif not success then
- if not plantCrops() then
- turtle.digDown();
- plantCrops();
- end
- end
- turtle.suckDown();
- end
- traversePath(check)
- goBackHome();
- end
- function saveCrops()
- turtle.turnRight();
- turtle.turnRight();
- turtle.select(1);
- local item = turtle.getItemDetail(1);
- if item ~= nil then
- local isSeed = false;
- for x = 1, #SEEDS do
- if item.name == SEEDS[x] then isSeed = true; end
- end
- if not isSeed then turtle.drop(64) end
- end
- for i = 2, 16 do
- turtle.select(i);
- item = turtle.getItemDetail(i);
- if item ~= nil then
- local amount = turtle.getItemCount(i);
- for x = 1, #SEEDS do
- if item.name == SEEDS[x] then
- turtle.transferTo(1, amount)
- end
- end
- if not turtle.drop(64) then
- print("Cant drop items.. trying again...")
- break
- end
- end
- end
- turtle.turnRight();
- turtle.turnRight();
- turtle.select(1);
- end
- if args[1] ~= nil then firstTime = args[1] == "true"; end
- -- STARTS PROGRAM
- shell.run('clear')
- while true do
- term.setCursorPos(1, 1);
- print("--Starting farming process number: " .. routes)
- if refuel() then
- if firstTime then
- clearPath();
- firstTime = false;
- end
- checkCrops();
- saveCrops();
- end
- textutils.slowPrint('Sleeping for 2 minutes....');
- print("--")
- os.sleep(120);
- routes = routes + 1;
- shell.run('clear')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement