Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local state = 0
- -- 0 = Returning, 1 = Maintenance, 2 = Farming, 3 = Critical
- local n = 0
- -- Refuels the turtle if fuel levels are low
- function Refuel()
- print("Refueling..")
- if turtle.getFuelLevel() < 10 then
- turtle.select(1)
- if not turtle.refuel(3) then
- print("Fuel reserves low.. Returning home")
- status = 0
- end
- end
- end
- -- Grabs fuel from fuelchest under the turtle, drops anything in slot 1 if it's not coal
- function GrabFuel()
- 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.suckDown()
- end
- end
- -- Stores everything but fuel in the dropoff chest above the turtle
- function DropOff()
- n = n + 1
- for i=2,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.dropUp()
- end
- end
- end
- -- Collect that sweet hemp
- function Farm()
- -- Are we full yet?
- if turtle.getItemCount(16) > 0 then
- status = 0
- elseif GetBlock(1) == "immersiveengineering:metal_decoration1" then
- turtle.digDown()
- turtle.turnLeft()
- turtle.forward()
- turtle.digDown()
- turtle.turnLeft()
- else
- turtle.forward()
- turtle.digDown()
- end
- end
- -- Returns the turtle to the station
- function Return()
- if status == 0 then
- front = GetBlock(1)
- if front == "immersiveengineering:metal_decoration1" then
- turtle.turnLeft()
- elseif front == "minecraft:hardened_clay" then
- if GetBlock(3) == "minecraft:chest" then
- turtle.turnLeft()
- turtle.forward()
- turtle.down()
- turtle.down()
- turtle.back()
- status = 1
- else
- turtle.turnLeft()
- turtle.forward()
- end
- else
- turtle.forward()
- end
- end
- end
- -- Inspects the block infront, above or below the turtle.
- function GetBlock(side)
- if side == 1 then
- local s, d = turtle.inspect()
- if s then return d.name else return false end
- elseif side == 2 then
- local s, d = turtle.inspectUp()
- if s then return d.name else return false end
- elseif side == 3 then
- local s, d = turtle.inspectDown()
- if s then return d.name else return false end
- end
- end
- -- Main Loop
- while true do
- Refuel()
- 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()
- turtle.up()
- status = 2
- if n % 3 == 0 then
- for i = 1,60 do
- print("Waiting: " .. i .. " seconds for the plants to grow..")
- end
- end
- end
- if status == 2 then
- print("Searching for hemp..")
- Farm()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement