Skip to content

Add client-side custom item creation via server RPCs - #99

Open
codefling-0xf wants to merge 2 commits into
Facepunch:masterfrom
codefling-0xf:add-custom-items-rpc
Open

Add client-side custom item creation via server RPCs#99
codefling-0xf wants to merge 2 commits into
Facepunch:masterfrom
codefling-0xf:add-custom-items-rpc

Conversation

@codefling-0xf

Copy link
Copy Markdown
Contributor

Summary

Adds runtime creation of custom ItemDefinition / ItemBlueprint objects on the client, driven by server RPCs. Lets servers/plugins ship fully client-side items (craftable, with icons) without bundling assets or touching server-side ItemManager.

What's included

CommunityEntity.Items.cs (new)

  • CreateItem(JSON.Object[, refresh]) — builds an ItemDefinition (and optional ItemBlueprint) on a fresh GameObject, registers it into ItemManager.itemList / itemDictionary / itemDictionaryByName, and (when a blueprint is present) into bpList / itemToBlueprint / ingredientToBlueprints / defaultBlueprints.
  • Server API: SendCreateCustomItems(player, json) / SendRemoveCustomItems(player, json) — send a JSON array over RPC via StringRaw (same pattern as AddUI).
  • RPC_CreateCustomItems / RPC_RemoveCustomItems — parse the array, create/remove per entry. UI refresh (LocalPlayer.OnInventoryChanged + UIBlueprints.Refresh) is batched to once per RPC instead of once per item.
  • defaultBlueprints is maintained surgically (AddDefaultBlueprint / RemoveDefaultBlueprint) — no full bpList rebuild.
  • RemoveCustomItems() cleanup on disconnect via the ClientDisconnect broadcast hook.

CommunityEntity.UI.ServerImage.cs

  • Icon sprites are set by CRC through the existing image callback system: a new ItemDefinitionEntry list on ImageRequest (mirrors the existing Entry list). ApplyTextureToItem(def, crc) registers an entry or applies immediately if the texture is cached; CL_ReceiveFilePng applies the sprite to all waiting definitions on arrival. No per-frame polling.

CommunityEntity.cs

  • Centralized ClientDisconnect hook (calls RemoveCustomItems()) and the single ParseEnum<T> (moved out of UI.cs to resolve a duplicate-definition conflict).

Example

var items = new JSON.Array();
items.Add(new JSON.Object {
    ["shortname"] = "custom_rpc_item",
    ["displayName"] = "Custom RPC Item",
    ["category"] = ItemCategory.Misc.ToString(),
    ["stackable"] = 100,
    ["rarity"] = Rarity.Uncommon.ToString(),
    ["ingredients"] = new JSON.Array {
        new JSON.Object { ["shortname"] = "wood",   ["amount"] = 100 },
        new JSON.Object { ["shortname"] = "stones", ["amount"] = 50  },
    },
    ["craftTime"] = 5,
    ["workbenchLevelRequired"] = 1,
    ["defaultBlueprint"] = true,
    ["iconSpriteCrc"] = 1234567890u.ToString(),
});
CommunityEntity.ServerInstance.SendCreateCustomItems(player, items.ToString());

Notes

  • Items exist only on the client (no server-side ItemManager registration) — intended for client-side UI/crafting features.
  • Build has not been tested yet.

0xF added 2 commits August 22, 2026 23:25
- Items.cs: CreateItem(JSON.Object[, refresh]) builds ItemDefinition +
  ItemBlueprint at runtime on the client and registers them into
  ItemManager collections. Server API SendCreate/RemoveCustomItems send
  JSON arrays over RPC (StringRaw). defaultBlueprints maintained
  surgically via Add/RemoveDefaultBlueprint (no full bpList rebuild).
  Cleanup on disconnect via ClientDisconnect -> RemoveCustomItems.
- UI.ServerImage.cs: icon sprites set by CRC through the existing image
  callback system (ItemDefinitionEntry entries, no polling).
- CommunityEntity.cs: centralized ClientDisconnect hook + ParseEnum.
- Items.Test.cs: citem test commands (customitem_test / customitem_endtest).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant