Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
Last active January 29, 2021 23:29
Show Gist options
  • Save CoderPuppy/206f4d36943eb8faf84558cff1f41c71 to your computer and use it in GitHub Desktop.
Save CoderPuppy/206f4d36943eb8faf84558cff1f41c71 to your computer and use it in GitHub Desktop.
[CC] Big Spruce Tree Farm
local function refuel(n)
local sel = turtle.getSelectedSlot()
local slot = 1
while turtle.getFuelLevel() < n do
if slot > 16 then
error 'no fuel'
end
turtle.select(slot)
if not turtle.refuel(1) then
slot = slot + 1
end
end
turtle.select(sel)
end
local function isDirt(d)
return d.name == 'minecraft:dirt' or d.name == 'minecraft:grass' or d.name == 'minecraft:podzol'
end
local function isAiry(e, d)
return not e or d.name:match'^minecraft:.*_leaves$'
end
while true do
repeat
turtle.select(1)
local u, ud = turtle.inspectUp()
local f, fd = turtle.inspect()
local d, dd = turtle.inspectDown()
print(u and ud.name or 'air', f and fd.name or 'air', d and dd.name or 'air')
if d and (dd.name == 'minecraft:chest' or dd.name == 'quark:custom_chest') then -- starting position
if not f then
turtle.select(2)
turtle.place()
end
local sel = turtle.getSelectedSlot()
for slot = 1, 16 do
turtle.select(slot)
local i = turtle.getItemDetail()
if i then
if i.name == 'minecraft:spruce_log' then
turtle.dropDown()
elseif i.name == 'minecraft:spruce_sapling' then
turtle.transferTo(2)
if slot ~= 2 and turtle.getItemCount() > 0 then
turtle.dropDown()
end
elseif turtle.refuel(0) then
turtle.transferTo(1)
if slot ~= 1 and turtle.getItemCount() > 0 then
turtle.dropDown()
end
else
turtle.dropDown()
end
else
end
end
-- if turtle.getItemSpace(1) > 0 or turtle.getItemSpace(2) > 0 then
-- local c = peripheral.wrap 'bottom'
-- for slot, stack in pairs(c.list()) do
-- if stack.name == 'quark:charcoal_block' and turtle.getItemSpace(1) > 0 then
-- c.pushItems('up', slot, stack.count, 1)
-- elseif stack.name:match'^minecraft:.*_sapling$' and turtle.getItemSpace(2) > 0 then
-- c.pushItems('up', slot, stack.count, 2)
-- end
-- end
-- end
turtle.select(sel)
if f and fd.name == 'minecraft:spruce_log' then -- tree grew
-- move into tree
print 'move into tree'
refuel(1)
turtle.dig()
assert(turtle.forward(), 'mv fwd')
-- → digging up
elseif f and fd.name == 'minecraft:spruce_sapling' then -- waiting
sleep(10)
elseif not f then -- handled above for speed
print 'sapling'
else
error 'TODO 2'
end
elseif f and (fd.name == 'minecraft:spruce_log' or fd.name:match'^minecraft:.*_leaves$') and (not d or (isDirt(dd) and not redstone.getInput 'bottom') or dd.name == 'minecraft:spruce_log') then
-- digging up
print 'digging up'
refuel(1)
turtle.digUp()
if not turtle.up() then break end -- ? → digging up
-- → digging up | digging down
elseif not f and (not d or dd.name == 'minecraft:spruce_log') then
-- digging down
print 'digging down'
refuel(1)
turtle.digDown()
if not turtle.down() then break end -- ? → digging down
local i, id = turtle.inspect()
if i and (id.name == 'minecraft:spruce_log' or id.name:match'^minecraft:.*_leaves$') then
turtle.dig() -- ? → digging up
end
-- → digging down | bottom 1
elseif d and isDirt(dd) and not redstone.getInput 'bottom' and not f then
-- bottom 1
print 'bottom 1'
refuel(2)
if not turtle.up() then break end
turtle.select(2)
if not turtle.placeDown() then break end -- ? → digging down
if not turtle.forward() then break end -- ? → bottom 5' → bottom 1
turtle.dig() -- ? → digging up → digging down → bottom 2
-- → bottom 2
elseif isAiry(f, fd) and not d then
-- bottom 2
-- TODO: digging down covers `not f and not d`
-- TODO: digging up covers `f and fd.name == 'minecraft:leaves' and not d`
print 'bottom 2'
refuel(1)
if not turtle.down() then break end
-- → bottom 3
elseif d and isDirt(dd) and redstone.getInput 'bottom' and isAiry(f, fd) then
-- bottom 3
print 'bottom 3'
turtle.turnRight()
-- → bottom 4 | bottom 4'
elseif d and isDirt(dd) and redstone.getInput 'bottom' and f and fd.name == 'minecraft:spruce_log' then
-- bottom 4
print 'bottom 4'
refuel(1)
if not turtle.up() then break end
turtle.select(2)
assert(turtle.placeDown(), 'plc dwn') -- ! → digging up
-- → bottom 5
elseif d and dd.name == 'minecraft:spruce_sapling' and f and fd.name == 'minecraft:spruce_log' then
-- bottom 5
print 'bottom 5'
refuel(1)
turtle.dig()
assert(turtle.forward(), 'mv fwd') -- ! → bottom 5'
turtle.turnRight() -- ! → digging down
-- → digging up
elseif d and isDirt(dd) and redstone.getInput 'bottom' and f and fd.name == 'minecraft:spruce_sapling' then
-- bottom 4'
print 'bottom 4\''
refuel(2)
if not turtle.up() then break end
turtle.select(2)
if not turtle.placeDown() then break end -- ? → digging down / bottom 2
if not turtle.forward() then break end -- ? → bottom 5' → bottom 4'
-- → bottom 5'
elseif d and dd.name == 'minecraft:spruce_sapling' and isAiry(f, fd) then
-- bottom 5'
-- TODO: similar to bottom 2 and digging down
print 'bottom 5\''
refuel(1)
turtle.digDown()
if not turtle.down() then break end -- ? → digging down | bottom 2
-- → bottom 6'
elseif d and isDirt(dd) and f and fd.name == 'minecraft:cobblestone' then
-- bottom 6'
print 'bottom 6\''
turtle.turnRight()
-- → bottom 7'
elseif d and isDirt(dd) and f and fd.name == 'minecraft:spruce_sapling' then
-- bottom 7'
print 'bottom 7\''
refuel(1)
if not turtle.back() then break end
-- → sapling
else
error 'TODO 1'
end
until true
end
-- move into tree (fwd: log, dwn: chest)
-- dig fwd
-- mv fwd (! → ERR)
-- * digging up (fwd: log|leaf, dwn: air|gnd|log)
-- dig up
-- mv up (? → digging up)
-- * digging down (fwd: air, dwn: air|log)
-- dig dwn
-- mv dwn (? → digging down)
-- dig fwd (only log|leaf to help with bottom 4') (? → digging up)
-- bottom 1 (dwn: gnd, fwd: air)
-- mv up
-- plc dwn (? → digging down → bottom 1)
-- mv fwd (? → bottom 5' → bottom 1)
-- dig fwd (? → digging up → digging down → bottom 2)
-- bottom 2 (fwd: air|leaf, dwn: air)
-- mv dwn
-- -- combine with digging down
-- bottom 3 (dwn: coarse dirt, fwd: air|leaf)
-- turn r
-- bottom 4 (dwn: coarse dirt, fwd: log)
-- mv up
-- plc dwn (! → digging up)
-- bottom 5 (dwn: sapling, fwd: log)
-- dig fwd
-- mv fwd (! → bottom 5')
-- turn r (! → digging down)
-- * digging up (fwd: log|leaf, dwn: air|gnd|log)
-- dig up
-- mv up (? → digging up)
-- * digging down (fwd: air, dwn: air|log)
-- dig dwn
-- mv dwn (? → digging down)
-- dig fwd (only log|leaf to help with bottom 4') (? → digging up)
-- bottom 1 (dwn: gnd, fwd: air)
-- mv up
-- plc dwn (? → digging down → bottom 1)
-- mv fwd (? → bottom 5' → bottom 1)
-- dig fwd (? → digging up → digging down → bottom 2)
-- bottom 2 (fwd: air|leaf, dwn: air)
-- mv dwn
-- -- combine with digging down
-- bottom 3 (dwn: coarse dirt, fwd: air|leaf)
-- turn r
-- bottom 4' (dwn: coarse dirt, fwd: sapling)
-- mv up
-- plc dwn (? → digging down → bottom 4')
-- mv fwd (? → bottom 5' → bottom 4')
-- bottom 5' (dwn: sapling, fwd: air|leaf)
-- dig dwn
-- mv dwn (? → digging down)
-- -- combine with digging down
-- bottom 6' (dwn: gnd, fwd: cobble)
-- turn r
-- bottom 7' (down: gnd, fwd: sapling)
-- mv bck
-- sapling (down: chest, fwd: air)
-- plc fwd
-- dead
-- bottom 1 (dwn: gnd, fwd: air)
-- mv fwd
-- bottom 2 (dwn: coarse dirt, fwd: air)
-- turn r
-- bottom 3 (dwn: coarse dirt, fwd: log)
-- dig fwd
-- mv fwd
-- bottom 4 (dwn: gnd, fwd: cobble)
-- turn r
-- * digging up (fwd: log|leaf)
-- dig up
-- mv up (? → digging up)
-- * digging down (fwd: air, dwn: !gnd)
-- dig dwn
-- mv dwn (? → digging down)
-- dig fwd (? → digging up)
-- bottom 1 (dwn: gnd, fwd: air)
-- mv fwd
-- bottom 2 (dwn: coarse dirt, fwd: cobble)
-- turn r
-- bottom 3 (dwn: coarse dirtwd
--
--
--
-- bottom 1 (dwn: gnd, fwd: air)
-- plc fwd
-- bottom 2 (dwn: gnd, fwd: sapling)
-- turn r
-- dig fwd (! → digging up)
-- mv fwd (! → bottom 1)
-- bottom 3 (dwn: gnd, fwd: cobble)
-- turn l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment