Cray-SBGItemFramework icon

SBGItemFramework

Shared backbone for custom item mods. Register an ItemType and a use-handler; it owns the Harmony plumbing for inventory injection, localized names, hotkey labels, tooltips, and pool-spawn injection. Required by dependent mods.

CHANGELOG

Changelog

v0.1.0

  • Initial release. Provides the Cray.SBGItemFramework library used by other custom-item mods. Surface:
    • ItemKit.Register(RegisteredItem) — entry point, takes a builder-built immutable item description.
    • RegisteredItem.Define(id, displayName) — fluent builder. Optional knobs: WithIconFromVanillaItem, WithIconOverride, WithIconTint, WithMaxUses, WithTooltip, WithSpawnWeight(poolIndex, weight), WithConfigBindings(consumerConfig, bindMaxUses, bindSpawnWeights), AllowVanillaSwingEligibility.
    • IItemHandler / ItemHandlerBase for the consumer to implement gameplay callbacks (OnUse, optional OnEquip / OnUnequip).
  • Framework-owned Harmony patches:
    • ItemCollection.Initialize / OnEnable extend the private items[] array idempotently so vanilla Count / GetItemAtIndex / TryGetItemData see custom items natively, with no per-mod prefix coordination.
    • PlayerInventory.TryUseItem dispatches to the registered handler.
    • PlayerInventory.GetEffectivelyEquippedItem(false) masks custom items to None so vanilla swing/aim eligibility doesn't get confused by an unknown ItemType.
    • LocalizedString.GetLocalizedString rewrites ITEM_<rawId> keys to the registered display name.
    • PauseMenu.UpdateItemProbabilites appends the optional tooltip text alongside the vanilla per-pool weight rows.
    • ItemSpawnerSettings.ResetRuntimeData injects custom items into the requested pools' spawnChances arrays and recalculates the totals.
  • Icon tinting goes through a CPU-pixel path on readable source textures and falls back to a Graphics.Blit through a temporary RenderTexture for unreadable ones, with results cached by (textureInstanceId, packedRgba).
  • Localization-table seeding runs once a frame from a hidden host until the Data table finishes loading, so vanilla code that bypasses the LocalizedString postfix still resolves the same display names.