diff --git a/GamecraftModdingAPI/App/Client.cs b/GamecraftModdingAPI/App/Client.cs
index e95d9f3..fbe960e 100644
--- a/GamecraftModdingAPI/App/Client.cs
+++ b/GamecraftModdingAPI/App/Client.cs
@@ -65,6 +65,15 @@ namespace GamecraftModdingAPI.App
}
}
+ ///
+ /// Whether Gamecraft is in the Main Menu
+ ///
+ /// true if in menu; false when loading or in a game.
+ public bool InMenu
+ {
+ get => appEngine.IsInMenu;
+ }
+
internal static void Init()
{
MenuEngineManager.AddMenuEngine(appEngine);
diff --git a/GamecraftModdingAPI/App/Game.cs b/GamecraftModdingAPI/App/Game.cs
index 3fd4900..d6a4eff 100644
--- a/GamecraftModdingAPI/App/Game.cs
+++ b/GamecraftModdingAPI/App/Game.cs
@@ -7,6 +7,8 @@ using RobocraftX.GUI.MyGamesScreen;
using RobocraftX.StateSync;
using Svelto.ECS;
+using GamecraftModdingAPI;
+using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Tasks;
using GamecraftModdingAPI.Utility;
@@ -414,6 +416,28 @@ namespace GamecraftModdingAPI.App
return debugIds.Remove(id);
}
+ ///
+ /// Gets the blocks in the game.
+ /// This returns null when in a loading state, and throws AppStateException when in menu.
+ ///
+ /// The blocks in game.
+ /// The block to search for. BlockIDs.Invalid will return all blocks.
+ public Block[] GetBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
+ {
+ if (!VerifyMode()) return null;
+ if (menuMode)
+ {
+ throw new AppStateException("Game object references a menu item but GetBlocksInGame only works on the currently-loaded game");
+ }
+ EGID[] blockEGIDs = gameEngine.GetAllBlocksInGame(filter);
+ Block[] blocks = new Block[blockEGIDs.Length];
+ for (int b = 0; b < blockEGIDs.Length; b++)
+ {
+ blocks[b] = new Block(blockEGIDs[b]);
+ }
+ return blocks;
+ }
+
~Game()
{
foreach (string id in debugIds)
diff --git a/GamecraftModdingAPI/App/GameGameEngine.cs b/GamecraftModdingAPI/App/GameGameEngine.cs
index d46eb32..cbb1c79 100644
--- a/GamecraftModdingAPI/App/GameGameEngine.cs
+++ b/GamecraftModdingAPI/App/GameGameEngine.cs
@@ -10,6 +10,7 @@ using Svelto.ECS;
using Svelto.Tasks;
using Svelto.Tasks.Lean;
+using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
@@ -93,5 +94,32 @@ namespace GamecraftModdingAPI.App
{
TimeRunningModeUtil.ToggleTimeRunningState(entitiesDB);
}
+
+ public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
+ {
+ EntityCollection blocks = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
+ if (filter == BlockIDs.Invalid)
+ {
+ EGID[] blockEGIDs = new EGID[blocks.count];
+ for (uint b = 0; b < blocks.count; b++)
+ {
+ blockEGIDs[b] = blocks[b].ID;
+ }
+ return blockEGIDs;
+ }
+ else
+ {
+ uint dbidFilter = (uint)filter;
+ List blockEGIDs = new List();
+ for (uint b = 0; b < blocks.count; b++)
+ {
+ if (blocks[b].DBID == dbidFilter)
+ {
+ blockEGIDs.Add(blocks[b].ID);
+ }
+ }
+ return blockEGIDs.ToArray();
+ }
+ }
}
}