mirror of
https://github.com/kepler155c/opus
synced 2025-03-01 15:20: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))
|
||||
local Event = require('event')
|
||||
local UI = require('ui')
|
||||
local Socket = require('socket')
|
||||
local Terminal = require('terminal')
|
||||
@ -20,7 +19,6 @@ local options = {
|
||||
|
||||
local SCRIPTS_PATH = '/apps/scripts'
|
||||
|
||||
local ct = term.current()
|
||||
local nullTerm = Terminal.getNullTerm(term.current())
|
||||
local turtles = { }
|
||||
local policies = {
|
||||
@ -84,8 +82,9 @@ local page = UI.Page {
|
||||
x = 1, y = 8, rey = -2,
|
||||
scripts = UI.Grid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
@ -93,6 +92,7 @@ local page = UI.Page {
|
||||
},
|
||||
turtles = UI.Grid {
|
||||
tabTitle = 'Sel',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
@ -104,18 +104,20 @@ local page = UI.Page {
|
||||
autospace = true,
|
||||
},
|
||||
inventory = UI.Grid {
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'qty', width = 2 },
|
||||
{ heading = 'Inventory', key = 'id', width = 13 },
|
||||
{ heading = '', key = 'qty', width = 2 },
|
||||
{ heading = 'Inventory', key = 'id', width = UI.term.width - 5 },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
},
|
||||
policy = UI.Grid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'label', key = 'label' },
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
@ -187,7 +189,6 @@ function page.tabs.inventory:draw()
|
||||
end
|
||||
if v.id then
|
||||
local item = itemInfoDB:get({ v.id, v.dmg })
|
||||
debug(v)
|
||||
if item then
|
||||
v.id = item.displayName
|
||||
else
|
||||
@ -273,7 +274,7 @@ end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'quit' then
|
||||
UI:setPreviousPage()
|
||||
UI:exitPullEvents()
|
||||
elseif event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
self:runFunction(event.button.fn, event.button.nowrap)
|
||||
@ -323,5 +324,5 @@ UI:setPage(page)
|
||||
|
||||
page.tabs:activateTab(page.tabs[options.tab.value])
|
||||
|
||||
Event.pullEvents(updateThread)
|
||||
UI:pullEvents(updateThread)
|
||||
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 { }
|
||||
|
||||
self.items = { } -- consolidated item info
|
||||
self.stacks = { } -- raw stack info
|
||||
self.cache = { }
|
||||
self.name = 'chest'
|
||||
self.direction = args.direction or 'up'
|
||||
self.wrapSide = args.wrapSide or 'bottom'
|
||||
self.p = peripheral.wrap(self.wrapSide)
|
||||
end
|
||||
|
||||
|
||||
function ChestProvider:isValid()
|
||||
return self.p and self.p.list
|
||||
end
|
||||
|
||||
|
||||
function ChestProvider:refresh()
|
||||
if self.p then
|
||||
--self.p.condenseItems()
|
||||
self.items = { }
|
||||
self.stacks = self.p.list()
|
||||
for k,s in pairs(self.stacks) do
|
||||
for k,s in pairs(self.p.list()) do
|
||||
|
||||
local key = s.name .. ':' .. s.damage
|
||||
local entry = self.items[key]
|
||||
if not entry then
|
||||
local meta = self.p.getItemMeta(k)
|
||||
entry = {
|
||||
id = s.name,
|
||||
dmg = s.damage,
|
||||
name = meta.displayName,
|
||||
max_size = meta.maxCount,
|
||||
qty = 0,
|
||||
}
|
||||
entry = self.cache[key]
|
||||
if not entry then
|
||||
local meta = self.p.getItemMeta(k) -- slow method.. cache for speed
|
||||
entry = {
|
||||
id = s.name,
|
||||
dmg = s.damage,
|
||||
name = meta.displayName,
|
||||
max_size = meta.maxCount,
|
||||
}
|
||||
self.cache[key] = entry
|
||||
end
|
||||
entry = Util.shallowCopy(entry)
|
||||
self.items[key] = entry
|
||||
entry.qty = 0
|
||||
end
|
||||
|
||||
entry.qty = entry.qty + s.count
|
||||
end
|
||||
end
|
||||
@ -45,16 +49,15 @@ function ChestProvider:refresh()
|
||||
end
|
||||
|
||||
function ChestProvider:getItemInfo(id, dmg)
|
||||
|
||||
|
||||
for key,item in pairs(self.items) do
|
||||
if item.id == id and item.dmg == dmg then
|
||||
return item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChestProvider:craft(id, dmg, qty)
|
||||
return false
|
||||
end
|
||||
|
||||
function ChestProvider:craftItems(items)
|
||||
@ -62,8 +65,8 @@ end
|
||||
|
||||
function ChestProvider:provide(item, qty, slot)
|
||||
if self.p then
|
||||
self:refresh()
|
||||
for key,stack in pairs(self.stacks) do
|
||||
local stacks = self.p.list()
|
||||
for key,stack in pairs(stacks) do
|
||||
if stack.name == item.id and stack.damage == item.dmg then
|
||||
local amount = math.min(qty, stack.count)
|
||||
self.p.pushItems(self.direction, key, amount, slot)
|
||||
@ -75,7 +78,7 @@ function ChestProvider:provide(item, qty, slot)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ChestProvider:extract(slot, qty)
|
||||
if self.p then
|
||||
self.p.pushItems(self.direction, slot, qty)
|
||||
|
@ -34,8 +34,10 @@ function RefinedProvider:getCachedItemDetails(item)
|
||||
if not detail then
|
||||
detail = self.findItem(item)
|
||||
if detail then
|
||||
Util.merge(detail, detail.getMetadata())
|
||||
if detail.displayName then
|
||||
local meta
|
||||
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
|
||||
detail.displayName = detail.displayName .. ' (damaged)'
|
||||
end
|
||||
@ -95,9 +97,10 @@ end
|
||||
|
||||
function RefinedProvider:isCrafting(item)
|
||||
for _,task in pairs(self.getCraftingTasks()) do
|
||||
if task.name == item.name and
|
||||
task.damage == item.damage and
|
||||
task.nbtHash == item.nbtHash then
|
||||
local output = task.getPattern().outputs[1]
|
||||
if output.name == item.name and
|
||||
output.damage == item.damage and
|
||||
output.nbtHash == item.nbtHash then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user