Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --DONE: Check Fuel level
- --DONE: Pickup Fuel
- --DONE: Refuel
- --DONE: Pickup Saplings
- --DONE: Pickup Bonemeal
- --DONE: Left or Right orientation
- --TODO: Plant Saplings
- --TODO: Use Bonemeal
- --TODO: Chop bottom blocks
- --TODO: Chop till top
- --TODO: Return to start
- --DONE: Drop-off everything
- --DONE: Wait x minutes
- --TODO: Restart after server down
- function printUsage()
- print("Usage:")
- print("WoodFarm")
- print("Everyting else will be done automatically..")
- print("If there is a 10x10 fenced area, and all chests are sitting where they should.")
- print("Drop-off chest, Fuel chest, Saplings chest, Bonemeal chest.")
- end
- function turnRight()
- turtle.turnRight()
- o = o + 1
- -- we want to stay between 0 and 4
- if o > 3 then
- o = o % 4
- end
- end
- function turnLeft()
- turtle.turnLeft()
- o = o - 1
- if o < 0 then
- o = o + 4
- end
- end
- function forward()
- turtle.forward()
- o = o % 4
- if o == 0 then
- x = x + 1
- elseif o == 1 then
- y = y + 1
- elseif o == 2 then
- x = x - 1
- elseif o == 3 then
- y = y - 1
- else
- -- Not good
- error()
- end
- end
- function goToCenter()
- end
- function returnHome()
- print("Returning home...")
- print("x = " .. x)
- print("y = " .. y)
- print("z = " .. z)
- print("o = " .. o)
- if x > 0 then
- print("1")
- while o ~= 2 do
- turnRight()
- end
- elseif x < 0 then
- print("2")
- while o ~= 0 do
- turnRight()
- end
- else
- print("3")
- --nothing?
- end
- while x ~= 0 do
- print("4")
- forward()
- end
- if y > 0 then
- print("5")
- print("Go left")
- while o ~= 3 do
- print("6")
- turnRight()
- end
- elseif y < 0 then
- print("7")
- print("Go right")
- while o ~= 1 do
- print("8")
- turnRight()
- end
- else
- print("9")
- --nothing?
- end
- while y ~= 0 do
- print("10")
- forward()
- end
- while o ~= 0 do
- print("11")
- turnRight()
- end
- end
- function moveToSide()
- if orientation == "right" then
- turnRight()
- forward()
- turnLeft()
- return
- elseif orientation == "left" then
- turnLeft()
- forward()
- turnRight()
- return
- else
- print("Shouldn't be here!")
- end
- error()
- end
- -- check if fuel is below 10000, and add fuel if so
- function checkAndReFuel()
- -- go to fuel chest
- moveToSide()
- if turtle.getFuelLevel() >= 10000 then
- return
- end
- -- we should be by the fuel chesst
- if not turtle.detect() then
- print("Nothing to get fuel from")
- error()
- end
- while turtle.getFuelLevel() < 20000 do
- pickup = false
- turtle.select(1)
- while not pickup do -- let's try untill we get something
- pickup = turtle.suck()
- end
- turtle.select(1)
- if not turtle.refuel() then
- print("No fuel in the fuel chest!")
- error()
- end
- end
- end
- -- find out if we go left or right
- function checkOrientation()
- if not orientation == nil then
- return
- end
- turnRight()
- if turtle.detect() then
- print("There is something to the right.. Let's try left.")
- else
- print("The right is free! We found our orientation!")
- orientation = "right"
- turnLeft()
- return
- end
- turnLeft()
- turnLeft()
- if turtle.detect() then
- print("There is something to the left aswell.. WTF!")
- else
- print("The left is free! We found our orientation!")
- orientation = "left"
- turnRight()
- return
- end
- -- if we get here we are lost
- error()
- end
- -- place items in chest
- function dropOff()
- if not turtle.detect() then
- print("There is nothing in front..! Halp!")
- error()
- end
- for slot = 1, 16 do
- dropped = false
- turtle.select(slot)
- if turtle.getItemCount(slot) > 0 then
- while not dropped do -- lets try this untill success
- dropped = turtle.drop()
- end
- end
- end
- end
- function pickup(something, slot, needed)
- -- go to next chest
- moveToSide()
- -- we should be by a chesst
- if not turtle.detect() then
- print("Nothing to get " .. something .. "from")
- error()
- end
- while turtle.getItemCount(slot) < needed do
- pickuped = false
- turtle.select(slot)
- while not pickuped do -- let's try untill we get something
- pickuped = turtle.suck()
- end
- end
- end
- function pickupSaplings()
- pickup("Sapling", 1, 4)
- end
- function pickupBonemeal()
- pickup("Bonemeal", 2, 1)
- end
- -- main fuction that stands for one cycle
- function woodFarm()
- dropOff() -- nice clean start
- checkOrientation() -- where do we want to go today
- checkAndReFuel() -- check fuel level and refill
- pickupSaplings() -- get some saplings
- pickupBonemeal() -- get some bonemeal
- -- goToCenter() -- walk to center
- returnHome() -- go to the start
- end
- -- ---------- Running programm ----------
- -- Check argument usage
- tArgs = { ... }
- if #tArgs ~= 0 then
- printUsage()
- return
- end
- -- Set params
- orientation = nil
- x = 0
- y = 0
- z = 0
- o = 0
- repeat
- if pcall(woodFarm) then
- -- nothing to report, sleep and start over.
- os.sleep(900)
- else
- print("Horrible nasty stuff happened.. Stopping program.")
- return
- end
- until false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement