NorbiPeti
7336fe8353
Newly created blocks use the initializer to set properties, allowing the user to set per-block properties
86 lines
No EOL
2.6 KiB
C#
86 lines
No EOL
2.6 KiB
C#
using System;
|
|
|
|
using RobocraftX.Common;
|
|
using Svelto.ECS;
|
|
|
|
using GamecraftModdingAPI.Engines;
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
public class BlockEventsEngine : IReactionaryEngine<DBEntityStruct>
|
|
{
|
|
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
|
|
public event EventHandler<BlockPlacedRemovedEventArgs> 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<RefWrapper<Type>, FasterList<IEngine>> engines,
|
|
ExclusiveGroupStruct? previousGroup, in PlatformProfiler profiler, EGID egid)
|
|
{
|
|
if (!engines.TryGetValue(new RefWrapper<Type>(TypeSafeDictionary<TValue>._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;
|
|
}
|
|
} |