Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- length = args[1]
- width = args[2]
- print("Fuel level:", turtle.getFuelLevel())
- stopRequired = false
- function preparation ()
- --refuel
- print("refueling...")
- turtle.select(1)
- turtle.suck(64)
- turtle.refuel()
- turtle.drop(turtle.getItemCount())
- --get seed
- print("getting seed...")
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.select(1)
- turtle.suck(10)
- --move into start position
- print("moving to start pos..")
- turtle.turnLeft()
- print("turning left..")
- turtle.forward()
- print("moving forward..")
- turtle.turnRight()
- print("turning right..")
- turtle.forward()
- print("moving forward..")
- turtle.forward()
- print("moving forward..")
- end
- -- harvest
- function harvestPlant ()
- local success, data = turtle.inspectDown()
- if success then
- local blockName = data.name
- local state = data.state or {}
- -- debug?
- print("Block name:", blockName)
- for k, v in pairs(state) do
- print(k, v)
- end
- if blockName == "supplementaries:flax" then
- local growthStage = state.age or 0
- if growthStage == 7 then
- turtle.digDown()
- plantNew()
- end
- end
- end
- end
- -- plant
- function plantNew ()
- turtle.down()
- local slotSelected = 0
- turtle.select(1)
- slotSelected = 1
- if turtle.getItemCount(1) < 1 then
- slotSelected = slotSelected + 1
- if slotSelected > 17 then
- turtle.select(slotSelected)
- else
- print("turtle is empty")
- turtle.select(1)
- turtle.up()
- turtle.up()
- stopRequired = true
- end
- else
- turtle.placeDown()
- turtle.up()
- end
- end
- -- dump inventory
- function dumpInv ()
- print("Beginning dump sequence...")
- turtle.select(2)
- dumping = true
- while dumping == true do
- if turtle.compareTo(1) then
- if turtle.getSelectedSlot() < 16 then
- turtle.select(turtle.getSelectedSlot() + 1)
- else
- dumping = false
- end
- end
- turtle.dropDown()
- if turtle.getSelectedSlot() < 16 then
- turtle.select(turtle.getSelectedSlot() + 1)
- else
- dumping = false
- end
- end
- --reposition for seed dump
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.down()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- --seed dump
- print("Dumping seeds...")
- turtle.select(1)
- while turtle.getSelectedSlot() < 16 do
- turtle.drop()
- turtle.select(turtle.getSelectedSlot() + 1)
- end
- turtle.select(1)
- --reposition for new round
- print("Repositioning...")
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- -- movePlan
- function movePlan (length, width)
- turtle.up()
- turtle.up()
- turtle.forward()
- for i=1, width,1 do
- for i=1, length,1 do
- harvestPlant()
- turtle.forward()
- end
- moveBack(length)
- end
- turtle.turnRight()
- for i=1, width,1 do
- turtle.forward()
- end
- turtle.forward()
- turtle.forward()
- turtle.down()
- dumpInv()
- end
- -- backtrack
- function moveBack (n)
- print("Line complete, backtracking...")
- for i=1, n,1 do
- turtle.back()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end
- -- argument handling
- if length == "-help" then
- print("usage is [harvester x y] where x is the length of the field to be harvested and y is the width.")
- print("the script assumes a pre-planted field, and will only bring 10 extra seeds.")
- elseif width then
- -- main
- while stopRequired == false do
- preparation()
- if turtle.getFuelLevel() < 10 then
- stopRequired = true
- end
- movePlan(length, width)
- print("waiting for 180 seconds...")
- os.sleep(180)
- end
- else
- print("Invalid argument, see -help.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement