Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ####################################
- -- harvest_millet
- -- version 0.3
- -- http://hevohevo.hatenablog.com/
- -- #########################
- -- TOP view
- -- T: turtle, o: millet, W: water
- -- Z_SIZE=5, COUNT=1
- -- oWo
- -- oWo
- -- oWo
- -- oWo
- -- oWo
- -- T
- -- Z_SIZE=5, COUNT=3
- -- oWooWooWo
- -- oWooWooWo
- -- oWooWooWo
- -- oWooWooWo
- -- oWooWooWo
- -- T
- -- #########################
- -- Side view
- -- Y position is 3, same as the top of the millet.
- -- T: turtle, o: millet, F: Chest for Fuel items, C: Chest for droping down millets
- -- F
- -- oT
- -- oC
- -- o
- -- ####################
- -- config
- FUEL_SLOT = 16
- Z_SIZE = 5
- COUNT = 1
- -- ####################
- -- define functions
- function goForward(n)
- for i=1,n do
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- end
- end
- function goRightLine()
- turtle.turnRight()
- goForward(2)
- turtle.turnRight()
- end
- function goLeftLine()
- turtle.turnLeft()
- goForward(1)
- turtle.turnLeft()
- end
- function harvest()
- for i=1,COUNT do
- goForward(Z_SIZE)
- goRightLine()
- goForward(Z_SIZE)
- goLeftLine()
- end
- end
- function backToChest()
- turtle.turnLeft()
- for i=1,COUNT*3 do
- turtle.forward()
- end
- turtle.turnRight()
- end
- function dropItems(begin_slot, end_slot)
- print('drop items: slots ',begin_slot,'-',end_slot)
- for i=begin_slot, end_slot do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- function fuelItUp()
- -- first of all, refuel() in slot 16
- turtle.select(FUEL_SLOT)
- turtle.refuel()
- if (turtle.getFuelLevel() < minFuelLevel) then
- -- suckup fuel items and refuel
- turtle.suckUp()
- turtle.refuel()
- if (turtle.getFuelLevel() < minFuelLevel) then
- -- failed to refuel(), and terminated.
- print("Please insert fuel into slot ",FUEL_SLOT)
- return false
- end
- print('Succeed: fuelItUp()')
- end
- return true
- end
- function isHomePosition()
- return (turtle.detectUp() and turtle.detectDown())
- end
- -- ###################
- -- Main
- args = {...}
- if args and #args == 2 then
- Z_SIZE = tonumber(args[1])
- COUNT = tonumber(args[2])
- end
- minFuelLevel = ((Z_SIZE + 2 + Z_SIZE + 1) * COUNT) + (3 * COUNT)
- print(string.format("harvest_millet %d %d", Z_SIZE, COUNT))
- print(' FuelLevel (current/needed)')
- print(' = ',turtle.getFuelLevel(),'/',minFuelLevel)
- while true do
- if fuelItUp() == false then return false end
- if isHomePosition() == false then
- print("As I'm not the HomePosition, Terminated. ")
- break
- end
- print('Starting harvest!')
- turtle.select(1)
- harvest()
- backToChest()
- dropItems(1,16)
- print('Finished!')
- sleep(1200)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement