Compare commits

..

No commits in common. "fdcc4f3eba31173ceb948570da73a5612665b31c" and "3ae694a216b02132e6ebda915ddd987c7db99c37" have entirely different histories.

3 changed files with 69 additions and 40 deletions

View File

@ -34,4 +34,19 @@ 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,6 +1,10 @@
--[[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
@ -10,7 +14,9 @@ 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
turtle.suck() -- Suck up everything if not turtle.suck() then -- Suck up all Wood
print('Did not find something to suck')
end
turtle.turnLeft() turtle.turnLeft()
end end
turtle.forward() turtle.forward()

View File

@ -5,6 +5,8 @@ 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
@ -12,28 +14,23 @@ if not fs.exists('choptree.lua') then
end end
while true do while true do
-- First of all, wait a few minutes -- First, empty the whole turtle
os.sleep(300)
-- 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
-- Check if we have saplings in our inventory if not hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_sapling') then
if not hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling') then error('Out of saplingurtle.craft() -- craft stone brickss')
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
@ -43,29 +40,40 @@ 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 blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then elseif block Exists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. 'sapling' then
print('Error! Wrong block') turtle.drop()
elseif not blockExists then
turtle.forward() print('Planting...')
local success, underneath = turtle.inspectDown() turtle.place() -- plant sapling
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']) -- Loop until tree is grown
turtle.back() while true do
blockExists, item = turtle.inspect()
if item['name'] ~= 'minecraft:spruce_log' then
print('wait 5 seconds')
os.sleep(5)
else else
break -- tree has grown
end
end
hare.selectEmptySlot()
shell.run('choptree.lua') -- run choptree
-- move to and face chest
turtle.back() 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
-- Move forward to the chest again --face planting sport
for i = 1, (3 * NUM_OF_TREES) do turtle.turnLeft()
turtle.forward() turtle.turnLeft()
end
end end