Find block when group is unknown

This commit is contained in:
Norbi Peti 2020-07-11 02:26:36 +02:00
parent f403feb298
commit aa0aefd41b
2 changed files with 20 additions and 2 deletions

View file

@ -135,8 +135,14 @@ namespace GamecraftModdingAPI
Id = id; Id = id;
} }
public Block(uint id) : this(new EGID(id, CommonExclusiveGroups.BUILD_STANDARD_BLOCK_GROUP)) /// <summary>
{ //TODO: Figure out the block group based on the id /// This overload searches for the correct group the block is in.
/// It will throw an exception if the block doesn't exist.
/// Use the EGID constructor where possible or subclasses of Block as those specify the group.
/// </summary>
public Block(uint id)
{
Id = BlockEngine.FindBlockEGID(id) ?? throw new BlockTypeException("Could not find the appropriate group for the block. The block probably doesn't exist or hasn't been submitted.");
} }
public EGID Id { get; } public EGID Id { get; }

View file

@ -171,6 +171,18 @@ namespace GamecraftModdingAPI.Blocks
return list.ToArray(); return list.ToArray();
} }
public EGID? FindBlockEGID(uint id)
{
var groups = entitiesDB.FindGroups<DBEntityStruct>();
foreach (ExclusiveGroupStruct group in groups)
{
if (entitiesDB.Exists<DBEntityStruct>(id, group))
return new EGID(id, group);
}
return null;
}
/// <summary> /// <summary>
/// Synchronize newly created entity components with entities DB. /// Synchronize newly created entity components with entities DB.
/// This forces a partial game tick, so it may be slow. /// This forces a partial game tick, so it may be slow.