Compare commits

...

2 Commits

3 changed files with 40 additions and 69 deletions

View File

@ -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

View File

@ -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()

View File

@ -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,28 @@ if not fs.exists('choptree.lua') then
end end
while true do while true do
-- First, empty the whole turtle -- First of all, wait a few minutes
for i = 1, 16 do os.sleep(300)
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 if turtle.getFuelLevel() < (2 * (3 * NUM_OF_TREES)) then
hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_log') hare.selectItem('minecraft:' .. TREE_SAPLING .. 'log')
turtle.craft() turtle.refuel(2)
hare.selectItem('minecraft:' .. TREE_SAPLING .. 'plan')
turtle.refuel()
end end
-- Take one stack of Saplings from the Chest -- Empty everything except for the saplings
if not hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_sapling') then for i = 1, 16 do
error('Out of saplingurtle.craft() -- craft stone brickss') local item = turtle.getItemDetail(i)
if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
turtle.select(i)
turtle.drop()
end
end
-- Check if we have saplings in our inventory
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 +43,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 turtle.back()
blockExists, item = turtle.inspect() else
if item['name'] ~= 'minecraft:spruce_log' then turtle.back()
print('wait 5 seconds') hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling')
os.sleep(5) turtle.place()
else end
break -- tree has grown end
end turtle.turnLeft()
end end
hare.selectEmptySlot()
shell.run('choptree.lua') -- run choptree -- Move forward to the chest again
for i = 1, (3 * NUM_OF_TREES) do
-- move to and face chest turtle.forward()
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 end
--face planting sport
turtle.turnLeft()
turtle.turnLeft()
end end