Files
LegacyWeaveLoader/LegacyForge.API/Block/BlockRegistry.cs
Jacobwasbeast 34177e1507 Add main menu overlay, creative inventory injection, mod discovery, logging, and Wine/Proton support
- Replace dbghelp with raw_pdb library for cross-platform PDB symbol resolution
- Add main menu branding overlay via C4JRender::Present hook
- Add creative inventory item injection from mods
- Add file-based logging (LogUtil) alongside console output
- Fix mod discovery with custom AssemblyLoadContext for proper type identity
- Add file dialog for game path selection in launcher
- Add CreativeTab enum and block/item creative tab assignment
- Unify build output to single ModLoader/build directory
2026-03-06 18:59:02 -06:00

58 lines
2.0 KiB
C#

namespace LegacyForge.API.Block;
/// <summary>
/// Represents a block that has been registered with the game engine.
/// </summary>
public class RegisteredBlock
{
/// <summary>The namespaced string ID (e.g. "mymod:ruby_ore").</summary>
public Identifier StringId { get; }
/// <summary>The numeric ID allocated by the engine.</summary>
public int NumericId { get; }
internal RegisteredBlock(Identifier id, int numericId)
{
StringId = id;
NumericId = numericId;
}
}
/// <summary>
/// Block registration via the LegacyForge registry.
/// Accessed through <see cref="Registry.Block"/>.
/// </summary>
public static class BlockRegistry
{
/// <summary>
/// Register a new block with the game engine.
/// </summary>
/// <param name="id">Namespaced identifier (e.g. "mymod:ruby_ore").</param>
/// <param name="properties">Block properties built with <see cref="BlockProperties"/>.</param>
/// <returns>A handle to the registered block.</returns>
public static RegisteredBlock Register(Identifier id, BlockProperties properties)
{
int numericId = NativeInterop.native_register_block(
id.ToString(),
(int)properties.MaterialValue,
properties.HardnessValue,
properties.ResistanceValue,
(int)properties.SoundValue,
properties.IconValue,
properties.LightEmissionValue,
properties.LightBlockValue);
if (numericId < 0)
throw new InvalidOperationException($"Failed to register block '{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($"Block '{id}' added to creative tab {properties.CreativeTabValue}");
}
Logger.Debug($"Registered block '{id}' -> numeric ID {numericId}");
return new RegisteredBlock(id, numericId);
}
}