better auto deposit

This commit is contained in:
kepler155c@gmail.com
2019-01-02 06:03:42 -05:00
parent 759f7b0fa6
commit 1aa5dfdeaf
2 changed files with 24 additions and 9 deletions

View File

@@ -45,6 +45,11 @@ local page = UI.Page {
}, },
} }
local function makeKey(item)
local damage = item.maxDamage == 0 and item.damage
return itemDB:makeKey({ name = item.name, damage = damage })
end
function page.tabs.inventory:enable() function page.tabs.inventory:enable()
local inv = ni.getInventory().list() local inv = ni.getInventory().list()
local list = { } local list = { }
@@ -58,11 +63,12 @@ function page.tabs.inventory:enable()
end end
if cItem then if cItem then
cItem = Util.shallowCopy(cItem) cItem = Util.shallowCopy(cItem)
cItem.key = key cItem.key = makeKey(cItem)
list[key] = cItem list[key] = cItem
end end
end end
end end
self.grid:setValues(list) self.grid:setValues(list)
itemDB:flush() itemDB:flush()
@@ -79,10 +85,11 @@ end
function page.tabs.inventory:eventHandler(event) function page.tabs.inventory:eventHandler(event)
if event.type == 'grid_select' then if event.type == 'grid_select' then
local autostore = context.state.autostore or { } local autostore = context.state.autostore or { }
if autostore[event.selected.key] then local key = makeKey(event.selected)
autostore[event.selected.key] = nil if autostore[key] then
autostore[key] = nil
else else
autostore[event.selected.key] = true autostore[key] = true
end end
context:setState('autostore', autostore) context:setState('autostore', autostore)
self.grid:draw() self.grid:draw()
@@ -106,7 +113,7 @@ end
function page.tabs.autostore:eventHandler(event) function page.tabs.autostore:eventHandler(event)
if event.type == 'grid_select' then if event.type == 'grid_select' then
local key = itemDB:makeKey(event.selected) local key = makeKey(event.selected)
context.state.autostore[key] = nil context.state.autostore[key] = nil
context:setState('autostore', context.state.autostore) context:setState('autostore', context.state.autostore)
Util.removeByValue(self.grid.values, event.selected) Util.removeByValue(self.grid.values, event.selected)
@@ -131,10 +138,15 @@ Event.onInterval(5, function()
if empty then if empty then
for k,v in pairs(inv) do for k,v in pairs(inv) do
local key = itemDB:makeKey(v) local item = itemDB:get(v)
if context.state.autostore[key] then if not item then
ni.getInventory().pushItems(target, k, v.count, slot) item = itemDB:add(ni.getInventory().getItemMeta(k))
break end
if item then
if context.state.autostore[makeKey(item)] then
ni.getInventory().pushItems(target, k, v.count, slot)
break
end
end end
end end
end end

View File

@@ -4,7 +4,9 @@ local hostiles = {
BabySkeleton = true, BabySkeleton = true,
BabyZombie = true, BabyZombie = true,
Bat = true, Bat = true,
Blaze = true,
Creeper = true, Creeper = true,
Ghast = true,
Husk = true, Husk = true,
LavaSlime = true, LavaSlime = true,
PigZombie = true, PigZombie = true,
@@ -12,6 +14,7 @@ local hostiles = {
Slime = true, Slime = true,
Spider = true, Spider = true,
Witch = true, Witch = true,
WitherSkeleton = true,
Zombie = true, Zombie = true,
ZombieVillager = true, ZombieVillager = true,
} }