recipe nbts + item get/add helper

This commit is contained in:
kepler155c@gmail.com
2019-01-04 00:29:03 -05:00
parent d0a7a6e488
commit 6606975f5b
7 changed files with 62 additions and 41 deletions

View File

@@ -18,6 +18,10 @@ local recipeTab = UI.Window {
},
sortColumn = 'slot',
},
ignoreResultNBT = UI.Button {
x = 2, y = -2,
text = 'Ignore Result NBT', event = 'ignore_result_nbt',
},
ignoreNBT = UI.Button {
x = -13, y = -2,
text = 'Ignore NBT', event = 'ignore_nbt',
@@ -38,12 +42,33 @@ function recipeTab:setItem(item)
key = v,
})
end
local key = itemDB:splitKey(self.recipe.result)
self.ignoreResultNBT.inactive = not key.nbtHash
end
self.grid:setValues(t)
end
function recipeTab:eventHandler(event)
if event.type == 'ignore_nbt' then
if event.type == 'ignore_result_nbt' then
-- remove old entry
Milo:updateRecipe(self.recipe.result)
local item = itemDB:splitKey(self.recipe.result)
item.nbtHash = nil
self.recipe.result = itemDB:makeKey(item)
-- add updated entry
Milo:updateRecipe(self.recipe.result, self.recipe)
self.ignoreResultNBT.inactive = true
self:emit({ type = 'info_message', message = 'Recipe updated' })
elseif event.type == 'grid_focus_row' then
local key = itemDB:splitKey(event.selected.key)
self.ignoreNBT.inactive = not key.nbtHash
self.ignoreNBT:draw()
elseif event.type == 'ignore_nbt' then
local selected = self.grid:getSelected()
local item = itemDB:splitKey(selected.key)
item.nbtHash = nil

View File

@@ -1,7 +1,6 @@
local Craft = require('craft2')
local itemDB = require('itemDB')
local Milo = require('milo')
local Util = require('util')
local BLAZE_POWDER = "minecraft:blaze_powder:0"
@@ -26,12 +25,7 @@ function PotionImportTask:cycle(context)
if blazePowder then
context.storage:export(bs, 5, 1, blazePowder)
else
local item = itemDB:get(BLAZE_POWDER)
if item then
item = Util.shallowCopy(item)
else
item = Milo:splitKey(BLAZE_POWDER)
end
local item = itemDB:get(BLAZE_POWDER) or Milo:splitKey(BLAZE_POWDER)
item.requested = 1
Milo:requestCrafting(item)
end

View File

@@ -57,12 +57,8 @@ function page.tabs.inventory:enable()
for k, item in pairs(inv) do
local key = itemDB:makeKey(item)
if not list[key] then
local cItem = itemDB:get(item)
if not cItem then
cItem = itemDB:add(ni.getInventory().getItemMeta(k))
end
local cItem = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end)
if cItem then
cItem = Util.shallowCopy(cItem)
cItem.key = makeKey(cItem)
list[key] = cItem
end
@@ -138,10 +134,7 @@ Event.onInterval(5, function()
if empty then
for k,v in pairs(inv) do
local item = itemDB:get(v)
if not item then
item = itemDB:add(ni.getInventory().getItemMeta(k))
end
local item = itemDB:get(v, function() ni.getInventory().getItemMeta(k) end)
if item then
if context.state.autostore[makeKey(item)] then
ni.getInventory().pushItems(target, k, v.count, slot)