-
Notifications
You must be signed in to change notification settings - Fork 0
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.
As of ScavLib 0.3.0, registering an
ItemInfoadds the item's definition to the registry only. It does not create a spawnable Prefab inResources/. CallingUtils.Create("your_id", ...)orGameUtil.SpawnItem("your_id", ...)will still fail because the engine looks up aGameObjectby name inResources/at runtime.What you can do today:
- Register a custom ID so it appears in
Item.GlobalItems.- Use that
ItemInfofor crafting recipes, lookup tables, and custom logic.- Override an existing item's
ItemInfousingoverwrite: true.Spawnable custom items are planned for a future version once an AssetBundle loading layer is added.
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. |
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);| 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. |
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)
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}");
}