mirror of
https://github.com/Jacobwasbeast/LegacyWeaveLoader.git
synced 2026-05-25 07:04:34 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user