Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local directions = {"north", "east", "south", "west"}
- local curDir = 1
- local function getDir()
- local file = fs.open("curDir", "r")
- if file then
- local savedDir = file.readAll()
- for k, dir in pairs(directions) do
- if savedDir == dir then
- curDir = k
- end
- end
- end
- end
- local function turn(dir)
- while directions[curDir] ~= dir do
- if turtle.turnRight() then
- curDir = curDir + 1
- if curDir == 5 then
- curDir = 1
- end
- local file = fs.open("curDir", "w")
- file.write(directions[curDir])
- file.flush()
- file.close()
- sleep(0.25)
- end
- end
- end
- local function startup()
- getDir()
- end
- local function clearInventory()
- turn("east")
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- if item.name ~= "minecraft:bone_meal" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- local function collectDrops()
- repeat
- until not turtle.suck()
- end
- local function growPlant()
- turn("north")
- repeat
- until not turtle.suckUp()
- local i2 = 0
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- if item.name == "minecraft:bone_meal" then
- turtle.select(i)
- repeat
- i2 = i2 + 1
- if i2 % 20 == 0 then
- collectDrops()
- end
- until not turtle.place()
- collectDrops()
- end
- end
- end
- end
- local function feedChicken()
- turn("south")
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- if item.name:match("chicken_food") then
- turtle.select(i)
- if not turtle.drop() then
- break
- end
- end
- end
- end
- end
- local function produceBoneMeal()
- turn("south")
- local hasBones = false
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- if item.name == "minecraft:bone" then
- hasBones = true
- end
- end
- end
- if not hasBones then
- turtle.suck()
- end
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item then
- if item.name == "minecraft:bone" then
- turtle.select(i)
- if not turtle.dropUp() then
- break
- end
- end
- end
- end
- end
- local function main()
- while true do
- feedChicken()
- clearInventory()
- growPlant()
- produceBoneMeal()
- end
- end
- startup()
- main()
Advertisement
Add Comment
Please, Sign In to add comment