Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Author: TheOriginalBIT
- Version: 1.0
- Created: 13 Dec 2012
- Last Update: 13 Dec 2012
- License:
- COPYRIGHT NOTICE
- Copyright © 2012-2013 Joshua Asbury a.k.a TheOriginalBIT [theoriginalbit@gmail.com]
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- associated documentation files (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- copies of the Software, and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- -Visible credit is given to the original author.
- -The software is distributed in a non-profit way.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ]]--
- --[[
- Variables you may change
- ]]
- saplingSlot = 1
- bonemealSlot = 2 -- This is only compatible with TurtleOS 1.4 and above
- woodSlot = 3 -- This is just starting dig slot, used to compare
- deployBonemealSide = "bottom" --[[ Should be: any side without peripheral or the front. Must have wire connecting to something that can deploy bonemeal i.e. RedPower Deployer
- This setting is for TurtleOS 1.3 only. ]]
- retainItems = false -- For TurtleOS 1.3 compatibilit
- itemDropOffSide = "left" --[[ Should be: left, right, up, down, back (cannot be front as thats where tree must grow)
- For TurtleOS 1.4 can be chest or RedPower Relay, etc, 1.3 must be something such as Buildcraft obsidian pipe or transposer NOT directly infront ]]
- --[[
- Program Code
- Note: Anything you change beyond this point may cause undesireable effects.
- I (TheOriginalBIT) in no way take responsibility for any damage done by
- misuse or changing of this code. But please do feel free to change if you
- wish.
- ]]
- tArgs = {...}
- local function checkInventory()
- x, y = term.getCursorPos()
- while turtle.getItemCount(saplingSlot) == 0 do
- term.setCursorPos(x,y)
- print("Waiting for saplings in slot 1")
- sleep(0.1)
- end
- end
- local function place(slot)
- turtle.select(slot)
- turtle.place()
- end
- local function deployBonemeal()
- rs.setOutput(deployBonemealSide, true)
- sleep(0.1)
- rs.setOutput(deployBonemealSide, false)
- end
- local function waitForSaplingGrowth()
- turtle.select(saplingSlot)
- x, y = term.getCursorPos()
- if (turtle.getItemCount(saplingSlot) == 0) then
- print("No sapling to compare to.\nNo way to check growth.\nQuiting")
- error()
- end
- while turtle.compare() do
- if (turtle.getItemCount(bonemealSlot) > 0) then
- if (osVersion >= 1.4) then
- place(bonemealSlot)
- elseif (osVersion == 1.3) then
- deployBonemeal()
- end
- turtle.select(saplingSlot)
- end
- term.setCursorPos(x,y)
- print("Waiting for sapling to grow.")
- sleep(0.1)
- end
- print("Sapling has grown.")
- end
- local function forward()
- turtle.select(woodSlot)
- turtle.dig()
- if (not turtle.forward() and not turtle.detect()) then
- print("I think I'm out of fuel and for OS compatibility reasons I cant check.")
- error()
- end
- end
- local function up()
- turtle.select(woodSlot)
- while turtle.compareUp() do
- turtle.digUp()
- if (not turtle.up() and not turtle.detectUp()) then
- print("I think I'm out of fuel and for OS compatibility reasons I cant check. On next run usage: "..shell.getRunningProgram().." home")
- error()
- end
- sleep(0.1)
- end
- if (turtle.detectUp()) then -- this makes sure the top leaves are removed to allow big tree growth
- turtle.digUp()
- end
- end
- local function removeTree()
- print("Removing tree.")
- forward()
- up()
- end
- local function returnHome()
- while not turtle.detectDown() do
- if (not turtle.down()) then
- print("I think I'm out of fuel and for OS compatibility reasons I cant check. On next run usage: "..shell.getRunningProgram().." home")
- error()
- end
- sleep(0.1)
- end
- if (not turtle.back()) then
- print("I think I'm out of fuel and for OS compatibility reasons I cant check. On next run usage: "..shell.getRunningProgram().." home")
- error()
- end
- end
- local function emptyInventory()
- for i = 1, tonumber(slotCount), 1 do
- if (i ~= saplingSlot or (osVersion == 1.3 and i ~= bonemealSlot)) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- local function dropOffItems()
- if (itemDropOffSide == "up") or (itemDropOffSide == "down") then
- emptyInventory()
- return
- end
- funcTo = turtle.turnLeft
- funcBack = turtle.turnRight
- if (itemDropOffSide == "right") then
- funcTo = turtle.turnRight
- funcBack = turtle.turnLeft
- end
- if (itemDropOffSide == "back") then funcTo() end
- funcTo()
- emptyInventory()
- if (itemDropOffSide == "back") then funcFrom() end
- funcFrom()
- end
- local function run()
- while true do
- checkInventory()
- place(saplingSlot)
- if (osVersion >= 1.4) then
- place(bonemealSlot)
- elseif (osVersion == 1.3) then
- deployBonemeal()
- end
- waitForSaplingGrowth() -- This is just incase its out of bonemeal
- removeTree()
- returnHome()
- if (not retainItems) then
- dropOffItems()
- end
- sleep(0.1)
- end
- end
- if (not turtle) then
- print("Sorry but this can only run on a turtle.")
- return
- end
- osVersion = os.version()
- osVersion = tonumber(string.sub(osVersion, string.len(osVersion) - 3, string.len(osVersion)))
- print("Running on TurtleOS "..osVersion)
- if (osVersion < 1.3) then
- print("Unable to run on this OS. Requires TurtleOS 1.3 or higher.")
- return
- elseif (osVersion > 1.4) then
- print("Sorry TurtleOS "..osVersion.." is not supported by this version. Please check for an update.")
- return
- end
- if ((#tArgs == 1) and (tArgs[1] == "home")) then
- returnHome()
- elseif ((#tArgs == 1) and (tArgs[1] ~= "home")) then
- print("Usage: "..shell.getRunningProgram())
- print("Usage: "..shell.getRunningProgram().." home")
- return
- end
- term.clear()
- term.setCursorPos(1,1)
- slotCount = 9
- if (osVersion == 1.4) then
- slotCount = 16
- write("Have you put fuel in me? ")
- answer = read()
- if (tolower(answer) ~= "yes") then
- print("\nPlease refuel me and run again.")
- return
- end
- end
- print(slotCount)
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement