feat(modloader): add item use and summon APIs

Add managed item use hooks, server-authoritative summon support, and side-aware use item context.

Include IdHelper mappings, example ruby wand usage, and related runtime/crash-handler updates.
This commit is contained in:
Jacobwasbeast
2026-03-07 19:54:52 -06:00
parent eabf8fe858
commit 0b4c87acbc
21 changed files with 1862 additions and 45 deletions

View File

@@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace WeaveLoader.API.Entity;
/// <summary>
@@ -21,6 +23,9 @@ public class RegisteredEntity
/// </summary>
public static class EntityRegistry
{
private static readonly object s_lock = new();
private static readonly Dictionary<int, Identifier> s_idByNumeric = new();
public static RegisteredEntity Register(Identifier id, EntityDefinition definition)
{
int numericId = NativeInterop.native_register_entity(
@@ -33,6 +38,33 @@ public static class EntityRegistry
throw new InvalidOperationException($"Failed to register entity '{id}'.");
Logger.Debug($"Registered entity '{id}' -> numeric ID {numericId}");
lock (s_lock)
{
s_idByNumeric[numericId] = id;
}
return new RegisteredEntity(id, numericId);
}
public static bool Summon(Identifier id, double x, double y, double z)
{
int numericId = IdHelper.GetEntityNumericId(id);
if (numericId < 0)
return false;
return Summon(numericId, x, y, z);
}
public static bool Summon(int numericId, double x, double y, double z)
{
int ok = NativeInterop.native_summon_entity_by_id(numericId, x, y, z);
return ok != 0;
}
internal static bool TryGetIdentifier(int numericId, out Identifier id)
{
lock (s_lock)
{
return s_idByNumeric.TryGetValue(numericId, out id);
}
}
}