Changed the complete Farmtree Script. Now we're able to chop down a complete lane of trees
This commit is contained in:
		@@ -34,19 +34,4 @@ function selectEmptySlot()
 | 
				
			|||||||
  return false -- couldn't find empty space
 | 
					  return false -- couldn't find empty space
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- getItemFromChest(chestItem) selects
 | 
					 | 
				
			||||||
-- something from a chest in front of the turtle
 | 
					 | 
				
			||||||
-- and pushes it into the turtle.
 | 
					 | 
				
			||||||
function getItemFromChest(chestItem)
 | 
					 | 
				
			||||||
    sapling = peripheral.wrap('front') -- This find the chest at the front and allow you do things to it
 | 
					 | 
				
			||||||
    selectEmptySlot()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for slot, item in pairs(sapling.getAllStacks()) do
 | 
					 | 
				
			||||||
        if item.id == chestItem then
 | 
					 | 
				
			||||||
	    -- If the chest is on the north side of the turtle, the turtle is on the south side of the peripheral
 | 
					 | 
				
			||||||
	    sapling.pushItem('south', slot)
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,6 @@
 | 
				
			|||||||
--[[Tree Chopping program by Sascha
 | 
					--[[Tree Chopping program by Sascha
 | 
				
			||||||
Chops down the tree in front of turtle.]]
 | 
					Chops down the tree in front of turtle.]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if not turtle.detect() then
 | 
					 | 
				
			||||||
  error('Could not find tree!')
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print('Chopping tree...')
 | 
					print('Chopping tree...')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if not turtle.dig() then -- chop base of tree
 | 
					if not turtle.dig() then -- chop base of tree
 | 
				
			||||||
@@ -14,9 +10,7 @@ end
 | 
				
			|||||||
os.sleep(5) -- Wait until everything droppen from the tree
 | 
					os.sleep(5) -- Wait until everything droppen from the tree
 | 
				
			||||||
for j = 1, 4 do
 | 
					for j = 1, 4 do
 | 
				
			||||||
    for i = 1, 4 do
 | 
					    for i = 1, 4 do
 | 
				
			||||||
        if not turtle.suck() then -- Suck up all Wood
 | 
					        turtle.suck() -- Suck up everything
 | 
				
			||||||
	    print('Did not find something to suck')
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
	turtle.turnLeft()
 | 
						turtle.turnLeft()
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    turtle.forward()
 | 
					    turtle.forward()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,6 @@ os.loadAPI('hare.lua') -- Load the hare module
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local NUM_OF_TREES = 4
 | 
					local NUM_OF_TREES = 4
 | 
				
			||||||
local TREE_SAPLING = 'spruce'
 | 
					local TREE_SAPLING = 'spruce'
 | 
				
			||||||
local blockExists, item
 | 
					 | 
				
			||||||
local logCount = 0
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Check if choptree program exists
 | 
					-- Check if choptree program exists
 | 
				
			||||||
if not fs.exists('choptree.lua') then
 | 
					if not fs.exists('choptree.lua') then
 | 
				
			||||||
@@ -14,23 +12,26 @@ if not fs.exists('choptree.lua') then
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while true do
 | 
					while true do
 | 
				
			||||||
    -- First, empty the whole turtle
 | 
					   -- Check if turtle has enough fuel
 | 
				
			||||||
 | 
					    if turtle.getFuelLevel() < (2 * (3 * NUM_OF_TREES)) then
 | 
				
			||||||
 | 
						hare.selectItem('minecraft:' .. TREE_SAPLING .. 'log')
 | 
				
			||||||
 | 
						turtle.refuel(2)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    -- Empty everything except for the saplings
 | 
				
			||||||
    for i = 1, 16 do
 | 
					    for i = 1, 16 do
 | 
				
			||||||
 | 
						local item = turtle.getItemDetail(i)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
 | 
				
			||||||
	    turtle.select(i)
 | 
						    turtle.select(i)
 | 
				
			||||||
	    turtle.drop()
 | 
						    turtle.drop()
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					 | 
				
			||||||
    -- Check if turtle has enough fuel
 | 
					 | 
				
			||||||
    if turtle.getFuelLevel() < (2 * (3 * NUM_OF_TREES)) then
 | 
					 | 
				
			||||||
	hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_log')
 | 
					 | 
				
			||||||
	turtle.craft()
 | 
					 | 
				
			||||||
	hare.selectItem('minecraft:' .. TREE_SAPLING .. 'plan')
 | 
					 | 
				
			||||||
	turtle.refuel()
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    -- Take one stack of Saplings from the Chest
 | 
					 
 | 
				
			||||||
    if not hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_sapling') then
 | 
					    -- Check if we have saplings in our inventory
 | 
				
			||||||
        error('Out of saplingurtle.craft()  -- craft stone brickss')
 | 
					    if not hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling') then
 | 
				
			||||||
 | 
					        error('Out of ' .. TREE_SAPLING .. ' saplings')
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    -- Build a Loop, where we plant and cut trees
 | 
					    -- Build a Loop, where we plant and cut trees
 | 
				
			||||||
@@ -40,40 +41,29 @@ while true do
 | 
				
			|||||||
	turtle.back()
 | 
						turtle.back()
 | 
				
			||||||
	turtle.turnRight()
 | 
						turtle.turnRight()
 | 
				
			||||||
	blockExists, item = turtle.inspect()
 | 
						blockExists, item = turtle.inspect()
 | 
				
			||||||
	if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. 'log' then
 | 
						if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. '_log' then
 | 
				
			||||||
 | 
						    hare.selectEmtySlot()
 | 
				
			||||||
            shell.run('choptree.lua') -- Run Choptree
 | 
					            shell.run('choptree.lua') -- Run Choptree
 | 
				
			||||||
	elseif block Exists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. 'sapling' then
 | 
						elseif blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
 | 
				
			||||||
	    turtle.drop()
 | 
						    print('Error! Wrong block')
 | 
				
			||||||
 | 
						elseif not blockExists then
 | 
				
			||||||
    print('Planting...')
 | 
						    turtle.forward()
 | 
				
			||||||
    turtle.place() -- plant sapling
 | 
						    local success, underneath = turtle.inspectDown()
 | 
				
			||||||
    
 | 
						    if underneath['name'] ~= 'minecraft:dirt' and underneath['name'] ~= 'minecraft:grass_block' then
 | 
				
			||||||
    -- Loop until tree is grown
 | 
					                print('Error. No Dirt or Grass underneath to plant a tree. Found: ' .. underneath['name'])
 | 
				
			||||||
    while true do
 | 
					 | 
				
			||||||
        blockExists, item = turtle.inspect()
 | 
					 | 
				
			||||||
        if item['name'] ~= 'minecraft:spruce_log' then
 | 
					 | 
				
			||||||
            print('wait 5 seconds')
 | 
					 | 
				
			||||||
            os.sleep(5)
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            break -- tree has grown
 | 
					 | 
				
			||||||
        end 
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
    hare.selectEmptySlot()
 | 
					 | 
				
			||||||
    shell.run('choptree.lua') -- run choptree
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
    -- move to and face chest
 | 
					 | 
				
			||||||
		turtle.back()
 | 
							turtle.back()
 | 
				
			||||||
 | 
						    else
 | 
				
			||||||
 | 
							turtle.back()
 | 
				
			||||||
 | 
							hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling')
 | 
				
			||||||
 | 
							turtle.place()
 | 
				
			||||||
 | 
						    end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
	turtle.turnLeft()
 | 
						turtle.turnLeft()
 | 
				
			||||||
    turtle.turnLeft()
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
    -- put logs into chest
 | 
					 | 
				
			||||||
    while hare.selectItem('minecraft:spruce_log') do
 | 
					 | 
				
			||||||
        logCount = logCount + turtle.getItemCount()
 | 
					 | 
				
			||||||
        print('Total logs: ' .. logCount)
 | 
					 | 
				
			||||||
        turtle.drop()
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    --face planting sport
 | 
					    -- Move forward to the chest again
 | 
				
			||||||
    turtle.turnLeft()
 | 
					    for i = 1, (3 * NUM_OF_TREES) do
 | 
				
			||||||
    turtle.turnLeft()
 | 
					        turtle.forward()
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user