Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function performPlanting()
- -- get seeds
- turtle.suck()
- -- move to the initial planting position
- moveToPlant()
- -- perform planting
- plantFarm(6,9)
- -- return to home
- returnHome()
- end
- function moveToPlant()--{{{
- turtle.turnRight()
- forward(2)
- moveUp(4)
- turtle.turnRight()
- forward(2)
- turtle.turnRight()
- forward(2)
- end--}}}
- function plantFarm(rowLength, rows, direction)--{{{
- if direction == nil then
- direction = "right"
- end
- for row = 1, rows do
- for count = 1, rowLength do
- -- plant crop
- turtle.placeDown()
- -- move forward
- forward()
- end
- if row ~= rows then
- -- turn at end of row
- turtle.placeDown()
- if direction == "right" then
- turtle.turnRight()
- forward(1)
- turtle.turnRight()
- direction = "left"
- else
- turtle.turnLeft()
- forward(1)
- turtle.turnLeft()
- direction = "right"
- end
- end
- end
- end--}}}
- function returnHome()--{{{
- turtle.placeDown()
- turnAround()
- forward(8)
- turtle.turnRight()
- forward(6)
- moveDown(4)
- turtle.turnRight()
- forward(2)
- turtle.turnRight()
- end--}}}
- function forward(distance)--{{{
- if distance == nil then
- distance = 1
- end
- for count = 1, distance do
- local moved = false
- while not moved do
- moved = turtle.forward()
- end
- end
- end--}}}
- function moveUp(distance)--{{{
- if distance == nil then
- distance = 1
- end
- for count = 1, distance do
- local moved = false
- while not moved do
- moved = turtle.up()
- end
- end
- end--}}}
- function moveDown(distance)--{{{
- if distance == nil then
- distance = 1
- end
- for count = 1, distance do
- local moved = false
- while not moved do
- moved = turtle.down()
- end
- end
- end--}}}
- function turnAround()--{{{
- turtle.turnRight()
- turtle.turnRight()
- end--}}}
- local redstoneEventCount = 0
- local justPlanted = false
- turtle.select(1)
- while true do
- eventName, event1, event2, event3 = os.pullEvent("redstone")
- if eventName == "redstone" then
- if justPlanted == false then
- redstoneEventCount = redstoneEventCount + 1
- else
- justPlanted = false
- end
- print("Redstone Event Count == " .. redstoneEventCount)
- if redstoneEventCount == 2 then
- print("Waiting for seeds")
- os.sleep(10)
- print("Planting")
- performPlanting()
- print("finished planting")
- redstoneEventCount = 0
- justPlanted = true
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement