|
|
@@ -71,13 +71,35 @@ namespace GamecraftModdingAPI |
|
|
|
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) |
|
|
|
{ |
|
|
|
Id = new EGID(id, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); |
|
|
|
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"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Synchronize newly created entity components with entities DB. |
|
|
|
/// This forces a partial game tick, so it may be slow. |
|
|
|
/// This also has the potential to make Gamecraft unstable. |
|
|
|
/// Use this sparingly. |
|
|
|
/// </summary> |
|
|
|
protected static void Sync() |
|
|
|
{ |
|
|
|
DeterministicStepCompositionRootPatch.SubmitEntitiesNow(); |
|
|
@@ -219,10 +241,8 @@ namespace GamecraftModdingAPI |
|
|
|
/// Convert the block to a specialised block class. |
|
|
|
/// </summary> |
|
|
|
/// <returns>The block.</returns> |
|
|
|
/// <param name="sameTick">Force an entity sync when <c>true</c>. |
|
|
|
/// Only set this to <c>false</c> when the block was not placed the same tick this was called.</param> |
|
|
|
/// <typeparam name="T">The specialised block type.</typeparam> |
|
|
|
public T Specialise<T>(bool sameTick = true) where T : Block |
|
|
|
public T Specialise<T>() where T : Block |
|
|
|
{ |
|
|
|
// What have I gotten myself into? |
|
|
|
// C# can't cast to a child of Block unless the object was originally that child type |
|
|
@@ -233,7 +253,6 @@ namespace GamecraftModdingAPI |
|
|
|
{ |
|
|
|
throw new BlockSpecializationException("Specialized block constructor does not accept an EGID"); |
|
|
|
} |
|
|
|
if (sameTick) Sync(); |
|
|
|
return (T)ctor.Invoke(new object[] { Id }); |
|
|
|
} |
|
|
|
|
|
|
|