|
|
@@ -25,6 +25,7 @@ namespace GamecraftModdingAPI |
|
|
|
protected static readonly RotationEngine RotationEngine = new RotationEngine(); |
|
|
|
protected static readonly RemovalEngine RemovalEngine = new RemovalEngine(); |
|
|
|
protected static readonly SignalEngine SignalEngine = new SignalEngine(); |
|
|
|
protected static readonly BlockEventsEngine BlockEventsEngine = new BlockEventsEngine(); |
|
|
|
|
|
|
|
protected internal static readonly BlockEngine BlockEngine = new BlockEngine(); |
|
|
|
|
|
|
@@ -109,17 +110,27 @@ namespace GamecraftModdingAPI |
|
|
|
return new Block(BlockIdentifiers.LatestBlockID); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// An event that fires each time a block is placed. |
|
|
|
/// </summary> |
|
|
|
public static event EventHandler<BlockPlacedRemovedEventArgs> Placed |
|
|
|
{ |
|
|
|
add => BlockEventsEngine.Placed += value; |
|
|
|
remove => BlockEventsEngine.Placed -= value; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// An event that fires each time a block is removed. |
|
|
|
/// </summary> |
|
|
|
public static event EventHandler<BlockPlacedRemovedEventArgs> Removed |
|
|
|
{ |
|
|
|
add => BlockEventsEngine.Removed += value; |
|
|
|
remove => BlockEventsEngine.Removed -= value; |
|
|
|
} |
|
|
|
|
|
|
|
public Block(EGID id) |
|
|
|
{ |
|
|
|
Id = id; |
|
|
|
if (!BlockEngine.BlockExists(Id)) |
|
|
|
{ |
|
|
|
/*Sync(); |
|
|
|
if (!BlockEngine.BlockExists(Id)) |
|
|
|
{ |
|
|
|
throw new BlockDoesNotExistException($"Block {Id.entityID} must be placed using PlaceNew(...) since it does not exist yet"); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Block(uint id) : this(new EGID(id, CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) |
|
|
@@ -264,11 +275,11 @@ namespace GamecraftModdingAPI |
|
|
|
/// Returns the rigid body of the cluster of blocks this one belongs to during simulation. |
|
|
|
/// Can be used to apply forces or move the block around while the simulation is running. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The SimBody of the cluster</returns> |
|
|
|
/// <returns>The SimBody of the cluster or null if the block doesn't exist.</returns> |
|
|
|
public SimBody GetSimBody() |
|
|
|
{ |
|
|
|
uint id = BlockEngine.GetBlockInfo<GridConnectionsEntityStruct>(Id).machineRigidBodyId; |
|
|
|
return new SimBody(id); |
|
|
|
uint id = BlockEngine.GetBlockInfo<GridConnectionsEntityStruct>(Id, out var exists).machineRigidBodyId; |
|
|
|
return exists ? new SimBody(id) : null; |
|
|
|
} |
|
|
|
|
|
|
|
public override string ToString() |
|
|
@@ -283,6 +294,7 @@ namespace GamecraftModdingAPI |
|
|
|
GameEngineManager.AddGameEngine(RotationEngine); |
|
|
|
GameEngineManager.AddGameEngine(RemovalEngine); |
|
|
|
GameEngineManager.AddGameEngine(BlockEngine); |
|
|
|
GameEngineManager.AddGameEngine(BlockEventsEngine); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|