Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Farming script V2 by Mathias
- -- Variables
- crop = "wheat"
- seed = "wheat_seeds"
- xpos = 1
- ypos = 1
- xlock = false
- ylock = false
- -- Functions
- function organize()
- local inventory = {}
- local slot
- for i = 1,16 do
- if (turtle.getItemDetail(i)) then
- data = turtle.getItemDetail(i)
- data["slot"] = i
- data.name = data.name:gsub("minecraft:","")
- if (data.name == seed) then
- table.insert(inventory,data)
- end
- end
- end
- for key, value in pairs(inventory) do
- if (key ~= 1 and inventory[1].count < 64) then
- turtle.select(inventory[key].slot)
- turtle.transferTo(inventory[1].slot)
- inventory[1].count = inventory[1].count + inventory[key].count
- end
- end
- end
- function depo()
- turtle.turnLeft()
- if (turtle.getItemDetail(1)) then
- local data = turtle.getItemDetail(1)
- data.name = data.name:gsub("minecraft:","")
- if (data.name ~= seed) then
- turtle.select(1)
- turtle.drop()
- end
- end
- for i = 2,16 do
- if (turtle.getItemDetail(i)) then
- data = turtle.getItemDetail(i)
- data.name = data.name:gsub("minecraft:","")
- turtle.select(i)
- if (data.name == seed) then
- turtle.transferTo(1)
- else
- turtle.drop()
- end
- end
- end
- turtle.turnRight()
- end
- function check()
- if (turtle.inspectDown()) then
- local block, type = turtle.inspectDown()
- type.name = type.name:gsub("minecraft:","")
- return type
- else
- local type = {name = "empty",metadata = 0}
- return type
- end
- print(block.name)
- end
- function plant()
- turtle.digDown()
- for i = 1,16 do
- if (turtle.getItemDetail(i)) then
- local data = turtle.getItemDetail(i)
- data.name = data.name:gsub("minecraft:","")
- if (data.name == seed) then
- turtle.select(i)
- turtle.placeDown()
- break
- end
- end
- end
- end
- function checkDown()
- turtle.down()
- result = check()
- turtle.up()
- if (result.name == "dirt") then
- plant()
- elseif (result.name == "water" or result.name == "flowing_water") then
- -- keep moving
- else
- if (xlock == false) then
- xlock = true
- else
- ylock = true
- end
- end
- end
- function decisions()
- result = check()
- if (turtle.getFuelLevel() <= 0) then
- while (true) do
- turtle.turnLeft()
- end
- elseif (result.name == crop) then
- if (result.metadata == 7) then
- plant()
- end
- elseif (result.name == "empty") then
- checkDown()
- else
- print("Confusion while making decisions")
- end
- end
- function declareGrid()
- while (xlock == false) do
- decisions()
- if (xlock == false) then
- turtle.back()
- xpos = xpos + 1
- else
- turtle.forward()
- xpos = xpos - 1
- end
- end
- turtle.turnLeft()
- while (ylock == false) do
- decisions()
- if (ylock == false) then
- turtle.back()
- ypos = ypos + 1
- else
- ypos = ypos - 1
- print("Farming a "..ypos.."x"..xpos.." area")
- for i = 1, ypos do
- turtle.forward()
- end
- turtle.turnRight()
- for i = 2, xpos do
- turtle.forward()
- end
- end
- end
- end
- function turn(direction)
- if (direction % 2 == 0) then
- turtle.turnRight()
- turtle.back()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.back()
- turtle.turnLeft()
- end
- end
- function goHome(_xpos, _ypos)
- if (_ypos % 2 == 0) then
- turtle.turnLeft()
- for i = 2,_xpos do
- turtle.back()
- end
- turtle.turnRight()
- else
- turtle.turnRight()
- for i = 2,_ypos do
- turtle.back()
- end
- turtle.turnRight()
- for i = 2, _xpos do
- turtle.back()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- function xpath(_xpos)
- for i = _xpos, (xpos-1) do
- decisions()
- if (_xpos ~= xpos) then
- turtle.back()
- end
- end
- decisions()
- end
- function pathing()
- for i = 1, ypos do
- xpath(1)
- if (i ~= ypos) then
- turn(i)
- end
- end
- end
- function Main()
- declareGrid()
- depo()
- while (true) do
- pathing()
- goHome(xpos,ypos)
- organize()
- depo()
- sleep(75)
- end
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement