Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('hare')
- os.loadAPI('act')
- local PLANT_CHECK_INTERVAL = 20 -- wait 2 mins in between plant growth checks
- function activateAA() -- AA is "autonomous activator"
- os.sleep(1) -- wait for items to go through hopper into AA
- redstone.setOutput('bottom', true)
- os.sleep(0.85) -- this is the tricky part, server lag might mess up this step, causing the AA to break the crop sticks
- redstone.setOutput('bottom', false)
- end
- function checkFacingHopper()
- local result, block
- result, block = turtle.inspect()
- assert(result == true and block['name'] == 'minecraft:hopper', 'Turtle is not facing a hopper')
- end
- function checkOverChest()
- local result, block
- result, block = turtle.inspectDown()
- assert(result == true and block['name'] == 'minecraft:chest', 'Turtle is not over a chest')
- end
- function dropSeedIntoHopper()
- local didDropSeed = false
- local slot, result
- for slot = 1, 16 do
- result = turtle.getItemDetail(slot)
- -- NOTE: This relies on "seed" being in the name of the seed item
- if result ~= nil and string.find(string.lower(result['name']), 'seed') then
- turtle.select(slot)
- act.doActions('dr')
- didDropSeed = true
- end
- end
- assert(didDropSeed, 'No seed to drop into seed analyzer hopper')
- end
- function condense()
- -- condense similar inventory items into fewer slots
- local slot1, slot2
- local itemData1, itemData2
- for slot1 = 1, 15 do
- turtle.select(slot1)
- for slot2 = slot1 + 1, 16 do
- if turtle.getItemCount() > 0 then
- itemData1 = turtle.getItemDetail(slot1)
- itemData2 = turtle.getItemDetail(slot2)
- if itemData1 ~= nil and itemData2 ~= nil and itemData1['name'] == itemData2['name'] then
- turtle.transferTo(slot2)
- end
- end
- end
- end
- end
- -- turtle start up checks
- local result, block
- result, block = turtle.inspectDown()
- assert(result == true and block['name'] == 'ExtraUtilities:trashcan', 'Start turtle on top of trash can')
- result, block = turtle.inspect()
- assert(result == true and block['name'] == 'minecraft:hopper', 'Start turtle facing the hopper')
- assert(turtle.getFuelLevel() > 1000, 'Start turtle w/ >= 1000 fuel')
- --assert(hare.selectItem('AgriCraft:cropsItem'), 'Start turtle with >= 6 crop sticks')
- --assert(turtle.getItemCount() >= 6, 'Start turtle with >= 6 crop sticks')
- local slot
- local numEmptySlots = 0
- for slot = 1, 16 do
- if turtle.getItemCount(slot) == 0 then
- numEmptySlots = numEmptySlots + 1
- end
- end
- -- 2 empty spaces needed for when picking up seeds and possibly essence
- assert(numEmptySlots >= 2, 'Start turtle with >= 2 empty slots')
- print('Passed startup checks.')
- while true do
- assert(hare.selectItem('AgriCraft:cropsItem'), 'Not enough crop sticks')
- assert(turtle.getItemCount() >= 6, 'Not enough crop sticks')
- -- place crop stick in P1 & P2
- act.doActions('b pd b r f pd') -- turtle ends over P2, facing P2AA
- print('Placed cropstick in P2.')
- -- get seeds from seed analyzer output chest
- assert(hare.selectEmptySlot(), 'Did not have empty space for seed pick up')
- act.doActions('l f 2')
- --act.doActions('sd') -- DON'T DO THIS. If the seeds are two different levels, only 1 gets picked up
- assert(turtle.suckDown(1), 'Could not get first seed')
- assert(turtle.suckDown(1), 'Could not get second seed')
- -- because non-magical crop seeds could have different names, we can't verify that seeds were taken from the chest here.
- print('Got seeds from chest.')
- -- put seed into P2 AA
- act.doActions('b 2 r f')
- checkFacingHopper()
- assert(hare.selectItem('ee'), 'Could not select P2 seed') -- hopefully 'ee' is enough to match 'seed' in the seed name
- turtle.drop(1)
- print('Put seed into P2 AA.')
- -- activate P2 AA to plant seed
- activateAA()
- print('Activated P2 AA.')
- -- put seed into P1 AA
- act.doActions('b 3 l f l')
- checkFacingHopper()
- assert(hare.selectItem('ee'), 'Could not select P1 seed') -- hopefully 'ee' is enough to match 'seed' in the seed name
- turtle.drop(1)
- print('Put seed into P1 AA.')
- -- activate P1 AA to plant seed
- activateAA()
- print('Activated P1 AA.')
- -- put cropsticks in C1
- assert(hare.selectItem('AgriCraft:cropsItem'), 'Turtle somehow lost a cropstick')
- act.doActions('b 2 pd')
- print('Placed cropstick in C1.')
- -- put cropsticks in C1 AA
- act.doActions('l 2 f')
- checkFacingHopper()
- turtle.drop(1)
- print('Put cropstick in C1 AA.')
- -- activate C1 AA to place 2nd crop stick
- activateAA()
- print('Activated C1 AA.')
- -- put cropsticks in C2
- assert(hare.selectItem('AgriCraft:cropsItem'), 'Turtle somehow lost a cropstick')
- act.doActions('b 2 l b pd')
- print('Placed cropstick in C2.')
- -- put cropsticks in C2 AA
- act.doActions('l f')
- checkFacingHopper()
- turtle.drop(1)
- print('Put cropstick in C1 AA.')
- -- activate C2 AA to plant seed
- activateAA()
- print('Activated C2 AA.')
- -- NOTE: The plants can't grow while the turtle is hovering over them.
- -- check if C2 plant has grown
- print('Waiting for C2 to grow...')
- while true do
- os.sleep(PLANT_CHECK_INTERVAL)
- act.doActions('b')
- result, block = turtle.inspectDown()
- assert(result and block['name'] == 'AgriCraft:crops', 'Turtle somehow not over crops')
- if block['metadata'] > 0 then
- print('C2 has grown!')
- break
- else
- act.doActions('f')
- end
- end
- -- harvest C2 plant
- act.doActions('dd')
- -- put seed into seed analyzer hopper
- act.doActions('r f 2')
- checkFacingHopper()
- dropSeedIntoHopper()
- -- move over the chest
- act.doActions('r f r')
- checkOverChest()
- -- check if C1 plant has grown
- print('Waiting for C1 to grow...')
- while true do
- act.doActions('f')
- result, block = turtle.inspectDown()
- assert(result and block['name'] == 'AgriCraft:crops', 'Turtle somehow not over crops')
- if block['metadata'] > 0 then
- print('C1 has grown!')
- break
- else
- act.doActions('b')
- end
- os.sleep(PLANT_CHECK_INTERVAL) -- wait comes after for C1 because if C2 has grown, so has this one probably
- end
- -- harvest C1 plant
- act.doActions('dd')
- -- put seed into seed analyzer hopper
- act.doActions('b r f r')
- checkFacingHopper()
- dropSeedIntoHopper()
- print('Collecting old plants to throw away...')
- -- pick up P1 plant
- act.doActions('b dd')
- -- pick up P2 plant
- act.doActions('b r f dd')
- -- trash the old seeds
- act.doActions('b l f 2')
- result, block = turtle.inspectDown()
- assert(result == true and block['name'] == 'ExtraUtilities:trashcan', 'Turtle is not over trash can')
- local didDropSeed = false
- for slot = 1, 16 do
- result = turtle.getItemDetail(slot)
- -- NOTE: This relies on "seed" being in the name of the seed item
- if result ~= nil and string.find(string.lower(result['name']), 'seed') then
- turtle.select(slot)
- act.doActions('drd')
- didDropSeed = true
- end
- if result ~= nil and string.find(string.lower(result['name']), 'essence') then
- turtle.select(slot)
- act.doActions('drd')
- didDropSeed = true
- end
- end
- assert(didDropSeed, 'No seed to drop into trash can')
- -- At this point, the turtle will have 2 fewer cropsticks
- -- than at the start, but they're in multiple slots.
- -- Condense them all into as few slots as possible.
- condense()
- os.sleep(10) -- just some extra time in case the seed analyzer is taking a while
- print('Cycle complete. Repeating...')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement