Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Very basic oak tree farming lua script for the turtles from the Computercraft mod
- -- Requires specific setup for tree growth, turtle position, refueling, restocking and unloading of wood
- -- Performs the farming of the wood
- function farm()
- -- Mines down
- turtle.digDown()
- for i=0,4 do
- turtle.down()
- turtle.digDown()
- end
- -- Places sapling
- turtle.placeDown()
- -- Returns to position
- for i=0,4 do
- turtle.up()
- end
- end
- -- Performs the unloading of the wood
- function unload_wood()
- -- Selects the 3rd item slot within the turtle, the 3rd item slot is where the wood should be
- turtle.select(3)
- -- Drops the wood into the chest inventory above itself
- turtle.dropUp()
- -- Selects the 1st item slot ready for planting saplings
- turtle.select(1)
- end
- -- Performs the refueling of the turtle
- function refuel()
- -- Selects the 2nd item slot within the turtle, the 2nd item slot should contain the fuel source for the turtle
- turtle.select(2)
- -- Moves forward under the hopper and chest used to store the fuel source
- turtle.forward()
- -- Waits for the collection of 32 items of fuel
- while turtle.getItemCount(2) < 32 do
- os.sleep(0.1)
- end
- -- Once 32 items have be collected, returns to position
- turtle.back()
- -- Consumes the fuel
- turtle.refuel()
- -- Selects the 1st item slot ready for planting sapligns
- turtle.select(1)
- end
- -- Performs the restocking of saplings
- function restock()
- -- Moves backward under the hopper and chest used to store saplings
- turtle.back()
- -- Waits for the collection of 32 saplings
- while turtle.getItemCount(1) < 32 do
- os.sleep(0.1)
- end
- -- Returns back to position
- turtle.forward()
- end
- -- Main loop
- while true do
- -- Checks if fuel level is low
- if turtle.getFuelLevel() < 15 then
- -- If it's low, calls the refuel function
- refuel()
- end
- -- Checks if sapling count is low (item count from slot 1)
- if turtle.getItemCount(1) < 5 then
- -- If it's low, calls restock function
- restock()
- end
- -- Checks if a tree has grown by detecting whether or not a blocks is beneath it (the top of the tree)
- if turtle.detectDown() then
- -- If the tree has grown, calls farm function
- farm()
- -- once tree has been farmed and returned to position, calls unload_wood function
- unload_wood()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment