This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Camwarp's profile picture

DrumOS V1.2 Wood Chopper Variation {Feat theoriginalbit}

Started by Camwarp, 11 April 2013 - 04:46 AM
Camwarp #1
Posted 11 April 2013 - 06:46 AM
This code Is Compatible With The DrumOS Version 1.2 Launch Command I Didn't Write The Woodchopper Code But I Put In Proper Credit To The Original Creator.


local senderId, message, distance = rednet.receive()
rednet.receive( 200 )
if
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()
Please Leave Comments
Original Creator thelittlebit
Camwarp #2
Posted 11 April 2013 - 09:25 AM
I need Someone To Check Over This Code Please