Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program for Farming Turtle from ComputerCraft mod.
- -- AutoFarm Ver 1.0
- -- Copyright (c) 2015 Alexander Andreyev <aravsar@ya.ru>
- -- Farming 9x9 field
- -- I S x x x x x x x x
- -- x x x x x x x x x
- -- x x x x x x x x x
- -- x x x x x x x x x
- -- x x x x W x x x x
- -- x x x x x x x x x
- -- x x x x x x x x x
- -- x x x x x x x x x
- -- x x x x x x x x x
- -- S - start position
- -- I - possible inventory with which interacts turtle in the end (do_end_stuff)
- -- W - water block in center
- -- The turtle moves clockwise from S to W by spiral,
- -- moves back to the S, drop stuff to I and stops.
- -- The turtle must be in one block above the field.
- -- MAIN PROGRAM
- args = {...}
- chest_name_part = 'Chest' -- a part of name of the I chest
- rings = {5,3}
- fuel_slot = 16
- function _refuel(fuel)
- turtle.select(fuel_slot)
- turtle.refuel(fuel)
- end
- function process_field(do_stuff, do_end_stuff)
- for i = 1, #rings do
- local n = rings[i]
- for j = 1, 4 do
- if j == 4 then n = n - 1 end
- for k = 1, n-1 do
- do_stuff()
- turtle.forward()
- end
- turtle.turnRight()
- end
- do_stuff()
- turtle.forward()
- end
- -- moving back on start position
- turtle.turnLeft()
- for i = 1, 4 do turtle.forward() end
- turtle.turnLeft()
- for i = 1, 4 do turtle.forward() end
- do_end_stuff()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- PLANTING
- plant_slots = {1,2,3,4}
- function plant()
- for i = 1, #plant_slots do
- turtle.select(plant_slots[i])
- if turtle.getItemCount(plant_slots[i]) > 0 then
- turtle.placeDown()
- return
- end
- end
- end
- function planting()
- local s,_ = turtle.inspectDown()
- if s == false then
- turtle.digDown()
- plant()
- end
- end
- function on_end_planting()
- end
- -- HARVESTING
- harvest_slots = {5,6,7,8}
- wheat = {name = 'minecraft:wheat', metadata = 7} -- growed up wheat
- function harvest(object)
- local _,m = turtle.inspectDown()
- if m.name ~= object.name or m.metadata ~= object.metadata then return end
- for i = 1, #harvest_slots do
- turtle.select(harvest_slots[i])
- if turtle.getItemSpace(harvest_slots[i]) > 0 then
- turtle.digDown()
- return
- end
- end
- end
- function harvesting()
- harvest(wheat)
- end
- function on_end_harvesting()
- local _,m = turtle.inspect()
- if m.name:find(chest_name_part) == nil then return end
- for i = 1, #harvest_slots do
- turtle.select(harvest_slots[i])
- turtle.drop()
- end
- end
- -- HARVEST AND PLANT
- function harvest_and_plant( ... )
- harvesting()
- planting()
- end
- -- Controlling program
- if args[1] == 'p' then
- _refuel(2)
- process_field(planting, on_end_planting)
- elseif args[1] == 'h' then
- _refuel(2)
- process_field(harvesting, on_end_harvesting)
- elseif args[1] == 'ph' then
- _refuel(2)
- process_field(harvest_and_plant, on_end_harvesting)
- else
- print('p - for planting')
- print('h - for harvest')
- print('ph - for harvest and plant')
- end
Add Comment
Please, Sign In to add comment