better pathing in superTreefarm

This commit is contained in:
kepler155c@gmail.com
2018-12-23 22:26:09 -05:00
parent 10b9772130
commit 931e368357

View File

@@ -303,7 +303,6 @@ local function getCobblestone(count)
end end
local function createFurnace() local function createFurnace()
if not state.furnace then if not state.furnace then
if turtle.getFuelLevel() < FUEL_BASE + 100 then if turtle.getFuelLevel() < FUEL_BASE + 100 then
return true -- try again later return true -- try again later
@@ -320,6 +319,7 @@ local function createFurnace()
setState('furnace', furnacePt) setState('furnace', furnacePt)
end end
end end
turtle.addWorldBlock(state.furnace)
end end
local function createChests() local function createChests()
@@ -458,7 +458,7 @@ local function findDroppedSaplings()
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 b.y == 0 and b.x > -6 and string.find(b.displayName, 'sapling', 1, true) then if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
b.sapling = true b.sapling = true
acc[makeKey(b)] = b acc[makeKey(b)] = b
end end
@@ -468,7 +468,7 @@ local function findDroppedSaplings()
end end
local function scan(pt, filter) local function scan(pt, filter)
turtle.pathfind(pt, { blocks = Util.shallowCopy(state.trees) }) 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')
@@ -565,9 +565,7 @@ local function fell()
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
turtle.setPolicy("digAttack")
blocks = scan(HIGH_PT, filter) blocks = scan(HIGH_PT, filter)
turtle.setPolicy("attackOnly")
end end
Util.merge(blocks, sensed) Util.merge(blocks, sensed)
@@ -580,13 +578,8 @@ local function fell()
local fuel = turtle.getFuelLevel() local fuel = turtle.getFuelLevel()
turtle.setPolicy("digAttack")
fellTrees(blocks) fellTrees(blocks)
turtle.pathfind(HOME_PT, { blocks = Util.shallowCopy(state.trees) })
turtle.setPolicy("attackOnly")
print('Used ' .. (fuel - turtle.getFuelLevel()) .. ' fuel') print('Used ' .. (fuel - turtle.getFuelLevel()) .. ' fuel')
end end
@@ -610,7 +603,9 @@ local function moreTrees()
for x = -2, 2, 1 do for x = -2, 2, 1 do
for z = -2, 2, 2 do for z = -2, 2, 2 do
if x ~= 0 or z ~= 0 then if x ~= 0 or z ~= 0 then
table.insert(state.trees, { x = x, y = 0, z = z }) local tree = { x = x, y = 0, z = z }
table.insert(state.trees, tree)
turtle.addWorldBlock(tree)
end end
end end
end end
@@ -658,6 +653,16 @@ local function findHome()
ey = 16, ey = 16,
ez = GRID.BR.z, ez = GRID.BR.z,
}) })
turtle.setPersistent(true)
for _, tree in pairs(state.trees) do
turtle.addWorldBlock(tree)
end
end
local function returnHome()
turtle.pathfind(HOME_PT)
return true
end end
local function updateClock() local function updateClock()
@@ -700,25 +705,26 @@ end
local tasks = { local tasks = {
{ desc = 'Startup check', fn = startupCheck }, { desc = 'Startup check', fn = startupCheck },
{ desc = 'Finding home', fn = findHome }, { desc = 'Finding home', fn = findHome },
{ desc = 'Emptying furnace', fn = emptyFurnace }, { desc = 'Creating furnace', fn = createFurnace },
{ desc = 'Creating chest', fn = createChests },
{ desc = 'Adding trees', fn = moreTrees }, { desc = 'Adding trees', fn = moreTrees },
{ desc = 'Emptying furnace', fn = emptyFurnace },
{ desc = 'Chopping', fn = fell }, { desc = 'Chopping', fn = fell },
{ desc = 'Snacking', fn = eatSaplings }, { desc = 'Snacking', fn = eatSaplings },
{ desc = 'Creating chest', fn = createChests },
{ desc = 'Creating furnace', fn = createFurnace },
{ desc = 'Making charcoal', fn = makeSingleCharcoal }, { desc = 'Making charcoal', fn = makeSingleCharcoal },
{ desc = 'Making charcoal', fn = makeCharcoal }, { desc = 'Making charcoal', fn = makeCharcoal },
{ desc = 'Placing torches', fn = placeTorches }, { desc = 'Placing torches', fn = placeTorches },
{ desc = 'Refueling', fn = refuel }, { desc = 'Refueling', fn = refuel },
{ desc = 'Dropping off items', fn = dropOffItems }, { desc = 'Dropping off items', fn = dropOffItems },
{ desc = 'Condensing', fn = turtle.condense }, { desc = 'Condensing', fn = turtle.condense },
{ desc = 'Returning home', fn = returnHome },
{ desc = 'Sleeping', fn = updateClock }, { desc = 'Sleeping', fn = updateClock },
} }
--local s, m = turtle.run(function() --local s, m = turtle.run(function()
turtle.reset() turtle.reset()
turtle.addFeatures('level', 'crafting') turtle.addFeatures('crafting')
turtle.setPolicy("attack") turtle.setPolicy("digAttack")
while not turtle.isAborted() do while not turtle.isAborted() do
print('fuel: ' .. turtle.getFuelLevel()) print('fuel: ' .. turtle.getFuelLevel())