better chopping in superTreefarm
This commit is contained in:
@@ -448,24 +448,23 @@ local function makeKey(b)
|
|||||||
return table.concat({ b.x, b.y, b.z }, ':')
|
return table.concat({ b.x, b.y, b.z }, ':')
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sense(pt, filter, blocks)
|
local function findDroppedSaplings()
|
||||||
turtle.pathfind(pt, { blocks = Util.shallowCopy(state.trees) })
|
|
||||||
|
|
||||||
equip('left', 'plethora:sensor', SENSOR)
|
equip('left', 'plethora:sensor', SENSOR)
|
||||||
local raw = peripheral.call('left', 'sense')
|
local raw = peripheral.call('left', 'sense')
|
||||||
equip('left', PICKAXE)
|
equip('left', PICKAXE)
|
||||||
|
|
||||||
Util.reduce(raw, function(acc, b)
|
local sensed = Util.reduce(raw, function(acc, b)
|
||||||
Point.rotate(b, state.home.heading)
|
Point.rotate(b, state.home.heading)
|
||||||
b.x = Util.round(b.x) + turtle.point.x
|
b.x = Util.round(b.x) + turtle.point.x
|
||||||
b.y = Util.round(b.y) + turtle.point.y
|
b.y = Util.round(b.y) + turtle.point.y
|
||||||
b.z = Util.round(b.z) + turtle.point.z
|
b.z = Util.round(b.z) + turtle.point.z
|
||||||
if filter(b) then
|
if b.y == 0 and b.x > -6 and string.find(b.displayName, 'sapling', 1, true) then
|
||||||
|
b.sapling = true
|
||||||
acc[makeKey(b)] = b
|
acc[makeKey(b)] = b
|
||||||
end
|
end
|
||||||
end, blocks)
|
end, { })
|
||||||
|
|
||||||
return blocks
|
return sensed
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scan(pt, filter)
|
local function scan(pt, filter)
|
||||||
@@ -551,16 +550,18 @@ local function fell()
|
|||||||
local function filter(b)
|
local function filter(b)
|
||||||
return b.y >= 0 and (b.name == LOG or b.name == LOG2 or b.name == SAPLING)
|
return b.y >= 0 and (b.name == LOG or b.name == LOG2 or b.name == SAPLING)
|
||||||
end
|
end
|
||||||
local function saplingFilter(b)
|
|
||||||
-- b.x > -6 so we don't take out the furnace
|
|
||||||
if b.y == 0 and b.x > -6 and string.find(b.displayName, 'sapling', 1, true) then
|
|
||||||
b.sapling = true
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- low scan
|
-- low scan
|
||||||
local blocks = scan(HOME_PT, filter)
|
local blocks = scan(HOME_PT, filter)
|
||||||
|
local sensed = { }
|
||||||
|
|
||||||
|
-- determine if we need saplings
|
||||||
|
local slots = turtle.getSummedInventory()
|
||||||
|
if not Util.every(ALL_SAPLINGS, function(sapling)
|
||||||
|
return slots[sapling] and slots[sapling].count >= MIN_SAPLINGS
|
||||||
|
end) then
|
||||||
|
sensed = findDroppedSaplings()
|
||||||
|
end
|
||||||
|
|
||||||
if not Util.every(blocks, function(b) return b.y < 6 end) then
|
if not Util.every(blocks, function(b) return b.y < 6 end) then
|
||||||
-- tree might be above low scan range, do a scan higher up
|
-- tree might be above low scan range, do a scan higher up
|
||||||
@@ -569,15 +570,7 @@ local function fell()
|
|||||||
turtle.setPolicy("attackOnly")
|
turtle.setPolicy("attackOnly")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- determine if we need saplings
|
Util.merge(blocks, sensed)
|
||||||
local slots = turtle.getSummedInventory()
|
|
||||||
if not Util.every(ALL_SAPLINGS, function(sapling)
|
|
||||||
return slots[sapling] and slots[sapling].count >= MIN_SAPLINGS
|
|
||||||
end) then
|
|
||||||
|
|
||||||
-- need saplings add sapling entities
|
|
||||||
sense(HOME_PT, saplingFilter, blocks)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add any locations that need saplings
|
-- add any locations that need saplings
|
||||||
plantTrees(blocks)
|
plantTrees(blocks)
|
||||||
|
|||||||
Reference in New Issue
Block a user