mirror of
https://github.com/Jacobwasbeast/LegacyWeaveLoader.git
synced 2026-06-04 03:54:31 +00:00
Mod Atlas (ModAtlas.cpp/h): - Build merged terrain.png and items.png from mod assets (blocks/*.png, items/*.png) - Scan vanilla atlas for empty (fully transparent) cells; place mod textures only there - Install merged atlases over game files before Minecraft::init; restore originals after - Hook loadUVs to create SimpleIcon objects for mod textures - Hook registerIcon to return mod icons when requested by name - FixupModIcons: copy field_0x48 (source-image ptr) from vanilla icons after init Mod Strings (ModStrings.cpp/h): - Store mod display names by description ID - Hook GetString to serve mod names for blocks/items API changes: - BlockProperties/ItemProperties: .Name(displayName), namespaced .Icon() - NativeInterop: displayName params, native_allocate_description_id, native_register_string - Registry.Assets for string registration - Output: mods/LegacyForge.API/, mods/ExampleMod/ (per-mod folders) Mod discovery: - Scan mods/*/ for mod folders; load DLLs from each - LegacyForge.API as mod in mods/LegacyForge.API/ ExampleMod: - Ruby ore block and ruby item with custom textures and names - Assets: blocks/ruby_ore.png, items/ruby.png, lang files - Furnace recipe: ruby_ore -> ruby Runtime: loadUVs, registerIcon, getResourceAsStream, GetString hooks; stb_image for PNG
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
namespace LegacyForge.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 LegacyForge 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);
|
|
}
|
|
}
|