Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local status = 0
- -- 0 = Returning, 1 = Maintenance, 2 = Farming, 3 = Critical
- local n = 0
- local j = 0
- --todo fix return, fix farm
- -- Refuels the turtle if fuel levels are low
- function Refuel() --fin?
- print("Refueling..")
- turtle.select(1)
- if not turtle.refuel(3) then
- print("Fuel reserves low.. Returning home")
- status = 0
- end
- end
- -- Grabs fuel from fuelchest above the turtle, drops anything in slot 1 if it's not coal
- function GrabFuel() --fin?
- if turtle.getItemCount(1) > 0 then
- if turtle.getItemDetail(1).name ~= "minecraft:coal" then
- print("That's not fuel.. Ew!")
- turtle.select(1)
- turtle.drop()
- end
- end
- if turtle.getItemCount(1) < 16 and status == 1 then
- print("Grabbing Fuel..")
- turtle.select(1)
- turtle.suckUp()
- end
- end
- -- Makes sure it has seeds in inventory, then dumps everything else
- function DropOff() --fin?
- for i = 2, 16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name ~= "minecraft:seed" then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- turtle.turnLeft()
- for i = 2, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.suck()
- turtle.suck()
- turtle.turnRight()
- end
- -- Inspects the block infront, above or below the turtle.
- function GetBlock(side) -- fin
- if side == 1 then
- local s, d = turtle.inspect()
- if s then return d else return false end
- elseif side == 2 then
- local s, d = turtle.inspectUp()
- if s then return d else return false end
- elseif side == 3 then
- local s, d = turtle.inspectDown()
- if s then return d else return false end
- end
- end
- -- Returns the turtle to the station
- function Return() --fin?
- if status == 0 then
- local front = GetBlock(1)
- if front and front.name == "immersiveengineering:metal_decoration1" then
- turtle.turnLeft()
- elseif front and front.name == "minecraft:hardened_clay" then
- turtle.turnLeft()
- turtle.forward()
- elseif front and front.name == "minecraft:chest" then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.down()
- turtle.back()
- status = 1
- else
- turtle.forward()
- end
- end
- end
- function GetSeedCount()
- return turtle.getItemCount(2), turtle.getItemCount(3)
- end
- function Replant()
- local seed1, seed2 = GetSeedCount()
- for i=2,3 do
- if seed1 > 0 then
- print("Found seed1")
- turtle.select(2)
- turtle.placeDown()
- elseif seed2 > 0 then
- print("Found seed2")
- turtle.select(3)
- turtle.placeDown()
- end
- end
- end
- -- Checks if plant is ready to be harvested, or if soil needs retilling/replanting
- function CheckPlant()
- print("Inspecting farmland..")
- local under = GetBlock(3)
- if not under then
- print("Retilling..")
- turtle.digDown()
- Replant()
- elseif under.name == "minecraft:wheat" and under.metadata == 7 then
- print("Found mature plant, harvesting..")
- turtle.placeDown()
- turtle.sleep(0.1)
- turtle.suckDown()
- end
- end
- function Farm()
- -- Are we full yet?
- local front = GetBlock(1)
- if turtle.getItemCount(16) > 0 then
- status = 0
- elseif not front then
- turtle.forward()
- CheckPlant()
- elseif front.name == "immersiveengineering:metal_decoration1"
- or front.name == "minecraft:hardened_clay" then
- CheckPlant()
- if j == 0 then
- j = 1
- turtle.turnLeft()
- turtle.forward()
- CheckPlant()
- turtle.turnLeft()
- elseif j == 1 then
- j = 0
- turtle.turnRight()
- if front.name == "immersiveengineering:metal_decoration1"
- and front.name == "minecraft:hardened_clay" then
- status = 0
- n = n + 1
- else
- turtle.forward()
- CheckPlant()
- turtle.turnRight()
- end
- end
- end
- end
- -- Main Loop
- while true do
- if turtle.getFuelLevel() < 10 then
- Refuel()
- end
- if status == 0 then
- print("Finding home..")
- Return()
- end
- if status == 1 then
- print("Refueling.. Storing.. Polishing..")
- DropOff()
- GrabFuel()
- print("Maintenance completed!")
- turtle.forward()
- turtle.up()
- status = 2
- if n % 2 == 0 and n > 0 then
- for i = 1,5 do
- print("Waiting: " .. 5-i .. " seconds for the plants to grow..")
- sleep(1)
- end
- n = 1
- end
- end
- if status == 2 then
- print("Farming..")
- Farm()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement