Skip to content

CustomItemRegistry

Kanisuko edited this page May 24, 2026 · 6 revisions

CustomItemRegistry

Namespace:​ ScavLib.item

Registers custom ItemInfo definitions into the game's global item registry (Item.GlobalItems). Injection happens automatically after the game's own Item.SetupItems() runs via a Harmony Postfix patch — you do not need to manage timing yourself.

Registrations made before the world loads are safely queued and flushed at the correct moment.


Current Limitation

As of ScavLib 0.3.0, registering an ItemInfo adds the item's definition to the registry only. It does not create a spawnable Prefab in Resources/. Calling Utils.Create("your_id", ...) or GameUtil.SpawnItem("your_id", ...) will still fail because the engine looks up a GameObject by name in Resources/ at runtime.

What you can do today:​

  • Register a custom ID so it appears in Item.GlobalItems.
  • Use that ItemInfo for crafting recipes, lookup tables, and custom logic.
  • Override an existing item's ItemInfo using overwrite: true.

Spawnable custom items are planned for a future version once an AssetBundle loading layer is added.


Simple Registration

For common cases, use RegisterSimpleItem to build a minimal ItemInfo with sensible defaults:

CustomItemRegistry.RegisterSimpleItem(
    id:       "mymod_herb",
    category: "custom",
    weight:   0.3f,
    value:    5,
    tags:     "medicine"
);
Parameter Type Default Description
id string Unique item ID. Prefix with your mod name to avoid collisions (e.g. "mymod_herb").
category string "custom" Item category string.
weight float 1f Item weight in kg.
value int 1 Monetary value.
tags string "" Space or comma separated tag string.

Full Registration

For complete control, build an ItemInfo manually and pass it to RegisterItem:

var info = new ItemInfo
{
    category             = "medical",
    weight               = 0.5f,
    value                = 20,
    tags                 = "medicine,dressing",
    usable               = false,
    usableOnLimb         = true,
    destroyAtZeroCondition = true,
    combineable          = true,
    rec                  = new Recognition(3),
    useLimbAction        = (limb, item) =>
    {
        limb.skinHealAmount += 15f;
        limb.pain           -= 20f;
        item.condition      -= 0.25f;
    }
};

CustomItemRegistry.RegisterItem("mymod_salve", info);

RegisterItem Parameters

Parameter Type Default Description
id string Unique item ID.
info ItemInfo The item definition.
overwrite bool false If true and the ID already exists, the existing entry is replaced.

ID Naming Convention

Prefix your item IDs with a short mod identifier to avoid collisions with the game's built-in items and other mods:

mymod_herb        ✔
super_bandage     ✗  (too generic, may collide)
bandage           ✗  (conflicts with a built-in item)

Checking Registration

After the world loads, verify your item was injected:

[Subscribe]
private void OnWorldLoaded(WorldLoadedEvent e)
{
    bool ok = ItemUtil.IsKnownId("mymod_herb");
    GameUtil.Log($"mymod_herb registered: {ok}");
}

Clone this wiki locally