superTreefarm
This commit is contained in:
@@ -35,7 +35,8 @@ local FUEL_DIRE = FUEL_BASE + 10
|
|||||||
local FUEL_GOOD = FUEL_BASE + 2000
|
local FUEL_GOOD = FUEL_BASE + 2000
|
||||||
|
|
||||||
local MIN_CHARCOAL = 24
|
local MIN_CHARCOAL = 24
|
||||||
local MAX_SAPLINGS = 32
|
local MIN_SAPLINGS = 32
|
||||||
|
local MAX_SAPLINGS = 64
|
||||||
|
|
||||||
local GRID = {
|
local GRID = {
|
||||||
TL = { x = 8, y = 0, z = -7 },
|
TL = { x = 8, y = 0, z = -7 },
|
||||||
@@ -70,6 +71,7 @@ local OAK_LOG = 'minecraft:log:0'
|
|||||||
local OAK_PLANK = 'minecraft:planks:0'
|
local OAK_PLANK = 'minecraft:planks:0'
|
||||||
local SAPLING = 'minecraft:sapling:0'
|
local SAPLING = 'minecraft:sapling:0'
|
||||||
local SCANNER = 'plethora:module:2'
|
local SCANNER = 'plethora:module:2'
|
||||||
|
local SENSOR = 'plethora:module:3'
|
||||||
local STICK = 'minecraft:stick:0'
|
local STICK = 'minecraft:stick:0'
|
||||||
local STONE = 'minecraft:stone:0'
|
local STONE = 'minecraft:stone:0'
|
||||||
local TORCH = 'minecraft:torch:0'
|
local TORCH = 'minecraft:torch:0'
|
||||||
@@ -328,10 +330,12 @@ local function createFurnace()
|
|||||||
return true -- try again later
|
return true -- try again later
|
||||||
end
|
end
|
||||||
print('Adding a furnace')
|
print('Adding a furnace')
|
||||||
getCobblestone(8)
|
if not turtle.has(FURNACE) then
|
||||||
|
getCobblestone(8)
|
||||||
|
end
|
||||||
|
|
||||||
if turtle.has(FURNACE) or craftItem(FURNACE) then
|
if turtle.has(FURNACE) or craftItem(FURNACE) then
|
||||||
-- turtle.drop(COBBLESTONE)
|
turtle.drop(COBBLESTONE)
|
||||||
local furnacePt = { x = GRID.BL.x + 2, y = 1, z = GRID.BL.z + 2 }
|
local furnacePt = { x = GRID.BL.x + 2, y = 1, z = GRID.BL.z + 2 }
|
||||||
turtle.placeAt(furnacePt, FURNACE)
|
turtle.placeAt(furnacePt, FURNACE)
|
||||||
setState('furnace', furnacePt)
|
setState('furnace', furnacePt)
|
||||||
@@ -380,8 +384,8 @@ local function dropOffItems()
|
|||||||
if state.chest and
|
if state.chest and
|
||||||
slots[CHARCOAL] and
|
slots[CHARCOAL] and
|
||||||
slots[CHARCOAL].count >= MIN_CHARCOAL and
|
slots[CHARCOAL].count >= MIN_CHARCOAL and
|
||||||
(turtle.getItemCount(LOG) > 0 or
|
(turtle.getItemCount(LOG) > 16 or
|
||||||
turtle.getItemCount(LOG2) > 0) then
|
turtle.getItemCount(LOG2) > 16) then
|
||||||
|
|
||||||
print('Storing logs')
|
print('Storing logs')
|
||||||
turtle.pathfind(Point.above(state.chest))
|
turtle.pathfind(Point.above(state.chest))
|
||||||
@@ -461,8 +465,28 @@ local function randomSapling()
|
|||||||
return sapling
|
return sapling
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function sense(pt, filter, blocks)
|
||||||
|
turtle.pathfind(pt, { blocks = Util.shallowCopy(state.trees) })
|
||||||
|
|
||||||
|
equip('left', 'plethora:sensor', SENSOR)
|
||||||
|
local raw = peripheral.call('left', 'sense')
|
||||||
|
equip('left', PICKAXE)
|
||||||
|
|
||||||
|
Util.reduce(raw, function(acc, b)
|
||||||
|
Point.rotate(b, state.home.heading)
|
||||||
|
b.x = Util.round(b.x) + turtle.point.x
|
||||||
|
b.y = Util.round(b.y) + turtle.point.y
|
||||||
|
b.z = Util.round(b.z) + turtle.point.z
|
||||||
|
if filter(b) then
|
||||||
|
table.insert(acc, b)
|
||||||
|
end
|
||||||
|
end, blocks)
|
||||||
|
|
||||||
|
return blocks
|
||||||
|
end
|
||||||
|
|
||||||
local function scan(pt, filter)
|
local function scan(pt, filter)
|
||||||
turtle.pathfind(pt)
|
turtle.pathfind(pt, { blocks = Util.shallowCopy(state.trees) })
|
||||||
|
|
||||||
equip('left', 'plethora:scanner', SCANNER)
|
equip('left', 'plethora:scanner', SCANNER)
|
||||||
local raw = peripheral.call('left', 'scan')
|
local raw = peripheral.call('left', 'scan')
|
||||||
@@ -496,8 +520,10 @@ local function plantTrees()
|
|||||||
end, { })
|
end, { })
|
||||||
|
|
||||||
Point.eachClosest(turtle.point, plant, function(pt)
|
Point.eachClosest(turtle.point, plant, function(pt)
|
||||||
turtle.digAt(pt)
|
if turtle.moveAgainst(pt, { blocks = Util.shallowCopy(state.trees) }) then
|
||||||
turtle.placeAt(pt, randomSapling())
|
turtle.digAt(pt)
|
||||||
|
turtle.placeAt(pt, randomSapling())
|
||||||
|
end
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -519,38 +545,63 @@ local function fellTrees(blocks)
|
|||||||
|
|
||||||
desperateRefuel(FUEL_DIRE)
|
desperateRefuel(FUEL_DIRE)
|
||||||
|
|
||||||
turtle.setPolicy("digAttack")
|
if turtle.point.y == 0 then
|
||||||
|
turtle.up()
|
||||||
|
end
|
||||||
for pt in Point.iterateClosest(turtle.point, blocks) do
|
for pt in Point.iterateClosest(turtle.point, blocks) do
|
||||||
turtle.digAt(pt)
|
if pt.sapling then
|
||||||
|
turtle.suckDownAt(pt)
|
||||||
|
else
|
||||||
|
turtle.digAt(pt)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desperateRefuel(FUEL_BASE + 100)
|
desperateRefuel(FUEL_BASE + 100)
|
||||||
turtle.clearMoveCallback()
|
turtle.clearMoveCallback()
|
||||||
turtle.setPolicy("attackOnly")
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fell()
|
local function fell()
|
||||||
local filter = function(b)
|
local leaves = false
|
||||||
return b.y > 0 and (b.name == LEAVES or b.name == LEAVES2 or b.name == LOG or b.name == LOG2)
|
|
||||||
|
local slots = turtle.getSummedInventory()
|
||||||
|
for _, sapling in pairs(ALL_SAPLINGS) do
|
||||||
|
if not slots[sapling] or slots[sapling].count < MIN_SAPLINGS then
|
||||||
|
leaves = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function filter(b)
|
||||||
|
return b.y > 0 and (b.name == LOG or b.name == LOG2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function saplingFilter(b)
|
||||||
|
if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
|
||||||
|
b.sapling = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local blocks = scan(HOME_PT, filter)
|
local blocks = scan(HOME_PT, filter)
|
||||||
|
|
||||||
|
if leaves then
|
||||||
|
sense(HOME_PT, saplingFilter, blocks)
|
||||||
|
end
|
||||||
|
|
||||||
if #blocks > 0 then
|
if #blocks > 0 then
|
||||||
print('Chopping')
|
print('Chopping')
|
||||||
|
|
||||||
local fuel = turtle.getFuelLevel()
|
local fuel = turtle.getFuelLevel()
|
||||||
|
|
||||||
fellTrees(blocks)
|
|
||||||
|
|
||||||
turtle.setPolicy("digAttack")
|
turtle.setPolicy("digAttack")
|
||||||
blocks = scan(HIGH_PT, filter)
|
|
||||||
turtle.setPolicy("attackOnly")
|
|
||||||
|
|
||||||
fellTrees(blocks)
|
fellTrees(blocks)
|
||||||
|
fellTrees(scan(HIGH_PT, filter))
|
||||||
|
|
||||||
|
turtle.pathfind(HOME_PT, { blocks = Util.shallowCopy(state.trees) })
|
||||||
|
turtle.setPolicy("attackOnly")
|
||||||
|
|
||||||
print('Used ' .. (fuel - turtle.getFuelLevel()) .. ' fuel')
|
print('Used ' .. (fuel - turtle.getFuelLevel()) .. ' fuel')
|
||||||
|
|
||||||
@@ -647,8 +698,13 @@ local function startupCheck()
|
|||||||
|
|
||||||
local slots = turtle.getSummedInventory()
|
local slots = turtle.getSummedInventory()
|
||||||
|
|
||||||
if not slots[CHEST] or not slots[CRAFTING_TABLE] or not slots[SCANNER] then
|
if not slots[CHEST] or not slots[CRAFTING_TABLE] or not slots[SCANNER] or not slots[SENSOR] then
|
||||||
error('A chest and crafting table must be in inventory')
|
error([[
|
||||||
|
Required:
|
||||||
|
* chest
|
||||||
|
* crafting table
|
||||||
|
* block scanner
|
||||||
|
* entity sensor]])
|
||||||
end
|
end
|
||||||
|
|
||||||
if not fs.exists(STARTUP_FILE) then
|
if not fs.exists(STARTUP_FILE) then
|
||||||
|
|||||||
@@ -594,6 +594,12 @@ Event.addRoutine(function()
|
|||||||
z = turtle.point.z - mining.home.z,
|
z = turtle.point.z - mining.home.z,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if math.abs(turtle.point.x) > 500 or math.abs(turtle.point.z) > 500 then
|
||||||
|
_G.printError('WARNING: distance > 500')
|
||||||
|
print('waiting for 30 seconds to begin')
|
||||||
|
os.sleep(30)
|
||||||
|
end
|
||||||
|
|
||||||
if not fs.exists(PROGRESS_FILE) then
|
if not fs.exists(PROGRESS_FILE) then
|
||||||
Util.writeTable(PROGRESS_FILE, mining)
|
Util.writeTable(PROGRESS_FILE, mining)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user