Build a new TreeFarm Skript

This commit is contained in:
Sascha Martens 2020-11-06 20:36:05 +01:00
parent 8f46d22501
commit 3ae694a216
2 changed files with 80 additions and 35 deletions

View File

@ -33,3 +33,20 @@ function selectEmptySlot()
end end
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

@ -3,49 +3,77 @@ Plants tree and cuts it down.]]
os.loadAPI('hare.lua') -- Load the hare module os.loadAPI('hare.lua') -- Load the hare module
local NUM_OF_TREES = 4
local TREE_SAPLING = 'spruce'
local blockExists, item local blockExists, item
local logCount = 0 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
error('You must install choptree app first') error('You must install choptree app first')
end end
while true do while true do
-- Check inventory for saplings -- First, empty the whole turtle
if not hare.selectItem('minecraft:spruce_sapling') then for i = 1, 16 do
error('Out of saplings') turtle.select(i)
end 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
end
hare.selectEmptySlot()
shell.run('choptree.lua') -- run choptree
-- move to and face chest -- Check if turtle has enough fuel
turtle.back() if turtle.getFuelLevel() < (2 * (3 * NUM_OF_TREES)) then
turtle.turnLeft() hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_log')
turtle.turnLeft() turtle.craft()
hare.selectItem('minecraft:' .. TREE_SAPLING .. 'plan')
turtle.refuel()
end
-- put logs into chest -- Take one stack of Saplings from the Chest
while hare.selectItem('minecraft:spruce_log') do if not hare.getItemFromChest('minecraft:' .. TREE_SAPLING .. '_sapling') then
logCount = logCount + turtle.getItemCount() error('Out of saplingurtle.craft() -- craft stone brickss')
print('Total logs: ' .. logCount) end
turtle.drop()
end
--face planting sport -- Build a Loop, where we plant and cut trees
turtle.turnLeft() for i = 1, NUM_OF_TREES do
turtle.turnLeft() 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
-- 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()
end end