superTreefarm: now with more trees

This commit is contained in:
kepler155c@gmail.com
2019-01-04 14:06:12 -05:00
parent 3d27808ce7
commit b05e614130

View File

@@ -487,23 +487,23 @@ local function findDroppedSaplings()
return sensed return sensed
end end
local function scan(pt, filter) local function scan(pt, filter, blocks)
turtle.pathfind(pt) turtle.pathfind(pt)
equip('left', 'plethora:scanner', SCANNER) equip('left', 'plethora:scanner', SCANNER)
local raw = peripheral.call('left', 'scan') local raw = peripheral.call('left', 'scan')
local blocks = Util.reduce(raw, function(acc, b) return Util.reduce(raw, function(acc, b)
Point.rotate(b, state.home.heading) if b.y >= 0 then
b.x = b.x + turtle.point.x Point.rotate(b, state.home.heading)
b.y = b.y + turtle.point.y b.x = b.x + turtle.point.x
b.z = b.z + turtle.point.z b.y = b.y + turtle.point.y
if filter(b) then b.z = b.z + turtle.point.z
acc[makeKey(b)] = b if filter(b) then
acc[makeKey(b)] = b
end
end end
end, { }) end, blocks or { })
return blocks
end end
local function getPlantLocations(blocks) local function getPlantLocations(blocks)
@@ -588,10 +588,13 @@ local function fell()
-- low scan -- low scan
local blocks = scan(HOME_PT, filter) local blocks = scan(HOME_PT, filter)
if not Util.every(blocks, function(b) return b.y < 6 end) then
local pt = Util.shallowCopy(HOME_PT)
while Util.any(blocks, function(b) return b.y > pt.y + 6 end) do
-- tree might be above low scan range, do a scan higher up -- tree might be above low scan range, do a scan higher up
equip('left', PICKAXE) equip('left', PICKAXE)
blocks = scan(HIGH_PT, filter) pt.y = pt.y + 8
blocks = scan(pt, filter, blocks)
end end
Util.merge(blocks, sensed) Util.merge(blocks, sensed)
@@ -616,7 +619,7 @@ local function moreTrees()
return return
end end
if not state.chest or turtle.getItemCount(OAK_SAPLING) < 15 then if not state.chest or turtle.getItemCount(OAK_SAPLING) < 2 then
return true return true
end end
@@ -626,7 +629,7 @@ local function moreTrees()
state.trees = { } state.trees = { }
for x = -2, 2, 1 do for x = -2, 2, 1 do
for z = -2, 2, 2 do for z = -2, 2, 1 do
if x ~= 0 or z ~= 0 then if x ~= 0 or z ~= 0 then
local tree = { x = x, y = 0, z = z } local tree = { x = x, y = 0, z = z }
table.insert(state.trees, tree) table.insert(state.trees, tree)
@@ -640,7 +643,10 @@ local function moreTrees()
setState('trees', state.trees) setState('trees', state.trees)
Point.eachClosest(turtle.point, state.trees, function(pt) Point.eachClosest(turtle.point, state.trees, function(pt)
turtle.placeDownAt(pt, randomSapling()) local sapling = randomSapling()
if sapling then
turtle.placeDownAt(pt, sapling)
end
end) end)
end end
@@ -675,7 +681,7 @@ local function findHome()
y = GRID.TL.y, y = GRID.TL.y,
z = GRID.TL.z, z = GRID.TL.z,
ex = GRID.BR.x, ex = GRID.BR.x,
ey = 16, ey = 32,
ez = GRID.BR.z, ez = GRID.BR.z,
}) })