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

Question

hello, 

I have been having some issues with creating a functional tree farm using a robot, and i was wondering if anyone was able to lend me a hand and help me try to work this out or create a program for me.

i want it to place a sapling then detect when the tree has grown and start to remove the logs once it gets to the top place a sapling since there is no longer one there and wait for the tree to grow again. there is no need for it to remove all the leaves as i have a collection method in place already for this and large trees wont happen as i have blocks above it to prevent huge trees.

 

Thanks :D

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 1

Here is a Lua script for a basic 6x6 tree farm.

Try inspecting the script to figure out how it works and modifying the script to your liking.

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 improved farm script.
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
Answer this question...

×   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.