Jump to content

my modded container is crashing the game when caves are enabled


Recommended Posts

I'm creating an item similar to Walter's slingshot that contains an item slot. Whenever I equip the item in a world with caves enabled, the game gives me this crash screen:

image.thumb.png.257774e3eefec1a165b42b04467ab6da.png

This report doesn't give me the exact line of code in my mod like I'm used to with most crash screens, and when I go to line 30 in containerwidget.lua, I still can't find any pointers as to why my game is still crashing! :confusion:

containerwidget.lua:
image.png.7963f093c2e19438c81abc4f047401bf.png

 

Here is my snippet of code in my modmain.lua that I believe creates the container:

local function CreateSpecialSlingshotWidget()
	local params = containers.params

	params.specialslingshot =
	{
		widget =
		{
        slotpos =
        {
            Vector3(0,   32 + 4,  0),
        },
        slotbg =
        {
            { image = "slingshot_ammo_slot.tex" },
        },
        animbank = "ui_cookpot_1x2",
        animbuild = "ui_cookpot_1x2",
        pos = Vector3(0, 15, 0),
    },
    usespecificslotsforitems = true,
    type = "hand_inv",
    excludefromcrafting = true,
	}
	
	containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.specialslingshot.widget.slotpos ~= nil and #params.specialslingshot.widget.slotpos or 0)

	local old_widgetsetup = containers.widgetsetup
	
	function containers.widgetsetup(container, prefab, data)
		local pref = prefab or container.inst.prefab
		
		if pref == "specialslingshot" then
			local t = params[pref]
			
			if t ~= nil then
				for k, v in pairs(t) do
					container[k] = v
				end
			container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
			end
		else
			return old_widgetsetup(container, prefab, data)
		end
	end
	
	function params.specialslingshot.itemtestfn(container, item, slot)
		return item:HasTag("specialitem")
	end
end

CreateSpecialSlingshotWidget()

 

Link to comment
Share on other sites

Two steps.

1.in prefab, server

inst:AddComponent("container")
inst.components.container:WidgetSetup("piggyback")

2.in prefab, client. If you are not registering a widget that has its name exactly the same as the prefab

if not TheWorld.ismastersim then
    inst.OnEntityReplicated = function(inst)
      if inst.replica.container then inst.replica.container:WidgetSetup("piggyback") end
    end
    return inst
end

or

2.in modmain, both server and client, the name must match the prefab

local params=require("containers").params
params.piggyback={...(params you would like)}

 

  • Thanks 2
Link to comment
Share on other sites

14 hours ago, Rickzzs said:

 

if not TheWorld.ismastersim then
    inst.OnEntityReplicated = function(inst)
      if inst.replica.container then inst.replica.container:WidgetSetup("piggyback") end
    end
    return inst
end
 

Thank you, this simple change did just the trick!

Link to comment
Share on other sites

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
 Share

×
  • Create New...