Files
LegacyWeaveLoader/WeaveLoader.API/Item/ItemRegistry.cs
Jacobwasbeast fa195fdc2e Rebrand LegacyForge to Weave Loader
Rename across entire codebase:
- LegacyForge -> WeaveLoader (identifiers, namespaces, classes, DLLs)
- LegacyForgeRuntime -> WeaveLoaderRuntime (C++ project)
- LegacyForge.API/Core/Launcher -> WeaveLoader.API/Core/Launcher (C# projects)
- [LegacyForge] -> [WeaveLoader] (log prefixes)
- legacyforge -> weaveloader (config files, log files, backup suffixes)
- Display name "Weave Loader" in README, CONTRIBUTING, LICENSE
2026-03-06 23:31:18 -06:00

55 lines
1.8 KiB
C#

namespace WeaveLoader.API.Item;
/// <summary>
/// Represents an item that has been registered with the game engine.
/// </summary>
public class RegisteredItem
{
/// <summary>The namespaced string ID (e.g. "mymod:ruby").</summary>
public Identifier StringId { get; }
/// <summary>The numeric ID allocated by the engine.</summary>
public int NumericId { get; }
internal RegisteredItem(Identifier id, int numericId)
{
StringId = id;
NumericId = numericId;
}
}
/// <summary>
/// Item registration via the WeaveLoader registry.
/// Accessed through <see cref="Registry.Item"/>.
/// </summary>
public static class ItemRegistry
{
/// <summary>
/// Register a new item with the game engine.
/// </summary>
/// <param name="id">Namespaced identifier (e.g. "mymod:ruby").</param>
/// <param name="properties">Item properties built with <see cref="ItemProperties"/>.</param>
/// <returns>A handle to the registered item.</returns>
public static RegisteredItem Register(Identifier id, ItemProperties properties)
{
int numericId = NativeInterop.native_register_item(
id.ToString(),
properties.MaxStackSizeValue,
properties.MaxDamageValue,
properties.IconValue,
properties.NameValue ?? "");
if (numericId < 0)
throw new InvalidOperationException($"Failed to register item '{id}'. No free IDs or invalid parameters.");
if (properties.CreativeTabValue != CreativeTab.None)
{
NativeInterop.native_add_to_creative(numericId, 1, 0, (int)properties.CreativeTabValue);
Logger.Debug($"Item '{id}' added to creative tab {properties.CreativeTabValue}");
}
Logger.Debug($"Registered item '{id}' -> numeric ID {numericId}");
return new RegisteredItem(id, numericId);
}
}