Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Tag365

Robot Tree Farm

Recommended Posts

A basic tree farm for a robot. By default it will start a 6x6 tree farm but you can configure the amount of trees in the grid as well as how far each tree will be from each other.

Firstly, the robot must have an inventory upgrade so it can have an inventory so it can place and obtain blocks. The script makes the robot go up to eight blocks above the ground to take down the tree, so you may also need a hover upgrade which increases the amount of blocks the robot can go above from the ground. To get the script to plant the trees properly you must have put saplings in the first inventory slot of the robot. You should also have an axe as the tool to claim the wood faster obviously, make sure you put the axe where the wrench icon is in the inventory. Also, make sure you have a flat surface of dirt so the robot can move properly without being blocked and actually place the saplings.

To get the script on your computer, if you have an internet component installed execute "pastebin get cg1ieKUi autorun.lua" and the required autorun script will be downloaded, or if you are the server host get the script at http://www.pastebin.com/raw/cg1ieKUi and add the script to the root of the filesystem that hosts the operating system.

local robot = require("robot")
print("Robot tree farm started")

-- Select the first slot, which is supposed to have a sapling.
robot.select(1)

-- Change these to change the tree farm grid size or the distance between each tree in the grid.
local treesX = 6
local treesZ = 6
local distanceBetweenTrees = 5

-- Goes forward eventually, no matter if something is blocking the path at the moment.
local function GoForward()
	while true do
		local movedSuccessfuly = robot.forward()
		if movedSuccessfuly then
			break
		end
	end
end

-- Goes down eventually, no matter if something is blocking the path at the moment.
local function GoDown()
	while true do
		local movedSuccessfuly = robot.down()
		if movedSuccessfuly then
			break
		end
	end
end

-- Checks for a tree
local function CheckForTree()
	-- Check for a block
	if robot.detect() then
		robot.up()
		
		-- Attempt to detect a block above which will determine if the tree has grown.
		local blockFound = robot.detect()
		robot.down()
		
		-- Check tree has grown and if so then go up.
		if blockFound then
			for blocksToMoveUp = 1, 8 do
				-- Destroy the wood in front of the robot
				robot.swing()
				
				-- Check if there is a block above and if so then destroy the block.
				if robot.detectUp() then
					robot.swingUp()
				end
				
				-- Go up
				robot.up()
			end
			
			-- Move back down again
			for blocksToMoveDown = 1, 8 do
				GoDown()
			end
			
			-- Suck up stuff and go forward
			robot.suck()
			robot.suckUp()
			robot.suckDown()
			GoForward()
			
			-- Suck up stuff
			for rotation = 1, 4 do
				robot.turnLeft()
				robot.suck()
			end
			
			-- Go back
			robot.turnAround()
			GoForward()
			robot.turnAround()
			
			-- Place the new sapling here
			robot.place()
		end
	else
		-- There is no block here, place the sapling
		robot.place()
	end
end

-- Scans a row of trees.
local function CheckRowOfTrees()
	-- Check for trees in the X row.
	for treeX = 1, treesX do
		CheckForTree()
		
		-- If this isn't the last tree in the row then move to the next tree in the row.
		if treeX < treesX then
			robot.turnRight()
			for blocksToMove = 1, distanceBetweenTrees do
				GoForward()
				robot.suck()
			end
			robot.turnLeft()
		end
	end
	
	-- Go back to the first tree in the row.
	robot.turnLeft()
	for blocksToMove = 1, distanceBetweenTrees*(treesX - 1) do
		GoForward()
	end
	robot.turnRight()
end

-- Do the complete cycle.
while true do
	-- Go to each X row in the grid.
	for treeZ = 1, treesZ do
		CheckRowOfTrees()
		
		-- If this isn't the last X row in the grid then go to the next X row in the grid.
		if treeZ < treesZ then
			robot.turnRight()
			GoForward()
			robot.turnLeft()
			for blocksToMove = 1, distanceBetweenTrees do
				GoForward()
				robot.suck()
			end
			robot.turnLeft()
			GoForward()
			robot.turnRight()
		end
	end
	
	-- Go back to the starting position.
	robot.turnRight()
	GoForward()
	robot.turnRight()
	for blocksToMove = 1, distanceBetweenTrees*(treesZ - 1) do
		GoForward()
		robot.suck()
	end
	robot.turnRight()
	GoForward()
	robot.turnRight()
	
	-- Sleep for five seconds.
	os.sleep(5)
end
Edited by Tag365
Added additional information about how to get the script to on your computer.
Link to post
Share on other sites

Firstly, the robot must have an inventory upgrade so it can have an inventory so it can place and obtain blocks. The script makes the robot go up to eight blocks above the ground to take down the tree, so you may also need a hover upgrade which increases the amount of blocks the robot can go above from the ground. To get it to work you must have put saplings in the first inventory slot of the robot. You should also have an axe as the tool to claim the wood obviously, make sure you put the axe where the wrench icon is in the inventory. Also, make sure you have a flat surface of dirt so the robot can move properly without being blocked and actually place the saplings. I believe that is all the stuff you need to get it to work.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.