Jump to content

Recommended Posts

Whenever I open a container with the crafting tab open or near a prototyper it lags me really bad, its been like this ever since Klei added the feature, unfortunately :(...

I would greatly appreciate if somebody could make a mod or tell me how to disable that code so I don't get a lagspike each time I go near a container with an open chest or open a chest near a container

28 minutes ago, . . . said:

Whenever I open a container with the crafting tab open or near a prototyper it lags me really bad, its been like this ever since Klei added the feature, unfortunately :(...

I would greatly appreciate if somebody could make a mod or tell me how to disable that code so I don't get a lagspike each time I go near a container with an open chest or open a chest near a container

Could you explain in detail what you mean? If you have pictures, it would be very helpful in trying to find a solution.

  • Like 1
On 9/8/2025 at 12:12 AM, FerniFrenito said:

Could you explain in detail what you mean? If you have pictures, it would be very helpful in trying to find a solution.

I don't think there's any real pictures I can take for this.
Basically, whenever I open a container with the crafting tab open I get a lag spike (game drops 10-20 fps) I assume it's because the game scans the contents of the container to see what I can craft.

I would like if somebody can make a mod so the crafting tab ignores contents of open containers so the player only can craft with items in their own inventory, that way it doesn't lag.

9 hours ago, . . . said:

I don't think there's any real pictures I can take for this.
Basically, whenever I open a container with the crafting tab open I get a lag spike (game drops 10-20 fps) I assume it's because the game scans the contents of the container to see what I can craft.

I would like if somebody can make a mod so the crafting tab ignores contents of open containers so the player only can craft with items in their own inventory, that way it doesn't lag.

Hum... That's strange. Even if the game scanned each object individually, normally no container should be so large as to cause the game to lag. Is your computer not very powerful? Anyway, I'll search the game files and try to find a solution for you, but I warn you that it will most likely take a while because these types of processes are never easy to track.

  • Like 1
2 hours ago, FerniFrenito said:

Hum... That's strange. Even if the game scanned each object individually, normally no container should be so large as to cause the game to lag. Is your computer not very powerful? Anyway, I'll search the game files and try to find a solution for you, but I warn you that it will most likely take a while because these types of processes are never easy to track.

Thank you so much, I always play with mod that increases container size such as treasure chest by 3-4x bigger because otherwise they are too small maybe that's the issue.. but I can't stop using them the vanilla container is too awful!

I forgot to say it's not just when my crafting tab is open, but it's just opening a container that contains items that can be used in crafting in general that causes the lag. I'm pretty sure it's because all the items in the container are scanned and then it updates the crafting tab on what the player can craft and since I'm using some big mods such as uncompromising mode, cherry forest, legion, ect. there is a LOT more crafting recipes so it causes a big lag spike.

So the only thing I need help with or somebody to make a mod for is make the crafting tab/builder code for all its code related to scanning contents of containers then player can use such items in crafting to be removed/nullified.

It's much less annoying if I had to just pick up the items from container to craft with them then open a container and each time get -10/20 fps for half a second.


I got it:

-- modmain.lua
AddClassPostConstruct("components/inventory", function(inst)
    local OriginalHasFunction = inst.Has
    inst.Has = function(self, item, amount, checkallcontainers)
        return OriginalHasFunction(self, item, amount, false) -- False to not search in containers
    end
end)
AddClassPostConstruct("components/inventory_replica", function(inst)
    local OriginalHasFunction = inst.Has
    inst.Has = function(self, item, amount, checkallcontainers)
        return OriginalHasFunction(self, item, amount, false) -- False to not search in containers
    end
end)

And that's all. I don't know why the game has a component and a replica of the same component.

If you're going to publish the mod, I'd like you to mention me, please.

  • Like 1
On 9/9/2025 at 4:00 PM, FerniFrenito said:

And that's all. I don't know why the game has a component and a replica of the same component.

If you're going to publish the mod, I'd like you to mention me, please.

Thank you, unfortunately it seems I still get lag spike.

I did some testing and when I have items in my inventory to craft something for example an axe and if I have a chest open with said materials to make an axe it will consume the items in the chest to craft the axe instead of the ones in my inventory, even though if I don't have materials in my inventory I can't craft the axe.

So this leads me to believe the code for scanning content of container for crafting is still active, it must have something to do with builder component or something hmm..

I'm sorry for all the trouble 

11 hours ago, . . . said:

Thank you, unfortunately it seems I still get lag spike.

I did some testing and when I have items in my inventory to craft something for example an axe and if I have a chest open with said materials to make an axe it will consume the items in the chest to craft the axe instead of the ones in my inventory, even though if I don't have materials in my inventory I can't craft the axe.

So this leads me to believe the code for scanning content of container for crafting is still active, it must have something to do with builder component or something hmm..

I'm sorry for all the trouble 

try this:

-- modmain.lua
AddClassPostConstruct("components/container", function(inst)
    inst.Open = function(self, doer)
        if doer ~= nil and self.openlist[doer] == nil then
            if not self.skipautoclose then
                self.inst:StartUpdatingComponent(self)
            end
            local inventory = doer.components.inventory
            if inventory.openContainersOnlyToClose == nil then
                inventory.openContainersOnlyToClose = {}
            end
            if inventory ~= nil then
                for k in pairs(inventory.openContainersOnlyToClose) do
                    if k.prefab == self.inst.prefab or k.components.container.type == self.type then
                        k.components.container:Close(doer)
                    end
                end

                inventory.openContainersOnlyToClose[self.inst] = true
            end
            self.openlist[doer] = true
            self.opencount = self.opencount + 1
            self.inst.replica.container:AddOpener(doer)

            if doer.HUD ~= nil then
                doer.HUD:OpenContainer(self.inst, self:IsSideWidget())
                doer:PushEvent("refreshcrafting")
                if not self.inst.replica.container:ShouldSkipOpenSnd() then
                    -- FIXME(JBK): The changes here need a way to tie the self.widget back to the entity to GetSkinBuild from for other containers like pillar and bundle wraps.
                    -- Replicate to the other three spots in container and container_replica.
                    local skinsound = self.inst.AnimState and SKIN_SOUND_FX[self.inst.AnimState:GetSkinBuild()] or nil
                    TheFocalPoint.SoundEmitter:PlaySound(
                        skinsound and skinsound.open_ui or
                        (self.widget ~= nil and self.widget.opensound) or
                        (self:IsSideWidget() and "dontstarve/wilson/backpack_open") or
                        "dontstarve/HUD/Together_HUD/container_open"
                    )
                end
            elseif self.widget ~= nil
                and self.widget.buttoninfo ~= nil
                and doer.components.playeractionpicker ~= nil then
                doer.components.playeractionpicker:RegisterContainer(self.inst)
            end

            self.inst:PushEvent("onopen", {doer = doer})

            if self.onopenfn ~= nil and self.opencount == 1 then
                self.onopenfn(self.inst, {doer = doer})
            end

            if self.onanyopenfn ~= nil then
                self.onanyopenfn(self.inst, {doer = doer})
            end
        end
    end
    inst.Close = function(self, doer)
        -- Maybe this is important, i don't know what this do
        --[[self:ForEachItem(Container.Close_Items_Internal, doer)
        if doer == nil then
            for opener, _ in pairs(self.openlist) do
                self:Close(opener)
            end
            return
        end--]]
        if doer ~= nil and self.openlist[doer] ~= nil then
            self.openlist[doer] = nil
            self.opencount = self.opencount - 1
            self.inst.replica.container:RemoveOpener(doer)

            if self.opencount == 0 then
                self.inst:StopUpdatingComponent(self)
            end

            if doer.HUD ~= nil then
                doer.HUD:CloseContainer(self.inst, self:IsSideWidget())
                doer:PushEvent("refreshcrafting")
                if not self.inst.replica.container:ShouldSkipCloseSnd() then
                    local skinsound = self.inst.AnimState and SKIN_SOUND_FX[self.inst.AnimState:GetSkinBuild()] or nil
                    TheFocalPoint.SoundEmitter:PlaySound(
                        skinsound and skinsound.close_ui or
                        (self.widget ~= nil and self.widget.closesound) or
                        (self:IsSideWidget() and "dontstarve/wilson/backpack_close") or
                        "dontstarve/HUD/Together_HUD/container_close"
                    )
                end
            elseif doer.components.playeractionpicker ~= nil then
                doer.components.playeractionpicker:UnregisterContainer(self.inst)
            end

            if doer.components.inventory ~= nil then
                doer.components.inventory.opencontainers[self.inst] = nil
            end

            if self.onclosefn ~= nil and self.opencount == 0 then
                self.onclosefn(self.inst, doer)
            end

            if self.onanyclosefn ~= nil then
                self.onanyclosefn(self.inst, {doer = doer})
            end

            self.inst:PushEvent("onclose", {doer = doer})
        end
    end
end)

The bad thing is that I had to override the functions, so if you change them in an update, you'll have to change the mod. Now I'm sure it works because the code it modifies is the one used at the root of the container opening action.
If you notice any bugs, delete the inst.Close override, as it has code that iterates over all the items, but I don't know what it does. I assume it's because when you open a chest, all the items inside are marked as yours, and when you close it, they should no longer be marked, but I don't know what this is used for. Anyway, I hope it helps.

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...