Fixed treefarm running out of fuel
parent
b263da5abf
commit
9b37b3ed01
26
treefarm.lua
26
treefarm.lua
|
@ -150,11 +150,33 @@ local function maintenance(width, depth, sapling_name, log_name)
|
|||
turtle.turnLeft()
|
||||
|
||||
-- Deposite all logs
|
||||
while select_item(log_name) do turtle.drop(64) end
|
||||
-- First, find all spots with logs in them
|
||||
local slots, count = {}, 0
|
||||
for i = 1, 16 do
|
||||
local data = turtle.getItemDetail(i)
|
||||
|
||||
if data and data.name == log_name then
|
||||
count = count + data.count
|
||||
slots[i] = count
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
-- Then, deposit logs as long as we have more than 10 logs left
|
||||
for slot, slot_count in pairs(slots) do
|
||||
-- Exit the loop if we have 10 or less logs
|
||||
if count <= 20 then break end
|
||||
|
||||
-- Refuel with 64 unless count says otherwise
|
||||
turtle.select(slot)
|
||||
local c = math.min(slot_count, count - 20)
|
||||
turtle.drop(c)
|
||||
count = count - c
|
||||
end
|
||||
|
||||
-- Keep 10 logs for refueling
|
||||
turtle.select(2)
|
||||
turtle.suck(10)
|
||||
turtle.suck(20 - count)
|
||||
|
||||
-- Get back to start block
|
||||
turtle.turnRight()
|
||||
|
|
Loading…
Reference in New Issue