Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("turtleChest.lua")
- length = 9
- width = 14
- -- Define an array with plant names and their final growth stages
- local plants = {
- ["minecraft:wheat"] = 7,
- ["minecraft:carrots"] = 7,
- ["minecraft:potatoes"] = 7,
- ["minecraft:beetroots"] = 3,
- ["minecraft:nether_wart"] = 3,
- ["minecraft:cocoa"] = 2,
- ["minecraft:pumpkin_stem"] = 7,
- ["minecraft:melon_stem"] = 7,
- -- Add more plants if needed
- }
- local seeds = {
- ["minecraft:wheat_seeds"] = 7,
- ["minecraft:carrots"] = 7,
- ["minecraft:potatoes"] = 7,
- ["minecraft:beetroots"] = 3,
- ["minecraft:pumpkin_stem"] = 7,
- ["minecraft:melon_stem"] = 7,
- ["minecraft:nether_wart"] = 3,
- ["minecraft:cocoa"] = 2,
- ["minecraft:sweet_berry_bush"] = 3,
- }
- local function findItem(itemName)
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name == itemName then
- return slot
- end
- end
- return -1
- end
- -- Function to check if the plant is fully grown
- local function isFullyGrown(plantName, growthStage)
- -- Look up the plant in the array
- finalStage = plants[plantName]
- if finalStage then
- return growthStage == finalStage
- else
- return false
- end
- end
- function plantSeed()
- for seedName, _ in pairs(seeds) do
- slot = findItem(seedName)
- if slot ~= -1 then
- break
- end
- end
- if slot == -1 then
- return false
- else
- turtle.select(slot)
- turtle.placeDown()
- return true
- end
- end
- function harvest()
- turtle.digDown()
- if not plantSeed() then
- return false
- end
- return true
- end
- function growCheck()
- success, data = turtle.inspectDown()
- if success then
- plantName = data.name
- growthStage = data.state.age
- if isFullyGrown(plantName, growthStage) then
- return harvest()
- end
- end
- return true
- end
- function toStart(width, length)
- if length % 2 == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, width do
- turtle.forward()
- end
- end
- turtle.turnRight()
- for j = 2, length do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- function mineTop(width, length, plantName, growthStage)
- outofseed = false
- for i = 1, length do
- for j = 1, width do
- if not growCheck() then
- outofseed = true
- end
- turtle.dig()
- turtle.forward()
- end
- if i < length then
- if i % 2 == 1 then
- if not growCheck() then
- outofseed = true
- end
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- else
- if not growCheck() then
- outofseed = true
- end
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- return outofseed
- end
- function farm(width, length, plantName, growthStage)
- mineTop(width, length, plantName, growthStage)
- outofseed = growCheck()
- toStart(width, length)
- turtleChest.insertAll()
- turtle.turnLeft()
- end
- check = 0
- while true do
- -- Main program
- success, data = turtle.inspect()
- if success then
- plantName = data.name
- growthStage = data.state.age
- if isFullyGrown(plantName, growthStage) then
- check = check + 1
- if check == 1 then
- turtle.turnLeft()
- end
- end
- end
- if check == 2 then
- check = 0
- turtle.up()
- farm(length-1, width, plantName, growthStage)
- turtle.down()
- end
- end
Add Comment
Please, Sign In to add comment