2020-11-06 15:05:04 +00:00
|
|
|
--[[Tree Farming App by Al Sweigart
|
|
|
|
Plants tree and cuts it down.]]
|
2020-11-06 11:00:34 +00:00
|
|
|
|
2020-12-20 13:31:55 +00:00
|
|
|
os.loadAPI('modules.lua') -- Load the modules module
|
2020-11-06 11:00:34 +00:00
|
|
|
|
2020-11-06 19:36:05 +00:00
|
|
|
local NUM_OF_TREES = 4
|
2020-12-20 13:31:55 +00:00
|
|
|
local TREE_SAPLING = 'oak'
|
2020-11-06 11:00:34 +00:00
|
|
|
|
2020-11-06 15:05:04 +00:00
|
|
|
-- Check if choptree program exists
|
2020-11-06 11:00:34 +00:00
|
|
|
if not fs.exists('choptree.lua') then
|
2020-12-20 13:31:55 +00:00
|
|
|
error('You must install choptree app first')
|
2020-11-06 11:00:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
while true do
|
2020-12-20 13:31:55 +00:00
|
|
|
-- First of all, wait a few minutes
|
|
|
|
os.sleep(300)
|
|
|
|
|
|
|
|
-- Sort all Items together
|
|
|
|
modules.sort_items()
|
|
|
|
|
|
|
|
|
|
|
|
-- Empty everything except for the saplings
|
|
|
|
for i = 1, 16 do
|
|
|
|
local item = turtle.getItemDetail(i)
|
2020-11-06 11:00:34 +00:00
|
|
|
|
2020-12-20 13:31:55 +00:00
|
|
|
if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
|
|
|
|
turtle.select(i)
|
2020-12-20 16:21:40 +00:00
|
|
|
print('Dropping ' .. item['name'] .. ' into chest.')
|
2020-12-20 13:31:55 +00:00
|
|
|
turtle.drop()
|
2020-11-06 19:36:05 +00:00
|
|
|
end
|
2020-12-20 13:31:55 +00:00
|
|
|
end
|
2020-11-06 11:00:34 +00:00
|
|
|
|
2020-12-20 13:31:55 +00:00
|
|
|
|
|
|
|
-- Check if we have saplings in our inventory
|
|
|
|
if not modules.select_item('minecraft:' .. TREE_SAPLING .. '_sapling') then
|
|
|
|
error('Out of ' .. TREE_SAPLING .. ' saplings')
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Build a Loop, where we plant and cut trees
|
|
|
|
turtle.turnLeft()
|
|
|
|
turtle.turnLeft()
|
|
|
|
for i = 1, NUM_OF_TREES do
|
|
|
|
for j = 1, 3 do
|
2020-12-20 16:21:40 +00:00
|
|
|
modules.check_fuel()
|
2020-12-20 13:31:55 +00:00
|
|
|
if i ~= 3 * NUM_OF_TREES then
|
|
|
|
turtle.dig()
|
|
|
|
end
|
|
|
|
turtle.forward()
|
2020-11-06 19:36:05 +00:00
|
|
|
end
|
2020-12-20 13:31:55 +00:00
|
|
|
turtle.turnLeft()
|
|
|
|
blockExists, item = turtle.inspect()
|
|
|
|
if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. '_log' then
|
2020-12-20 16:21:40 +00:00
|
|
|
modules.select_emptySlot()
|
2020-12-20 13:31:55 +00:00
|
|
|
shell.run('choptree.lua') -- Run Choptree
|
|
|
|
elseif blockExists and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
|
2020-12-20 16:21:40 +00:00
|
|
|
print('Error! Wrong block. Found ' .. item['name'])
|
2020-12-20 13:31:55 +00:00
|
|
|
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()
|
2020-12-20 16:21:40 +00:00
|
|
|
print('Planting seed.')
|
|
|
|
modules.select_item('minecraft:' .. TREE_SAPLING .. '_sapling')
|
2020-12-20 13:31:55 +00:00
|
|
|
turtle.place()
|
|
|
|
end
|
2020-11-06 19:36:05 +00:00
|
|
|
end
|
2020-12-20 13:31:55 +00:00
|
|
|
turtle.turnRight()
|
|
|
|
end
|
2020-11-06 21:50:26 +00:00
|
|
|
|
2020-12-20 13:31:55 +00:00
|
|
|
-- Move forward to the chest again
|
|
|
|
turtle.turnLeft()
|
|
|
|
turtle.turnLeft()
|
2020-12-20 16:21:40 +00:00
|
|
|
print('Heading back to chest.')
|
2020-12-20 13:31:55 +00:00
|
|
|
for i = 1, (3 * NUM_OF_TREES) do
|
2020-12-20 16:21:40 +00:00
|
|
|
modules.check_fuel()
|
2020-12-20 13:31:55 +00:00
|
|
|
if i ~= 3 * NUM_OF_TREES then
|
|
|
|
turtle.dig()
|
2020-11-06 19:36:05 +00:00
|
|
|
end
|
2020-12-20 16:21:40 +00:00
|
|
|
turtle.forward()
|
2020-12-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2020-11-06 11:00:34 +00:00
|
|
|
end
|