Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FTB AutomaticFarm - V 2.0
- -- Made by Xmarks
- -- https://www.youtube.com/channel/UCA6oAnFqdDcc0sa6H8G5DSA
- -- Program Farms and Replants Seeds
- -- Program ensures the operation can not be blocked
- -- Program Drops Excess Inventory in a chest below when Operation is finished
- -- *********************************
- -- Fuel Goes to Slot 1
- -- Seeds for comparison go to Slot 2
- -- *********************************
- -- Set Coordinates for where the Turtle will farm
- x = 4
- y = 4
- -- Global Seed Slot Variable - Do not Change
- seed_slot = 0
- -- Local Function - Check Fuel Level - Refuel if necessary
- -- TODO: Calculate Path and do not start if not enough for 1 Full Operation
- local function checkFuel()
- if turtle.getFuelLevel() < 20 then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- -- Local Function - Ensure Turtle Moves Forward 1 Block
- local function forward()
- checkFuel()
- counter = 0
- while counter < 1 do
- if turtle.forward() then
- counter = counter + 1
- -- If can not move, try digging and attacking
- else
- turtle.dig()
- turtle.attack()
- end
- end
- end
- -- Left U-Turn
- local function goLeft()
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- end
- -- Right U-Turn
- local function goRight()
- turtle.turnRight()
- forward()
- turtle.turnRight()
- end
- -- Function Tries to find seeds
- local function findSeeds()
- for i = 3,16 do
- turtle.select(i)
- if turtle.compareTo(2) then
- return i
- end
- end
- -- if Seeds are not found - Reset to Slot 2
- return 2
- end
- -- Turtle Plows/Harvests & Plants Seeds
- local function harvestReplant()
- turtle.digDown()
- -- Go to Saved Seed Slot if set during Operation
- if seed_slot ~= 0 then
- turtle.select(seed_slot)
- end
- -- If Seed Slot is not set
- -- If Seed Slot is the Comparison Slot
- -- If Saved Seed Slot Count is 0
- -- If Saved Seed Slot does not actually have Seeds
- if ( (seed_slot == 0) or (seed_slot == 2) or (turtle.getItemCount(seed_slot) == 0) or (turtle.compareTo(2) == false) ) then
- seed_slot = findSeeds()
- turtle.select(seed_slot)
- end
- turtle.placeDown()
- end
- -- Farming Function
- -- Turtle will go around the set Matrix x/y
- -- Plowing/Harvesting and Planting
- local function farm()
- for i = 1,x do
- if i%2 == 1 then
- goLeft()
- for j =1,y do
- harvestReplant()
- if j ~= y then
- forward()
- end
- end
- elseif i%2 == 0 then
- goRight()
- for j = 1,y do
- harvestReplant()
- if j ~= y then
- forward()
- end
- end
- end
- end
- end
- -- Turns the Turtle back to Starting Position
- -- Calculations based on the given Farm Matrix-Size x/y
- local function returnHome()
- if x%2 == 0 then
- forward()
- turtle.turnRight()
- for i = 1,x do
- forward()
- end
- elseif x%2 == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- for j = 1,y do
- forward()
- end
- turtle.turnRight()
- for i = 1,x do
- forward()
- end
- end
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Wait for Seeds to Grow Back - 35min
- local function timeOut()
- for i = 2100,0,-1 do
- print('Waiting Seed Growth - ' .. i .. 'sec left')
- sleep(1)
- end
- end
- -- Drop Everything except Fuel and Comparison Seeds
- local function dumpInventory()
- print('Dropping all blocks in slots 3-to-16 into a bottom chest')
- for slot = 3,16 do
- turtle.select(slot)
- turtle.dropDown()
- end
- end
- -- Farm/Return/Wait/Repeat
- while true do
- farm()
- returnHome()
- dumpInventory()
- timeOut()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement