Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Left chest: Seed
- -- Back chest: Product
- -- Right chest: Fuel
- -- Constants
- local seedSlot = 15
- local chestSlot = 16
- local NORTH = 1
- local EAST = 2
- local SOUTH = 3
- local WEST = 4
- -- States
- local loop = true
- local power = turtle.getFuelLevel()
- local selected = 1 -- Top left
- turtle.select(selected)
- local facing = NORTH
- local position = {}
- position.x = 1
- position.y = 1
- -- Turn right, incrementing facing
- local function TurnRight()
- facing = facing + 1
- if (facing > 4) then
- facing = 1
- end
- turtle.turnRight()
- end
- -- Turn left, decrementing facing
- local function TurnLeft()
- facing = facing - 1
- if (facing < 1) then
- facing = 4
- end
- turtle.turnRight()
- end
- -- Move forward, increment/decrement facing coordinate position
- local function MoveForward()
- if (facing == NORTH) then
- position.y = position.y + 1
- elseif (facing == EAST) then
- position.x = position.x + 1
- elseif (facing == SOUTH) then
- position.y = position.y - 1
- else
- position.x = position.x - 1
- end
- turtle.forward()
- end
- -- Find the direction towards the first farm plot
- local function Initialize()
- local facingChest = true
- turtle.select(chestSlot)
- facingChest = turtle.compare()
- while (facingChest) do
- turtle.turnRight()
- turtle.select(chestSlot)
- facingChest = turtle.compare()
- end
- facing = 1
- end
- -- Plant a crop, harvesting any existing plant and plowing
- local function PlantCrop()
- turtle.digDown()
- end
- local function Farm(x, y)
- --Initialize()
- MoveForward()
- while (loop) do
- print(string.format(
- "CURRENT POS (%s, %s)",
- position.x, position.y))
- if (position.y < y) then
- MoveForward()
- elseif (position.x < x) then
- TurnRight()
- TurnRight()
- while (position.x > 1) do
- MoveForward()
- end
- TurnLeft()
- MoveForward()
- TurnLeft()
- else
- loop = false
- end
- end
- end
- Farm(3, 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement