using System; using RobocraftX.Common; using Svelto.ECS; using GamecraftModdingAPI.Engines; using GamecraftModdingAPI.Utility; namespace GamecraftModdingAPI.Blocks { public class BlockEventsEngine : IReactionaryEngine { public event EventHandler Placed; public event EventHandler Removed; public BlockEventsEngine() { //Console.WriteLine("Creating BlockEventsEngine\n" + Environment.StackTrace); } public void Ready() { //Console.WriteLine("BlockEventsEngine registered"); } public EntitiesDB entitiesDB { get; set; } public void Dispose() { } public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine"; public bool isRemovable { get; } = false; private bool shouldAddRemove; public void Add(ref DBEntityStruct entityComponent, EGID egid) { if (!(shouldAddRemove = !shouldAddRemove)) return; ExceptionUtil.InvokeEvent(Placed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID}); } public void Remove(ref DBEntityStruct entityComponent, EGID egid) { if (!(shouldAddRemove = !shouldAddRemove)) return; ExceptionUtil.InvokeEvent(Removed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID}); } } /*[HarmonyPatch] public static class TestPatch { public static void Postfix(FasterDictionary, FasterList> engines, ExclusiveGroupStruct? previousGroup, in PlatformProfiler profiler, EGID egid) { if (!engines.TryGetValue(new RefWrapper(TypeSafeDictionary._type), out result)) return; } public static MethodBase TargetMethod() { return AccessTools.Method("Svelto.ECS.Internal.TypeSafeDictionary:AddEntityComponentToEngines"); } }*/ /*[HarmonyPatch] public static class TestPatch { public static void Postfix(EGID basePartEGID) { Console.WriteLine("Patched Add method: " + basePartEGID); } public static MethodBase TargetMethod() { return AccessTools.Method("RobocraftX.CR.MachineEditing.BuildBlockAdditionalPartEngine:Add"); } }*/ public struct BlockPlacedRemovedEventArgs { public EGID ID; public BlockIDs Type; } }