TechbloxModdingAPI/GamecraftModdingAPI/Blocks/BlockEventsEngine.cs
NorbiPeti dba7c0a46f
Added 2 block events and removed BDNEException
Added an event for placing and removing blocks
Added a class to wrap event calls in a try-catch
Removed BlockDoesNotExistException
Made Block.GetSimBody() return null if block doesn't exist
2020-06-02 03:15:32 +02:00

42 lines
No EOL
1.2 KiB
C#

using System;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks
{
public class BlockEventsEngine : IReactionaryEngine<DBEntityStruct>
{
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
public void Ready()
{
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
}
public string Name { get; } = "GamecraftModdingAPIBlockEventsEngine";
public bool isRemovable { get; } = false;
public void Add(ref DBEntityStruct entityComponent, EGID egid)
{
ExceptionUtil.InvokeEvent(Placed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
}
public void Remove(ref DBEntityStruct entityComponent, EGID egid)
{
ExceptionUtil.InvokeEvent(Removed, this, new BlockPlacedRemovedEventArgs {ID = egid, Type = (BlockIDs) entityComponent.DBID});
}
}
public struct BlockPlacedRemovedEventArgs
{
public EGID ID;
public BlockIDs Type;
}
}