Updated the file to support modules.lua and check fuel
The app now checks if it has enough fuel and if not, it asks for more. Additionally it digs everythin in front of it, except for the last block.
This commit is contained in:
parent
58f282e0bf
commit
591b06aa19
@ -1,71 +1,82 @@
|
||||
--[[Tree Farming App by Al Sweigart
|
||||
Plants tree and cuts it down.]]
|
||||
|
||||
os.loadAPI('hare.lua') -- Load the hare module
|
||||
os.loadAPI('modules.lua') -- Load the modules module
|
||||
|
||||
local NUM_OF_TREES = 4
|
||||
local TREE_SAPLING = 'spruce'
|
||||
local TREE_SAPLING = 'oak'
|
||||
|
||||
-- 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
|
||||
-- First of all, wait a few minutes
|
||||
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)
|
||||
-- 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)
|
||||
|
||||
if item ~= nil and item['name'] ~= 'minecraft:' .. TREE_SAPLING .. '_sapling' then
|
||||
turtle.select(i)
|
||||
turtle.drop()
|
||||
end
|
||||
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
|
||||
-- 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
|
||||
check_fuel()
|
||||
if i ~= 3 * NUM_OF_TREES then
|
||||
turtle.dig()
|
||||
end
|
||||
turtle.forward()
|
||||
end
|
||||
|
||||
|
||||
-- Check if we have saplings in our inventory
|
||||
if not hare.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling') then
|
||||
error('Out of ' .. TREE_SAPLING .. ' saplings')
|
||||
turtle.turnLeft()
|
||||
blockExists, item = turtle.inspect()
|
||||
if blockExists and item['name'] == 'minecraft:' .. TREE_SAPLING .. '_log' then
|
||||
modules.selectEmptySlot()
|
||||
shell.run('choptree.lua') -- Run Choptree
|
||||
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()
|
||||
modules.selectItem('minecraft:' .. TREE_SAPLING .. '_sapling')
|
||||
turtle.place()
|
||||
end
|
||||
end
|
||||
turtle.turnRight()
|
||||
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
|
||||
hare.selectEmtySlot()
|
||||
shell.run('choptree.lua') -- Run Choptree
|
||||
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
|
||||
|
||||
-- Move forward to the chest again
|
||||
for i = 1, (3 * NUM_OF_TREES) do
|
||||
turtle.forward()
|
||||
-- Move forward to the chest again
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
for i = 1, (3 * NUM_OF_TREES) do
|
||||
check_fuel()
|
||||
if i ~= 3 * NUM_OF_TREES then
|
||||
turtle.dig()
|
||||
end
|
||||
turtle.foward()
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user