hall123 Posted March 20, 2025 Share Posted March 20, 2025 I'm adding a food storage feature to my building mod. But it can store more than just food. In my tests, some items can't be stored, such as Nightmare Fuel("nightmarefuel"). But most things can be stored. Here are the key code snippets, and the full source code is available in this repo: https://github.com/yanghao5/painmagnet/tree/dev. prefabs/painmagnet.lua inst:AddComponent("container") inst.components.container:WidgetSetup("painmagnet_storage") inst.components.container.onopenfn = function(inst) inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_open") end inst.components.container.onclosefn = function(inst) inst.SoundEmitter:PlaySound("dontstarve/wilson/chest_close") end modmain.lua local containers = require("containers") ... local params = { widget = { slotpos = {}, animbank = "ui_chest_4x5", animbuild = "ui_chest_4x5", pos = Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", itemtestfn = function(container, item, slot) return item.components.edible ~= nil end } for y = 3, 0, -1 do -- slot_y = 3 for x = 0, 4 do -- slot_x = 4 table.insert(params.widget.slotpos, Vector3(80 * x - 346 * 2 + 90, 80 * y - 100 * 2 + 130, 0)) end end containers.params.painmagnet_storage = params containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, #params.widget.slotpos) Does anyone know how to fix it? Link to comment https://forums.kleientertainment.com/forums/topic/164965-how-do-i-restrict-container-to-store-only-food-items/ Share on other sites More sharing options...
yanecc Posted March 20, 2025 Share Posted March 20, 2025 itemtestfn = function(container, item, slot) return item.components.edible ~= nil and item.components.edible.foodtype ~= FOODTYPE.ELEMENTAL end 1 Link to comment https://forums.kleientertainment.com/forums/topic/164965-how-do-i-restrict-container-to-store-only-food-items/#findComment-1808313 Share on other sites More sharing options...
hall123 Posted March 21, 2025 Author Share Posted March 21, 2025 @yanecc Thanks! Your condition filters out more items, but some non-food items can still be stored. Your code gave me a clue. I tried the following code, everything is fine now. itemtestfn = function(container, item, slot) if item.components.edible then local foodtypes = item.components.edible.foodtype if type(foodtypes) == "table" then for _, ft in pairs(foodtypes) do if ft == FOODTYPE.MEAT or ft == FOODTYPE.VEGGIE or ft == FOODTYPE.FRUIT or ft == FOODTYPE.FISH then return true end end end end return false end 1 Link to comment https://forums.kleientertainment.com/forums/topic/164965-how-do-i-restrict-container-to-store-only-food-items/#findComment-1808395 Share on other sites More sharing options...
hall123 Posted March 23, 2025 Author Share Posted March 23, 2025 update itemtestfn itemtestfn = function(container, item, slot) if item.components.edible then if item.components.edible.foodtype == FOODTYPE.MEAT or item.components.edible.foodtype==FOODTYPE.VEGGIE then return true end end return false end Link to comment https://forums.kleientertainment.com/forums/topic/164965-how-do-i-restrict-container-to-store-only-food-items/#findComment-1808730 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now