Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local robot = component.robot
- local inv = component.inventory_controller
- local nav = component.navigation
- local geo = component.geolyzer
- local vector = require("vector")
- local side = require("sides")
- local slot = 1
- local startx, starty, startz = nav.getPosition()
- print("Enter Field Size:")
- local fieldsize = io.read()
- while true do
- farm(fieldsize)
- end
- local function harvest()
- if geo.analyze(side.bottom) == 7 then
- robot.swingDown()
- robot.suckDown()
- return true
- else
- return false
- end
- end
- local function plant()
- while not slot == 16 | inv.getStackInInternalSlot(slot) == "minecraft:wheat_seeds" do
- slot = slot + 1
- robot.select(slot)
- end
- if inv.getStackInInternalSlot(slot) == "minecraft:wheat_seeds" then
- robot.equip()
- robot.place(side.bottom)
- else
- return false
- end
- return true
- end
- local function faceNorth()
- local face = nav.getFacing()
- while not face == 2 do
- if face == 3 then
- robot.turnAround()
- end
- if face == 4 then
- robot.turnRight()
- end
- if face == 5 then
- robot.turnLeft()
- end
- end
- return true
- end
- local function faceSouth()
- local face = nav.getFacing()
- while not face == 3 do
- if face == 2 then
- robot.turnAround()
- end
- if face == 5 then
- robot.turnRight()
- end
- if face == 4 then
- robot.turnLeft()
- end
- end
- return true
- end
- local function faceEast()
- local face = nav.getFacing()
- while not face == 5 do
- if face == 4 then
- robot.turnAround()
- end
- if face == 2 then
- robot.turnRight()
- end
- if face == 3 then
- robot.turnLeft()
- end
- end
- return true
- end
- local function faceWest()
- local face = nav.getFacing()
- while not face == 4 do
- if face == 5 then
- robot.turnAround()
- end
- if face == 3 then
- robot.turnRight()
- end
- if face == 2 then
- robot.turnLeft()
- end
- end
- return true
- end
- local function goThere(gox, goz)
- local beginx, beginy, beginz = nav.getPosition()
- if beginx < gox then
- repeat
- faceEast()
- robot.forward()
- until beginx == gox
- elseif beginx > gox then
- repeat
- faceWest()
- robot.forward()
- until beginx == gox
- end
- if beginz < goz then
- repeat
- faceSouth()
- robot.forward()
- until beginz == goz
- elseif beginz > goz then
- repeat
- faceNorth()
- robot.forward()
- until beginz == goz
- end
- return true
- end
- local function chargeTest()
- local charge = computer.energy()
- local invslot = 0
- local freeslots = robot.inventorySize()
- if charge / computer.energy <= 0.1 then
- charge()
- return true
- else
- repeat
- slot = slot + 1
- robot.select(slot)
- if robot.count(slot) ~= 0 then
- freeslots = freeslots -1
- end
- until slot == robot.inventory.Size()
- if freeslots <= 2 then
- charge()
- return true
- end
- end
- end
- local function checkChestSide()
- local chestSide
- faceNorth()
- if not getInventorySize(0) == "no inventory" then
- chestSide = 0
- elseif not getInventorySize(1) == "no inventory" then
- chestSide = 1
- elseif not getInventorySize(2) == "no inventory" then
- chestSide = 2
- elseif not getInventorySize(3) == "no inventory" then
- chestSide = 3
- elseif not getInventorySize(4) == "no inventory" then
- chestSide = 4
- elseif not getInventorySize(5) == "no inventory" then
- chestSide = 5
- end
- return chestSide
- end
- local function charge()
- gothere(startx, startz)
- faceNorth()
- local shestside = checkChestSide()
- local chestsize = getInventorySize(chestside)
- local slot = 0
- while not slot == chestsize do
- slot = slot + 1
- select(slot)
- dropIntoSlot(chestside, slot)
- end
- while not computer.energy == computer.maxEnergy do
- os.sleep(100)
- end
- end
- local function farm(fieldsize)
- faceNorth()
- local endx = startx + fieldsize
- local endz = startz - fieldsize
- local currentx = startx
- local currentz = startz
- local currenty = 0
- repeat
- if not currentx == startx then
- faceNorth()
- robot.forward()
- end
- while not currentx == startx do
- faceWest()
- robot.forward()
- currentx, currenty, currentz = nav.getPosition()
- end
- repeat
- harvest()
- plant()
- faceEast()
- robot.forward()
- currentx, currenty, currentz = nav.getPosition()
- until currentx == endx
- until currentz == endz | chargeTest()
- charge()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement