Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local arg1, arg2 = ...
- limX = tonumber(arg1)
- limZ = tonumber(arg2)
- area = limX * limZ
- relX = 0
- relZ = 0
- facing = 0
- function plant()
- seedSlot = selectSeeds()
- if seeds == 0
- then
- print("Seeds not found.")
- return false
- end
- turtle.select(seedSlot)
- placed = turtle.placeDown()
- return placed
- end
- function selectSeeds()
- for i = 1, 16, 1
- do
- turtle.select(i)
- data = turtle.getItemDetail()
- if data
- then
- name = turtle.getItemDetail().name
- if name == "minecraft:wheat_seeds"
- then
- return i
- end
- end
- end
- return 0
- end
- function harvest()
- if turtle.detectDown()
- then
- local success, data = turtle.inspectDown()
- if data.name == "minecraft:wheat"
- then
- if data.metadata == 7
- then
- turtle.digDown()
- end
- end
- end
- end
- function turnTo(dir)
- if facing > dir
- then
- turtle.turnRight()
- facing = facing - 1
- turnTo(dir)
- end
- if facing < dir
- then
- turtle.turnLeft()
- facing = facing + 1
- turnTo(dir)
- end
- if facing == dir
- then
- return
- end
- end
- function goUp()
- turnTo(0)
- turtle.forward()
- relZ = relZ + 1
- end
- function goDown()
- turnTo(2)
- turtle.forward()
- relZ = relZ - 1
- end
- function goLeft()
- turnTo(1)
- turtle.forward()
- relX = relX - 1
- end
- function goRight()
- turnTo(3)
- turtle.forward()
- relX = relX + 1
- end
- function printPos()
- print("Walking Pos (", tostring(relX), ", ", tostring(relZ), ").\n")
- end
- function walkField()
- while relZ < limZ
- do
- goUp()
- printPos()
- harvest()
- plant()
- while relX < limX
- do
- goRight()
- printPos()
- harvest()
- plant()
- end
- if relZ < limZ
- then
- goUp()
- printPos()
- harvest()
- plant()
- while relX > 1
- do
- goLeft()
- printPos()
- harvest()
- plant()
- end
- end
- end
- end
- function returnToOrigin()
- while relX > 0
- do
- goLeft()
- end
- while relZ > 0
- do
- goDown()
- end
- end
- function depositItems()
- for i = 1, 16, 1
- do
- turtle.select(i)
- turtle.drop()
- end
- end
- function grabSeeds()
- i = 1
- remaining = area
- while remaining > 64
- do
- turtle.select(i)
- turtle.suckDown(64)
- i = i + 1
- remaining = remaining - 64
- end
- turtle.suckDown(remaining)
- end
- function feedFuel()
- print("Refueling...")
- turnTo(3)
- while (turtle.getFuelLevel() < 2000)
- do
- turtle.suck(4)
- turtle.refuel(4)
- end
- print("Complete.\n")
- end
- function execute()
- feedFuel()
- grabSeeds()
- walkField()
- returnToOrigin()
- depositItems()
- turnTo(0)
- end
- function main()
- while (true)
- do
- os.queueEvent("fakeEvent")
- os.pullEvent()
- if redstone.getInput("left")
- then
- execute()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement