From 1aa5dfdeafcf366a95de13070d7b8cca09587730 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 2 Jan 2019 06:03:42 -0500 Subject: [PATCH] better auto deposit --- milo/plugins/remote/autostore.lua | 30 +++++++++++++++++++++--------- neural/apis/neural/mobs.lua | 3 +++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/milo/plugins/remote/autostore.lua b/milo/plugins/remote/autostore.lua index e044bd6..1c514fc 100644 --- a/milo/plugins/remote/autostore.lua +++ b/milo/plugins/remote/autostore.lua @@ -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() local inv = ni.getInventory().list() local list = { } @@ -58,11 +63,12 @@ function page.tabs.inventory:enable() end if cItem then cItem = Util.shallowCopy(cItem) - cItem.key = key + cItem.key = makeKey(cItem) list[key] = cItem end end end + self.grid:setValues(list) itemDB:flush() @@ -79,10 +85,11 @@ end function page.tabs.inventory:eventHandler(event) if event.type == 'grid_select' then local autostore = context.state.autostore or { } - if autostore[event.selected.key] then - autostore[event.selected.key] = nil + local key = makeKey(event.selected) + if autostore[key] then + autostore[key] = nil else - autostore[event.selected.key] = true + autostore[key] = true end context:setState('autostore', autostore) self.grid:draw() @@ -106,7 +113,7 @@ end function page.tabs.autostore:eventHandler(event) if event.type == 'grid_select' then - local key = itemDB:makeKey(event.selected) + local key = makeKey(event.selected) context.state.autostore[key] = nil context:setState('autostore', context.state.autostore) Util.removeByValue(self.grid.values, event.selected) @@ -131,10 +138,15 @@ Event.onInterval(5, function() if empty then for k,v in pairs(inv) do - local key = itemDB:makeKey(v) - if context.state.autostore[key] then - ni.getInventory().pushItems(target, k, v.count, slot) - break + local item = itemDB:get(v) + if not item then + item = itemDB:add(ni.getInventory().getItemMeta(k)) + end + if item then + if context.state.autostore[makeKey(item)] then + ni.getInventory().pushItems(target, k, v.count, slot) + break + end end end end diff --git a/neural/apis/neural/mobs.lua b/neural/apis/neural/mobs.lua index 8196e7a..1af07c0 100644 --- a/neural/apis/neural/mobs.lua +++ b/neural/apis/neural/mobs.lua @@ -4,7 +4,9 @@ local hostiles = { BabySkeleton = true, BabyZombie = true, Bat = true, + Blaze = true, Creeper = true, + Ghast = true, Husk = true, LavaSlime = true, PigZombie = true, @@ -12,6 +14,7 @@ local hostiles = { Slime = true, Spider = true, Witch = true, + WitherSkeleton = true, Zombie = true, ZombieVillager = true, }