Browse Source

Find block when group is unknown

tags/v1.4.0-preview
NorbiPeti 4 years ago
parent
commit
aa0aefd41b
2 changed files with 20 additions and 2 deletions
  1. +8
    -2
      GamecraftModdingAPI/Block.cs
  2. +12
    -0
      GamecraftModdingAPI/Blocks/BlockEngine.cs

+ 8
- 2
GamecraftModdingAPI/Block.cs View File

@@ -135,8 +135,14 @@ namespace GamecraftModdingAPI
Id = id;
}

public Block(uint id) : this(new EGID(id, CommonExclusiveGroups.BUILD_STANDARD_BLOCK_GROUP))
{ //TODO: Figure out the block group based on the id
/// <summary>
/// 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; }


+ 12
- 0
GamecraftModdingAPI/Blocks/BlockEngine.cs View File

@@ -171,6 +171,18 @@ namespace GamecraftModdingAPI.Blocks
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>
/// Synchronize newly created entity components with entities DB.
/// This forces a partial game tick, so it may be slow.


Loading…
Cancel
Save