Build a new TreeFarm Skript
This commit is contained in:
		@@ -3,49 +3,77 @@ Plants tree and cuts it down.]]
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
  error('You must install choptree app first')
 | 
			
		||||
    error('You must install choptree app first')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
while true do
 | 
			
		||||
  -- Check inventory for saplings
 | 
			
		||||
  if not hare.selectItem('minecraft:spruce_sapling') then
 | 
			
		||||
    error('Out of saplings')
 | 
			
		||||
  end
 | 
			
		||||
    -- First, empty the whole turtle
 | 
			
		||||
    for i = 1, 16 do
 | 
			
		||||
	turtle.select(i)
 | 
			
		||||
	turtle.drop()
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    -- 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')
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Build a Loop, where we plant and cut trees
 | 
			
		||||
    for i = 1, NUM_OF_TREES do
 | 
			
		||||
	turtle.back()
 | 
			
		||||
	turtle.back()
 | 
			
		||||
	turtle.back()
 | 
			
		||||
	turtle.turnRight()
 | 
			
		||||
	blockExists, item = turtle.inspect()
 | 
			
		||||
	if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. 'log' then
 | 
			
		||||
            shell.run('choptree.lua') -- Run Choptree
 | 
			
		||||
	elseif block Exists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. 'sapling' then
 | 
			
		||||
	    turtle.drop()
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
  
 | 
			
		||||
  print('Planting...')
 | 
			
		||||
  turtle.place() -- plant sapling
 | 
			
		||||
    -- move to and face chest
 | 
			
		||||
    turtle.back()
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
  
 | 
			
		||||
  -- 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()
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  --face planting sport
 | 
			
		||||
  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
 | 
			
		||||
  
 | 
			
		||||
    --face planting sport
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user