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
 | 
			
		||||
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
 | 
			
		||||
Chops down the tree in front of turtle.]]
 | 
			
		||||
 | 
			
		||||
if not turtle.detect() then
 | 
			
		||||
  error('Could not find tree!')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
print('Chopping 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
 | 
			
		||||
for j = 1, 4 do
 | 
			
		||||
    for i = 1, 4 do
 | 
			
		||||
        if not turtle.suck() then -- Suck up all Wood
 | 
			
		||||
	    print('Did not find something to suck')
 | 
			
		||||
	end
 | 
			
		||||
        turtle.suck() -- Suck up everything
 | 
			
		||||
	turtle.turnLeft()
 | 
			
		||||
    end
 | 
			
		||||
    turtle.forward()
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,6 @@ os.loadAPI('hare.lua') -- Load the hare module
 | 
			
		||||
 | 
			
		||||
local NUM_OF_TREES = 4
 | 
			
		||||
local TREE_SAPLING = 'spruce'
 | 
			
		||||
local blockExists, item
 | 
			
		||||
local logCount = 0
 | 
			
		||||
 | 
			
		||||
-- Check if choptree program exists
 | 
			
		||||
if not fs.exists('choptree.lua') then
 | 
			
		||||
@@ -14,23 +12,26 @@ if not fs.exists('choptree.lua') then
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
while true do
 | 
			
		||||
    -- First, empty the whole turtle
 | 
			
		||||
    for i = 1, 16 do
 | 
			
		||||
	turtle.select(i)
 | 
			
		||||
	turtle.drop()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Check if turtle has enough fuel
 | 
			
		||||
   -- 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()
 | 
			
		||||
	hare.selectItem('minecraft:' .. TREE_SAPLING .. 'log')
 | 
			
		||||
	turtle.refuel(2)
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Empty everything except for the saplings
 | 
			
		||||
    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.drop()
 | 
			
		||||
	end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Take one stack of Saplings from the Chest
 | 
			
		||||
    if not hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_sapling') then
 | 
			
		||||
        error('Out of saplingurtle.craft()  -- craft stone brickss')
 | 
			
		||||
 
 | 
			
		||||
    -- Check if we have saplings in our inventory
 | 
			
		||||
    if not hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling') then
 | 
			
		||||
        error('Out of ' .. TREE_SAPLING .. ' saplings')
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Build a Loop, where we plant and cut trees
 | 
			
		||||
@@ -40,40 +41,29 @@ while true do
 | 
			
		||||
	turtle.back()
 | 
			
		||||
	turtle.turnRight()
 | 
			
		||||
	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
 | 
			
		||||
	elseif block Exists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. 'sapling' then
 | 
			
		||||
	    turtle.drop()
 | 
			
		||||
	elseif blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
 | 
			
		||||
	    print('Error! Wrong block')
 | 
			
		||||
	elseif not blockExists then
 | 
			
		||||
	    turtle.forward()
 | 
			
		||||
	    local success, underneath = turtle.inspectDown()
 | 
			
		||||
	    if underneath['name'] ~= 'minecraft:dirt' and underneath['name'] ~= 'minecraft:grass_block' then
 | 
			
		||||
                print('Error. No Dirt or Grass underneath to plant a tree. Found: ' .. underneath['name'])
 | 
			
		||||
		turtle.back()
 | 
			
		||||
	    else
 | 
			
		||||
		turtle.back()
 | 
			
		||||
		hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling')
 | 
			
		||||
		turtle.place()
 | 
			
		||||
	    end
 | 
			
		||||
	end
 | 
			
		||||
	turtle.turnLeft()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    print('Planting...')
 | 
			
		||||
    turtle.place() -- plant sapling
 | 
			
		||||
    
 | 
			
		||||
    -- Loop until tree is grown
 | 
			
		||||
    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.turnLeft()
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
  
 | 
			
		||||
    -- put logs into chest
 | 
			
		||||
    while hare.selectItem('minecraft:spruce_log') do
 | 
			
		||||
        logCount = logCount + turtle.getItemCount()
 | 
			
		||||
        print('Total logs: ' .. logCount)
 | 
			
		||||
        turtle.drop()
 | 
			
		||||
    -- Move forward to the chest again
 | 
			
		||||
    for i = 1, (3 * NUM_OF_TREES) do
 | 
			
		||||
        turtle.forward()
 | 
			
		||||
    end
 | 
			
		||||
  
 | 
			
		||||
    --face planting sport
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user