new icon set + scanning miner

This commit is contained in:
kepler155c
2018-10-15 16:07:03 -04:00
parent 755c37bc9b
commit 77aada762f
2 changed files with 99 additions and 87 deletions

View File

@@ -96,7 +96,7 @@ local page = UI.Page {
sortColumn = 'name', sortColumn = 'name',
columns = { columns = {
{ heading = 'Resource', key = 'displayName' }, { heading = 'Resource', key = 'displayName' },
{ heading = 'Count', key = 'count', width = 6 }, { heading = 'Count', key = 'count', width = 5 },
}, },
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
@@ -167,6 +167,15 @@ local function getCornerOf(c)
return math.floor(c.x / 16) * 16, math.floor(c.z / 16) * 16 return math.floor(c.x / 16) * 16, math.floor(c.z / 16) * 16
end end
local function isFinished()
if mining.chunks ~= -1 then
local chunks = math.pow(mining.diameter-2, 2) + mining.chunkIndex
if chunks >= mining.chunks then
return true
end
end
end
local function nextChunk() local function nextChunk()
local x, z = getCornerOf({ x = mining.x, z = mining.z }) local x, z = getCornerOf({ x = mining.x, z = mining.z })
local points = math.pow(mining.diameter, 2) - math.pow(mining.diameter-2, 2) local points = math.pow(mining.diameter, 2) - math.pow(mining.diameter-2, 2)
@@ -177,13 +186,6 @@ local function nextChunk()
mining.chunkIndex = 0 mining.chunkIndex = 0
end end
if mining.chunks ~= -1 then
local chunks = math.pow(mining.diameter-2, 2) + mining.chunkIndex
if chunks >= mining.chunks then
return false
end
end
local nc = getChunkCoordinates(mining.diameter, mining.chunkIndex, x, z) local nc = getChunkCoordinates(mining.diameter, mining.chunkIndex, x, z)
-- enter next chunk -- enter next chunk
@@ -192,7 +194,7 @@ local function nextChunk()
Util.writeTable(PROGRESS_FILE, mining) Util.writeTable(PROGRESS_FILE, mining)
return true return not isFinished()
end end
local function status(newStatus) local function status(newStatus)
@@ -389,10 +391,10 @@ local function scan()
local i = #blocks local i = #blocks
Point.eachClosest(turtle.point, blocks, function(b) Point.eachClosest(turtle.point, blocks, function(b)
if turtle.isAborted() then if turtle.isAborted() then
return error('aborted')
end end
page.grid.nextBlock = b.displayName page.grid.nextBlock = b.name .. ':' .. b.metadata
-- Get the action again in case the user has ignored via UI -- Get the action again in case the user has ignored via UI
b.action = dictionary:get(b.name, b.metadata) or 'mine' b.action = dictionary:get(b.name, b.metadata) or 'mine'
@@ -441,20 +443,13 @@ local function mineChunk()
while true do while true do
status('scanning') status('scanning')
turtle.select(1) turtle.select(1)
turtle._goto({ x = mining.x + 8, z = mining.z + 8, y = y }) safeGoto(mining.x + 8, mining.z + 8, y)
scan() scan()
if turtle.isAborted() then
status('aborting')
return false
end
if turtle.getFuelLevel() < LOW_FUEL then if turtle.getFuelLevel() < LOW_FUEL then
refuel() refuel()
local veryMinFuel = Point.turtleDistance(turtle.point, { x = 0, y = 0, z = 0}) + 512 local veryMinFuel = Point.turtleDistance(turtle.point, { x = 0, y = 0, z = 0}) + 512
if turtle.getFuelLevel() < veryMinFuel then if turtle.getFuelLevel() < veryMinFuel then
page.statusBar:setValue('Not enough fuel to continue') error('Not enough fuel to continue')
page.statusBar:draw()
page:sync()
return false
end end
end end
inc() inc()
@@ -463,8 +458,6 @@ local function mineChunk()
break break
end end
end end
return true
end end
local function addTrash() local function addTrash()
@@ -515,82 +508,96 @@ end
local function main() local function main()
repeat repeat
if not mineChunk() then mineChunk()
return
end
Util.writeTable(PROGRESS_FILE, mining)
until not nextChunk() until not nextChunk()
end end
local success, msg
Event.addRoutine(function() Event.addRoutine(function()
turtle.run(function() turtle.reset()
turtle.reset()
if not fs.exists(DICTIONARY_FILE) or options.setTrash.value then if not fs.exists(DICTIONARY_FILE) or options.setTrash.value then
print('Add blocks to ignore, press enter when ready') print('Add blocks to ignore, press enter when ready')
read() read()
addTrash() addTrash()
end end
ejectTrash() ejectTrash()
turtle.initialize { turtle.initialize {
right = 'computercraft:advanced_modem', right = 'computercraft:advanced_modem',
left = 'minecraft:diamond_pickaxe', left = 'minecraft:diamond_pickaxe',
required = { required = {
'minecraft:bucket', 'minecraft:bucket',
'plethora:module', 'plethora:module',
}, },
GPS = true, GPS = true,
minFuel = 100, minFuel = 100,
-- searchFor = 'ironchest:iron_shulker_box_white' -- searchFor = 'ironchest:iron_shulker_box_white'
} }
turtle.setMoveCallback(function() turtle.setMoveCallback(function()
page.statusBar:setValue('fuel', Util.toBytes(turtle.getFuelLevel())) page.statusBar:setValue('fuel', Util.toBytes(turtle.getFuelLevel()))
page.statusBar:draw() page.statusBar:draw()
page:sync() page:sync()
end)
mining = Util.readTable(PROGRESS_FILE) or {
diameter = 1,
chunkIndex = 0,
x = 0, z = 0,
chunks = options.chunks.value,
home = Point.copy(turtle.point),
heading = turtle.point.heading, -- always using east for now
}
-- use coordinates relative to initial starting point
turtle.setPoint({
x = turtle.point.x - mining.home.x,
y = turtle.point.y - mining.home.y,
z = turtle.point.z - mining.home.z,
})
if not fs.exists(PROGRESS_FILE) then
Util.writeTable(PROGRESS_FILE, mining)
end
turtle.setPolicy(turtle.policies.digAttack)
turtle.setDigPolicy(turtle.digPolicies.turtleSafe)
turtle.setMovementStrategy('goto')
status('mining')
local s, m = pcall(main)
status(s and 'finished' or 'error')
turtle._goto({ x = 0, y = 0, z = 0 })
turtle.reset()
if not s and m then
_G.printError(m)
end
Event.exitPullEvents()
end) end)
mining = Util.readTable(PROGRESS_FILE) or {
diameter = 1,
chunkIndex = 0,
x = 0, z = 0,
chunks = options.chunks.value,
home = Point.copy(turtle.point),
heading = turtle.point.heading, -- always using east for now
}
if options.chunks.value ~= -1 then
mining.chunks = options.chunks.value
end
-- use coordinates relative to initial starting point
turtle.setPoint({
x = turtle.point.x - mining.home.x,
y = turtle.point.y - mining.home.y,
z = turtle.point.z - mining.home.z,
})
if not fs.exists(PROGRESS_FILE) then
Util.writeTable(PROGRESS_FILE, mining)
end
turtle.setPolicy(turtle.policies.digAttack)
turtle.setDigPolicy(turtle.digPolicies.turtleSafe)
turtle.setMovementStrategy('goto')
status('mining')
if isFinished() then
success = false
msg = 'Mining complete'
else
success, msg = pcall(main)
end
status(success and 'finished' or turtle.isAborted() and 'aborting' or 'error')
if turtle._goto({ x = 0, y = 0, z = 0 }) then
unload()
end
turtle.reset()
Event.exitPullEvents()
end)
Event.onTerminate(function()
turtle.abort(true)
end) end)
UI:setPage(page) UI:setPage(page)
UI:pullEvents() UI:pullEvents()
UI.term:reset() UI.term:reset()
turtle.reset()
if not success and msg then
_G.printError(msg)
end

View File

@@ -134,6 +134,9 @@
icon = "\0308\031f \0300 \0308 \ icon = "\0308\031f \0300 \0308 \
\0308\031f \0300 \030f \ \0308\031f \0300 \030f \
\0300\031f \030f ", \0300\031f \030f ",
iconExt = "\0308\0318\128\0300\159\129\0310\128\0308\159\129\0318\128\
\0300\0318\135\0310\128\128\030f\135\0300\031f\143\159\030f\0310\144\
\0300\128\030f\159\129\138\0300\031f\143\149\030f\0310\134",
run = "https://pastebin.com/raw/jyDH7mLH", run = "https://pastebin.com/raw/jyDH7mLH",
}, },
[ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = { [ "48d6857f6b2869d031f463b13aa34df47e18c548" ] = {
@@ -147,6 +150,7 @@
\030 \031f\030f\0310\136\140\140\030 ", \030 \031f\030f\0310\136\140\140\030 ",
run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw", run = "https://gist.github.com/LDDestroier/c7528d95bc0103545c2a/raw",
}, },
--[[
[ "d78f28759f255a0db76604ee560b87c4715a0da5" ] = { [ "d78f28759f255a0db76604ee560b87c4715a0da5" ] = {
title = "Sketch", title = "Sketch",
category = "Apps", category = "Apps",
@@ -158,6 +162,7 @@
\030 \031f\030f\0318\138\0308\031b\130\131\129\030f\0318\133", \030 \031f\030f\0318\138\0308\031b\130\131\129\030f\0318\133",
run = "http://pastebin.com/raw/Mm5hd97E", run = "http://pastebin.com/raw/Mm5hd97E",
}, },
]]
[ "58ec8d6e36e346d9f42eb43935652e3e58e2c829" ] = { [ "58ec8d6e36e346d9f42eb43935652e3e58e2c829" ] = {
title = "Mwm", title = "Mwm",
category = "Apps", category = "Apps",