mirror of
https://github.com/kepler155c/opus
synced 2025-03-02 15:50:01 +00:00
refined storage bug, obsidian script
This commit is contained in:
parent
17f4f8d9c1
commit
c57ff1541b
@ -1,5 +1,4 @@
|
|||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local Event = require('event')
|
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Socket = require('socket')
|
local Socket = require('socket')
|
||||||
local Terminal = require('terminal')
|
local Terminal = require('terminal')
|
||||||
@ -20,7 +19,6 @@ local options = {
|
|||||||
|
|
||||||
local SCRIPTS_PATH = '/apps/scripts'
|
local SCRIPTS_PATH = '/apps/scripts'
|
||||||
|
|
||||||
local ct = term.current()
|
|
||||||
local nullTerm = Terminal.getNullTerm(term.current())
|
local nullTerm = Terminal.getNullTerm(term.current())
|
||||||
local turtles = { }
|
local turtles = { }
|
||||||
local policies = {
|
local policies = {
|
||||||
@ -84,8 +82,9 @@ local page = UI.Page {
|
|||||||
x = 1, y = 8, rey = -2,
|
x = 1, y = 8, rey = -2,
|
||||||
scripts = UI.Grid {
|
scripts = UI.Grid {
|
||||||
tabTitle = 'Run',
|
tabTitle = 'Run',
|
||||||
|
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = '', key = 'label' },
|
{ heading = '', key = 'label' },
|
||||||
},
|
},
|
||||||
disableHeader = true,
|
disableHeader = true,
|
||||||
sortColumn = 'label',
|
sortColumn = 'label',
|
||||||
@ -93,6 +92,7 @@ local page = UI.Page {
|
|||||||
},
|
},
|
||||||
turtles = UI.Grid {
|
turtles = UI.Grid {
|
||||||
tabTitle = 'Sel',
|
tabTitle = 'Sel',
|
||||||
|
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'label', key = 'label' },
|
{ heading = 'label', key = 'label' },
|
||||||
{ heading = 'Dist', key = 'distance' },
|
{ heading = 'Dist', key = 'distance' },
|
||||||
@ -104,18 +104,20 @@ local page = UI.Page {
|
|||||||
autospace = true,
|
autospace = true,
|
||||||
},
|
},
|
||||||
inventory = UI.Grid {
|
inventory = UI.Grid {
|
||||||
|
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||||
tabTitle = 'Inv',
|
tabTitle = 'Inv',
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = '', key = 'qty', width = 2 },
|
{ heading = '', key = 'qty', width = 2 },
|
||||||
{ heading = 'Inventory', key = 'id', width = 13 },
|
{ heading = 'Inventory', key = 'id', width = UI.term.width - 5 },
|
||||||
},
|
},
|
||||||
disableHeader = true,
|
disableHeader = true,
|
||||||
sortColumn = 'index',
|
sortColumn = 'index',
|
||||||
},
|
},
|
||||||
policy = UI.Grid {
|
policy = UI.Grid {
|
||||||
tabTitle = 'Mod',
|
tabTitle = 'Mod',
|
||||||
|
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'label', key = 'label' },
|
{ heading = 'label', key = 'label' },
|
||||||
},
|
},
|
||||||
values = policies,
|
values = policies,
|
||||||
disableHeader = true,
|
disableHeader = true,
|
||||||
@ -187,7 +189,6 @@ function page.tabs.inventory:draw()
|
|||||||
end
|
end
|
||||||
if v.id then
|
if v.id then
|
||||||
local item = itemInfoDB:get({ v.id, v.dmg })
|
local item = itemInfoDB:get({ v.id, v.dmg })
|
||||||
debug(v)
|
|
||||||
if item then
|
if item then
|
||||||
v.id = item.displayName
|
v.id = item.displayName
|
||||||
else
|
else
|
||||||
@ -273,7 +274,7 @@ end
|
|||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:setPreviousPage()
|
UI:exitPullEvents()
|
||||||
elseif event.type == 'button_press' then
|
elseif event.type == 'button_press' then
|
||||||
if event.button.fn then
|
if event.button.fn then
|
||||||
self:runFunction(event.button.fn, event.button.nowrap)
|
self:runFunction(event.button.fn, event.button.nowrap)
|
||||||
@ -323,5 +324,5 @@ UI:setPage(page)
|
|||||||
|
|
||||||
page.tabs:activateTab(page.tabs[options.tab.value])
|
page.tabs:activateTab(page.tabs[options.tab.value])
|
||||||
|
|
||||||
Event.pullEvents(updateThread)
|
UI:pullEvents(updateThread)
|
||||||
UI.term:reset()
|
UI.term:reset()
|
||||||
|
58
apps/scripts/obsidian
Normal file
58
apps/scripts/obsidian
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
require = requireInjector(getfenv(1))
|
||||||
|
local Point = require('point')
|
||||||
|
|
||||||
|
local checkedNodes = { }
|
||||||
|
local nodes = { }
|
||||||
|
|
||||||
|
local function addNode(node)
|
||||||
|
|
||||||
|
local key = table.concat({ node.x, node.z }, ':')
|
||||||
|
|
||||||
|
for i = 0, 3 do
|
||||||
|
local hi = turtle.getHeadingInfo(i)
|
||||||
|
local testNode = { x = node.x + hi.xd, z = node.z + hi.zd }
|
||||||
|
|
||||||
|
key = table.concat({ testNode.x, testNode.z }, ':')
|
||||||
|
if not checkedNodes[key] then
|
||||||
|
nodes[key] = testNode
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function findObsidian()
|
||||||
|
while true do
|
||||||
|
local _,b = turtle.inspectDown()
|
||||||
|
local node = { x = turtle.point.x, z = turtle.point.z }
|
||||||
|
local key = table.concat({ node.x, node.z }, ':')
|
||||||
|
|
||||||
|
checkedNodes[key] = true
|
||||||
|
nodes[key] = nil
|
||||||
|
|
||||||
|
if b and b.name == 'minecraft:obsidian' then
|
||||||
|
turtle.digDown()
|
||||||
|
addNode(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
print(string.format('%d nodes remaining', Util.size(nodes)))
|
||||||
|
|
||||||
|
if Util.size(nodes) == 0 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = Point.closest(turtle.point, nodes)
|
||||||
|
if not turtle.gotoPoint(node) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
turtle.reset()
|
||||||
|
turtle.setPolicy(turtle.policies.digOnly)
|
||||||
|
local s, m = turtle.run(function() findObsidian() end)
|
||||||
|
if not s and m then
|
||||||
|
error(m)
|
||||||
|
end
|
||||||
|
turtle.goto(0, 0, 0, 0)
|
||||||
|
turtle.reset()
|
||||||
|
|
@ -7,37 +7,41 @@ function ChestProvider:init(args)
|
|||||||
args = args or { }
|
args = args or { }
|
||||||
|
|
||||||
self.items = { } -- consolidated item info
|
self.items = { } -- consolidated item info
|
||||||
self.stacks = { } -- raw stack info
|
self.cache = { }
|
||||||
self.name = 'chest'
|
self.name = 'chest'
|
||||||
self.direction = args.direction or 'up'
|
self.direction = args.direction or 'up'
|
||||||
self.wrapSide = args.wrapSide or 'bottom'
|
self.wrapSide = args.wrapSide or 'bottom'
|
||||||
self.p = peripheral.wrap(self.wrapSide)
|
self.p = peripheral.wrap(self.wrapSide)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:isValid()
|
function ChestProvider:isValid()
|
||||||
return self.p and self.p.list
|
return self.p and self.p.list
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:refresh()
|
function ChestProvider:refresh()
|
||||||
if self.p then
|
if self.p then
|
||||||
--self.p.condenseItems()
|
|
||||||
self.items = { }
|
self.items = { }
|
||||||
self.stacks = self.p.list()
|
for k,s in pairs(self.p.list()) do
|
||||||
for k,s in pairs(self.stacks) do
|
|
||||||
|
|
||||||
local key = s.name .. ':' .. s.damage
|
local key = s.name .. ':' .. s.damage
|
||||||
local entry = self.items[key]
|
local entry = self.items[key]
|
||||||
if not entry then
|
if not entry then
|
||||||
local meta = self.p.getItemMeta(k)
|
entry = self.cache[key]
|
||||||
entry = {
|
if not entry then
|
||||||
id = s.name,
|
local meta = self.p.getItemMeta(k) -- slow method.. cache for speed
|
||||||
dmg = s.damage,
|
entry = {
|
||||||
name = meta.displayName,
|
id = s.name,
|
||||||
max_size = meta.maxCount,
|
dmg = s.damage,
|
||||||
qty = 0,
|
name = meta.displayName,
|
||||||
}
|
max_size = meta.maxCount,
|
||||||
|
}
|
||||||
|
self.cache[key] = entry
|
||||||
|
end
|
||||||
|
entry = Util.shallowCopy(entry)
|
||||||
self.items[key] = entry
|
self.items[key] = entry
|
||||||
|
entry.qty = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
entry.qty = entry.qty + s.count
|
entry.qty = entry.qty + s.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -45,16 +49,15 @@ function ChestProvider:refresh()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:getItemInfo(id, dmg)
|
function ChestProvider:getItemInfo(id, dmg)
|
||||||
|
|
||||||
for key,item in pairs(self.items) do
|
for key,item in pairs(self.items) do
|
||||||
if item.id == id and item.dmg == dmg then
|
if item.id == id and item.dmg == dmg then
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:craft(id, dmg, qty)
|
function ChestProvider:craft(id, dmg, qty)
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:craftItems(items)
|
function ChestProvider:craftItems(items)
|
||||||
@ -62,8 +65,8 @@ end
|
|||||||
|
|
||||||
function ChestProvider:provide(item, qty, slot)
|
function ChestProvider:provide(item, qty, slot)
|
||||||
if self.p then
|
if self.p then
|
||||||
self:refresh()
|
local stacks = self.p.list()
|
||||||
for key,stack in pairs(self.stacks) do
|
for key,stack in pairs(stacks) do
|
||||||
if stack.name == item.id and stack.damage == item.dmg then
|
if stack.name == item.id and stack.damage == item.dmg then
|
||||||
local amount = math.min(qty, stack.count)
|
local amount = math.min(qty, stack.count)
|
||||||
self.p.pushItems(self.direction, key, amount, slot)
|
self.p.pushItems(self.direction, key, amount, slot)
|
||||||
@ -75,7 +78,7 @@ function ChestProvider:provide(item, qty, slot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestProvider:extract(slot, qty)
|
function ChestProvider:extract(slot, qty)
|
||||||
if self.p then
|
if self.p then
|
||||||
self.p.pushItems(self.direction, slot, qty)
|
self.p.pushItems(self.direction, slot, qty)
|
||||||
|
@ -34,8 +34,10 @@ function RefinedProvider:getCachedItemDetails(item)
|
|||||||
if not detail then
|
if not detail then
|
||||||
detail = self.findItem(item)
|
detail = self.findItem(item)
|
||||||
if detail then
|
if detail then
|
||||||
Util.merge(detail, detail.getMetadata())
|
local meta
|
||||||
if detail.displayName then
|
pcall(function() meta = detail.getMetadata() end)
|
||||||
|
if meta then
|
||||||
|
Util.merge(detail, meta)
|
||||||
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
|
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
|
||||||
detail.displayName = detail.displayName .. ' (damaged)'
|
detail.displayName = detail.displayName .. ' (damaged)'
|
||||||
end
|
end
|
||||||
@ -95,9 +97,10 @@ end
|
|||||||
|
|
||||||
function RefinedProvider:isCrafting(item)
|
function RefinedProvider:isCrafting(item)
|
||||||
for _,task in pairs(self.getCraftingTasks()) do
|
for _,task in pairs(self.getCraftingTasks()) do
|
||||||
if task.name == item.name and
|
local output = task.getPattern().outputs[1]
|
||||||
task.damage == item.damage and
|
if output.name == item.name and
|
||||||
task.nbtHash == item.nbtHash then
|
output.damage == item.damage and
|
||||||
|
output.nbtHash == item.nbtHash then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user