Advertisement
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 = {9,7,5}
- fuel_slot = 16
- plant_slots = {1,2,3,4,5,6,7,8}
- harvest_slots = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
- magic = {name = 'magicalcrops:', metadata = 7} -- growed up magic crops
- function _refuel(fuel)
- turtle.select(fuel_slot)
- turtle.refuel(fuel)
- end
- -- MOVEMENT
- 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, 3 do turtle.forward() end
- turtle.turnLeft()
- for i = 1, 3 do turtle.forward() end
- do_end_stuff()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- PLANTING
- function before_plant()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, #plant_slots do
- turtle.select(plant_slots[i])
- turtle.suck()
- local data = turtle.getItemDetail()
- if not string.match(data.name,magic.name) then turtle.drop() end
- local count = turtle.getItemCount()
- if count > 9 then turtle.dropUp(count - 9) end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- 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()
- for i = 1, #plant_slots do
- turtle.select(plant_slots[i])
- turtle.drop()
- end
- end
- -- HARVESTING
- function harvest(object)
- local s,m = turtle.inspectDown()
- if not s or not string.match(m.name,object.name) 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(magic)
- end
- function on_end_harvesting()
- for i = 1, #harvest_slots do
- turtle.select(harvest_slots[i])
- turtle.drop()
- end
- end
- -- Controlling program
- if args[1] == 'p' then
- _refuel(2)
- before_plant()
- process_field(planting, on_end_planting)
- elseif args[1] == 'h' then
- _refuel(2)
- process_field(harvesting, on_end_harvesting)
- else
- print('p - for planting')
- print('h - for harvest')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement