Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local robot = require("robot")
- local sides = require("sides")
- local geolyzer = component.geolyzer
- local inventory_controller = component.inventory_controller
- term.write("Enter length (number): ")
- local length = term.read()
- term.write("Enter width (number): ")
- local width = term.read()
- local right = true
- function turn()
- if (right) then robot.turnRight() else robot.turnLeft() end
- end
- function tryForward()
- if (not robot.forward()) then tryForward() end
- end
- function isSelectingSeed()
- local selectedItem = inventory_controller.getStackInInternalSlot()
- return (selectedItem and selectedItem.name == "minecraft:wheat_seeds")
- end
- function plant()
- local lastSlot = robot.inventorySize()
- robot.select(lastSlot)
- robot.dropDown(robot.count())
- inventory_controller.equip()
- if (not isSelectingSeed()) then
- local i = 1
- while true do
- robot.select(i)
- if (isSelectingSeed()) then
- break
- end
- if (i == lastSlot) then
- i = 1
- else
- i = i + 1
- end
- end
- end
- inventory_controller.equip()
- robot.useDown()
- end
- function farm()
- robot.select(1)
- local block = geolyzer.analyze(sides.bottom)
- if (block.growth == 1 and block.name == "minecraft:wheat") then
- robot.swingDown()
- plant()
- end
- end
- function moveX(j)
- for i = length, 1, -1 do
- farm()
- if (i > 1) then
- tryForward()
- elseif (j > 1) then
- turn()
- farm()
- tryForward()
- turn()
- end
- end
- end
- function moveY()
- for i = width, 0, -1 do
- if (i > 0) then
- moveX(i)
- right = not right
- end
- end
- robot.turnAround()
- right = not right
- end
- while true do
- moveY()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement