From 448cf3af48007fedc9a700e56bc78ed481b9905e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 5 Jun 2020 00:57:22 +0200 Subject: [PATCH] Expose the simulation-time object IDs They are useful --- GamecraftModdingAPI/Blocks/BlockEngine.cs | 4 ++-- .../Blocks/ObjectIdentifier.cs | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/BlockEngine.cs b/GamecraftModdingAPI/Blocks/BlockEngine.cs index 1d9f8c9..3473106 100644 --- a/GamecraftModdingAPI/Blocks/BlockEngine.cs +++ b/GamecraftModdingAPI/Blocks/BlockEngine.cs @@ -144,14 +144,14 @@ namespace GamecraftModdingAPI.Blocks return ret.ToArray(); } - public ObjectIdentifier[] GetObjectIDsFromID(byte id) + public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim) { var ret = new FasterList(4); if (!entitiesDB.HasAny(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) return new ObjectIdentifier[0]; var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); foreach (ref ObjectIdEntityStruct oid in oids) - if (oid.objectId == id) + if (sim ? oid.simObjectId == id : oid.objectId == id) ret.Add(new ObjectIdentifier(oid.ID)); return ret.ToArray(); } diff --git a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs index 3beacfa..6357053 100644 --- a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs +++ b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs @@ -32,10 +32,25 @@ namespace GamecraftModdingAPI.Blocks } /// - /// Finds the identfier blocks with the given ID. + /// Simulation-time ID. Assigned by the game starting from 0. + /// + public byte SimID + { + get => BlockEngine.GetBlockInfo(Id).simObjectId; + } + + /// + /// Finds the identifier blocks with the given ID. /// /// The ID to look for /// An array that may be empty - public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A')); + public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false); + + /// + /// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0. + /// + /// + /// + public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true); } } \ No newline at end of file