app tweaks
This commit is contained in:
161
builder/viewer.lua
Normal file
161
builder/viewer.lua
Normal file
@@ -0,0 +1,161 @@
|
||||
local n = peripheral.find "neuralInterface"
|
||||
|
||||
if not n then error "run on neural interface" end
|
||||
|
||||
if not n.hasModule "plethora:glasses" then error "needs overlay glasses" end
|
||||
if not n.hasModule "plethora:sensor" or not n.hasModule "plethora:introspection" or not n.getMetaOwner then error "needs entity sensor + bound introspection module" end
|
||||
|
||||
local itemDB = require('core.itemDB')
|
||||
local Schematic = require('builder.schematic')
|
||||
local TableDB = require('core.tableDB')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
|
||||
local BUILDER_DIR = 'usr/builder'
|
||||
|
||||
local Builder = require('builder.builder')
|
||||
|
||||
Builder.schematic = Schematic()
|
||||
|
||||
local function convertSingleBack(item)
|
||||
if item then
|
||||
item.id = item.name
|
||||
item.dmg = item.damage
|
||||
item.qty = item.count
|
||||
item.max_size = item.maxCount
|
||||
item.display_name = item.displayName
|
||||
end
|
||||
return item
|
||||
end
|
||||
|
||||
local function convertBack(t)
|
||||
for _,v in pairs(t) do
|
||||
convertSingleBack(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--[[-- SubDB --]]--
|
||||
local subDB = TableDB({
|
||||
fileName = fs.combine(BUILDER_DIR, 'sub.db'),
|
||||
})
|
||||
|
||||
function subDB:load()
|
||||
if fs.exists(self.fileName) then
|
||||
TableDB.load(self)
|
||||
elseif not Builder.isCommandComputer then
|
||||
self:seedDB()
|
||||
end
|
||||
end
|
||||
|
||||
function subDB:seedDB()
|
||||
self.data = {
|
||||
[ "minecraft:redstone_wire:0" ] = "minecraft:redstone:0",
|
||||
[ "minecraft:wall_sign:0" ] = "minecraft:sign:0",
|
||||
[ "minecraft:standing_sign:0" ] = "minecraft:sign:0",
|
||||
[ "minecraft:potatoes:0" ] = "minecraft:potato:0",
|
||||
[ "minecraft:unlit_redstone_torch:0" ] = "minecraft:redstone_torch:0",
|
||||
[ "minecraft:powered_repeater:0" ] = "minecraft:repeater:0",
|
||||
[ "minecraft:unpowered_repeater:0" ] = "minecraft:repeater:0",
|
||||
[ "minecraft:carrots:0" ] = "minecraft:carrot:0",
|
||||
[ "minecraft:cocoa:0" ] = "minecraft:dye:3",
|
||||
[ "minecraft:unpowered_comparator:0" ] = "minecraft:comparator:0",
|
||||
[ "minecraft:powered_comparator:0" ] = "minecraft:comparator:0",
|
||||
[ "minecraft:piston_head:0" ] = "minecraft:air:0",
|
||||
[ "minecraft:piston_extension:0" ] = "minecraft:air:0",
|
||||
[ "minecraft:portal:0" ] = "minecraft:air:0",
|
||||
[ "minecraft:double_wooden_slab:0" ] = "minecraft:planks:0",
|
||||
[ "minecraft:double_wooden_slab:1" ] = "minecraft:planks:1",
|
||||
[ "minecraft:double_wooden_slab:2" ] = "minecraft:planks:2",
|
||||
[ "minecraft:double_wooden_slab:3" ] = "minecraft:planks:3",
|
||||
[ "minecraft:double_wooden_slab:4" ] = "minecraft:planks:4",
|
||||
[ "minecraft:double_wooden_slab:5" ] = "minecraft:planks:5",
|
||||
[ "minecraft:lit_redstone_lamp:0" ] = "minecraft:redstone_lamp:0",
|
||||
[ "minecraft:double_stone_slab:1" ] = "minecraft:sandstone:0",
|
||||
[ "minecraft:double_stone_slab:2" ] = "minecraft:planks:0",
|
||||
[ "minecraft:double_stone_slab:3" ] = "minecraft:cobblestone:0",
|
||||
[ "minecraft:double_stone_slab:4" ] = "minecraft:brick_block:0",
|
||||
[ "minecraft:double_stone_slab:5" ] = "minecraft:stonebrick:0",
|
||||
[ "minecraft:double_stone_slab:6" ] = "minecraft:nether_brick:0",
|
||||
[ "minecraft:double_stone_slab:7" ] = "minecraft:quartz_block:0",
|
||||
[ "minecraft:double_stone_slab:9" ] = "minecraft:sandstone:2",
|
||||
[ "minecraft:double_stone_slab2:0" ] = "minecraft:sandstone:0",
|
||||
[ "minecraft:stone_slab:2" ] = "minecraft:wooden_slab:0",
|
||||
[ "minecraft:wheat:0" ] = "minecraft:wheat_seeds:0",
|
||||
[ "minecraft:flowing_water:0" ] = "minecraft:air:0",
|
||||
[ "minecraft:lit_furnace:0" ] = "minecraft:furnace:0",
|
||||
[ "minecraft:wall_banner:0" ] = "minecraft:banner:0",
|
||||
[ "minecraft:standing_banner:0" ] = "minecraft:banner:0",
|
||||
[ "minecraft:tripwire:0" ] = "minecraft:string:0",
|
||||
[ "minecraft:pumpkin_stem:0" ] = "minecraft:pumpkin_seeds:0",
|
||||
}
|
||||
self.dirty = true
|
||||
self:flush()
|
||||
end
|
||||
|
||||
function subDB:add(s)
|
||||
TableDB.add(self, { s.id, s.dmg }, table.concat({ s.sid, s.sdmg }, ':'))
|
||||
self:flush()
|
||||
end
|
||||
|
||||
function subDB:remove(s)
|
||||
-- TODO: tableDB.remove should take table key
|
||||
TableDB.remove(self, s.id .. ':' .. s.dmg)
|
||||
self:flush()
|
||||
end
|
||||
|
||||
function subDB:extract(s)
|
||||
local id, dmg = s:match('(.+):(%d+)')
|
||||
return id, tonumber(dmg)
|
||||
end
|
||||
|
||||
function subDB:getSubstitutedItem(id, dmg)
|
||||
local sub = TableDB.get(self, { id, dmg })
|
||||
if sub then
|
||||
id, dmg = self:extract(sub)
|
||||
end
|
||||
return { id = id, dmg = dmg }
|
||||
end
|
||||
|
||||
function subDB:lookupBlocksForSub(sid, sdmg)
|
||||
local t = { }
|
||||
for k,v in pairs(self.data) do
|
||||
local id, dmg = self:extract(v)
|
||||
if id == sid and dmg == sdmg then
|
||||
id, dmg = self:extract(k)
|
||||
t[k] = { id = id, dmg = dmg, sid = sid, sdmg = sdmg }
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--[[-- startup logic --]]--
|
||||
local args = {...}
|
||||
if #args < 1 then
|
||||
error('supply file name')
|
||||
end
|
||||
|
||||
subDB:load()
|
||||
|
||||
print('Loading schematic')
|
||||
Builder.schematic:load(args[1])
|
||||
print('Substituting blocks')
|
||||
|
||||
Builder.subDB = subDB
|
||||
Builder:substituteBlocks(Util.throttle())
|
||||
|
||||
local cn = n.canvas3d().create()
|
||||
|
||||
local pos = n.getMetaOwner().withinBlock
|
||||
cn.recenter({-pos.x, -pos.y, -pos.z})
|
||||
for i = 1, #Builder.schematic.blocks do
|
||||
b = Builder.schematic:getComputedBlock(i)
|
||||
if b.id ~= "minecraft:air" then
|
||||
cn.addBox(b.x, b.y-10, b.z, 0xffffff40).setDepthTested(false)
|
||||
end
|
||||
end
|
||||
|
||||
pcall(read)
|
||||
cn.clear()
|
||||
@@ -12,6 +12,9 @@ local ni = peripheral.find('neuralInterface')
|
||||
if not context.state.depositAll then
|
||||
context.state.depositAll = { }
|
||||
end
|
||||
if not context.state.depositAll.retain then
|
||||
context.state.depositAll.retain = { }
|
||||
end
|
||||
|
||||
local page = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
@@ -58,6 +61,7 @@ function page:updateInventoryList()
|
||||
else
|
||||
list[key].count = list[key].count + item.count
|
||||
end
|
||||
list[key].key = key
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,19 +76,30 @@ function page:enable()
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
function page.items:getRowTextColor(row)
|
||||
if context.state.depositAll.retain[row.key] then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row)
|
||||
end
|
||||
|
||||
function page:depositAll()
|
||||
self.notification:info('Depositing all items...')
|
||||
|
||||
local inv = ni.getInventory().list()
|
||||
|
||||
for slot, item in pairs(inv) do
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = 'inventory',
|
||||
slot = slot,
|
||||
count = item.count,
|
||||
})
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not context.state.depositAll.retain[key] then
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = 'inventory',
|
||||
slot = slot,
|
||||
count = item.count,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -94,6 +109,16 @@ function page:eventHandler(event)
|
||||
context.state.depositAll.includeHotbar = event.checked
|
||||
page:updateInventoryList()
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
local key = event.selected.key
|
||||
if context.state.depositAll.retain[key] then
|
||||
context.state.depositAll.retain[key] = nil
|
||||
else
|
||||
context.state.depositAll.retain[key] = true
|
||||
end
|
||||
context:setState('depositAll', context.state.depositAll)
|
||||
self.items:draw()
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update('miloRemote', context.state)
|
||||
page:depositAll()
|
||||
|
||||
@@ -33,6 +33,7 @@ local function display(meta)
|
||||
canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
|
||||
canvas.pitch.setShadow(true)
|
||||
canvas.pitch.setScale(.75)
|
||||
canvas.group.addItem({ 5, 30 }, 'minecraft:elytra')
|
||||
canvas.group2 = canvas.addGroup({ 80, 10 })
|
||||
canvas.group2.addLines(
|
||||
{ 0, 0 },
|
||||
@@ -143,5 +144,9 @@ parallel.waitForAny(
|
||||
end
|
||||
print('Waiting for 5 seconds before restarting')
|
||||
os.sleep(5)
|
||||
modules = _G.peripheral.wrap('back')
|
||||
canvas = modules and modules.canvas and modules.canvas()
|
||||
end
|
||||
end)
|
||||
|
||||
clearDisplay()
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
run = "elytraFly.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "fisher" ] = {
|
||||
title = "Fisher",
|
||||
category = "Neural",
|
||||
run = "fisher.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "9101fc1744ab274aaa0b54ee22b14ca53ee6e236" ] = {
|
||||
title = "Sensor",
|
||||
category = "Neural",
|
||||
|
||||
@@ -10,31 +10,61 @@ local function Syntax(missing)
|
||||
end
|
||||
|
||||
local kinetic = device['plethora:kinetic'] or Syntax('kinetic augment')
|
||||
local sensor = device['plethora:sensor'] or Syntax('entity sensor')
|
||||
local sensor = device['plethora:sensor'] or Syntax('entity sensor')
|
||||
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
|
||||
|
||||
if not sensor.getMetaOwner then Syntax('introspection module') end
|
||||
|
||||
local depth = -3
|
||||
local icon
|
||||
local scales = { .2, .4, .6, .8, 1, .8, .6, .4 }
|
||||
local scale = 0
|
||||
|
||||
while true do
|
||||
local meta = sensor.getMetaByName('unknown')
|
||||
if not meta then
|
||||
local owner = sensor.getMetaOwner()
|
||||
local held = owner.heldItem and owner.heldItem.getMetadata()
|
||||
if held and held.rawName == 'item.fishingRod' then
|
||||
kinetic.use(.2)
|
||||
print('casting')
|
||||
os.sleep(.5)
|
||||
meta = sensor.getMetaByName('unknown')
|
||||
depth = meta and meta.y - .5 or depth
|
||||
if canvas then
|
||||
local w, h = canvas.getSize()
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||
end
|
||||
|
||||
local function fish()
|
||||
while true do
|
||||
local meta = sensor.getMetaByName('unknown')
|
||||
if not meta then
|
||||
local owner = sensor.getMetaOwner()
|
||||
local held = owner.heldItem and owner.heldItem.getMetadata()
|
||||
if held and held.rawName == 'item.fishingRod' then
|
||||
if icon then
|
||||
icon.setItem('minecraft:fish', 1)
|
||||
end
|
||||
kinetic.use(.2)
|
||||
print('casting')
|
||||
os.sleep(.5)
|
||||
meta = sensor.getMetaByName('unknown')
|
||||
depth = meta and meta.y - .5 or depth
|
||||
else
|
||||
if icon then
|
||||
icon.setItem('minecraft:fishing_rod')
|
||||
end
|
||||
print('waiting for fishing rod to be selected')
|
||||
end
|
||||
scale = 1
|
||||
icon.setScale(1)
|
||||
os.sleep(1)
|
||||
else
|
||||
print('waiting for fishing rod to be selected')
|
||||
if meta.y < depth then
|
||||
kinetic.use(.3)
|
||||
print('reeled in')
|
||||
end
|
||||
if icon then
|
||||
scale = scale + 1
|
||||
icon.setScale(scales[(scale % #scales) + 1])
|
||||
end
|
||||
os.sleep(.1)
|
||||
end
|
||||
os.sleep(1)
|
||||
else
|
||||
if meta.y < depth then
|
||||
kinetic.use(.3)
|
||||
print('reeled in')
|
||||
end
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
pcall(fish)
|
||||
|
||||
if icon then
|
||||
icon.remove()
|
||||
end
|
||||
|
||||
@@ -13,10 +13,13 @@ local k = require("k")
|
||||
local jua = require("jua")
|
||||
|
||||
local await = jua.await
|
||||
local device = _G.device
|
||||
local json = _G.json
|
||||
local rs = _G.rs
|
||||
local textutils = _G.textutils
|
||||
|
||||
local chat = device['plethora:chat']
|
||||
|
||||
rs.setOutput('top', false)
|
||||
|
||||
r.init(jua)
|
||||
@@ -116,6 +119,11 @@ local function handleTransaction(transaction)
|
||||
elseif e == 'shop_provided' and p1 == uid then
|
||||
local extra = value - (t.price * p2)
|
||||
logTransaction(t, { purchased = p2 })
|
||||
if chat and chat.tell then
|
||||
local msg = string.format('PURCHASE: %s bought %d %s for %s',
|
||||
recipient, p2, t.itemId, t.price * p2)
|
||||
chat.tell(msg)
|
||||
end
|
||||
if extra > 0 then
|
||||
print('extra: ' .. extra)
|
||||
refundTransaction(extra, "message=Here's your change!")
|
||||
@@ -150,5 +158,5 @@ end)
|
||||
|
||||
rs.setOutput('top', false)
|
||||
if not s then
|
||||
error(m)
|
||||
error(m, 2)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user