autocrafting improvements

This commit is contained in:
kepler155c
2018-01-10 16:48:23 -05:00
parent d4cf76b8e8
commit f7893ab2fe
24 changed files with 1798 additions and 159 deletions

View File

@@ -1,23 +1,33 @@
local JSON = require('json')
local TableDB = require('tableDB')
local fs = _G.fs
local NAME_DIR = '/usr/etc/names'
local nameDB = TableDB()
function nameDB:load()
local blocks = JSON.decodeFromFile('usr/etc/blocks.json')
local files = fs.list(NAME_DIR)
table.sort(files)
if not blocks then
error('Unable to read usr/etc/blocks.json')
end
for _,file in ipairs(files) do
local mod = file:match('(%S+).json')
local blocks = JSON.decodeFromFile(fs.combine(NAME_DIR, file))
for strId, block in pairs(blocks) do
strId = 'minecraft:' .. strId
if type(block.name) == 'string' then
self.data[strId .. ':0'] = block.name
else
for nid,name in pairs(block.name) do
self.data[strId .. ':' .. (nid-1)] = name
if not blocks then
error('Unable to read ' .. fs.combine(NAME_DIR, file))
end
for strId, block in pairs(blocks) do
strId = string.format('%s:%s', mod, strId)
if type(block.name) == 'string' then
self.data[strId .. ':0'] = block.name
else
for nid,name in pairs(block.name) do
self.data[strId .. ':' .. (nid-1)] = name
end
end
end
end