From 3dcce18ceb63da9c88a6d285623cb6f98b41c167 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 8 Jun 2020 00:10:10 +0200 Subject: [PATCH] Add method to get selected blocks by player --- .../GamecraftModdingAPI.csproj | 1 + GamecraftModdingAPI/Player.cs | 9 ++++++++ GamecraftModdingAPI/Players/PlayerEngine.cs | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index c72b77a..559ddd8 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -8,6 +8,7 @@ GNU General Public Licence 3+ https://git.exmods.org/modtainers/GamecraftModdingAPI en-CA + true diff --git a/GamecraftModdingAPI/Player.cs b/GamecraftModdingAPI/Player.cs index 086c910..efb381e 100644 --- a/GamecraftModdingAPI/Player.cs +++ b/GamecraftModdingAPI/Player.cs @@ -366,6 +366,15 @@ namespace GamecraftModdingAPI : null; } + /// + /// Returns the blocks that are in the player's current selection. + /// + /// An array of blocks or an empty array + public Block[] GetSelectedBlocks() + { + return playerEngine.GetSelectedBlocks(Id); + } + public bool Equals(Player other) { if (ReferenceEquals(null, other)) return false; diff --git a/GamecraftModdingAPI/Players/PlayerEngine.cs b/GamecraftModdingAPI/Players/PlayerEngine.cs index bcbfd11..4ab5ed9 100644 --- a/GamecraftModdingAPI/Players/PlayerEngine.cs +++ b/GamecraftModdingAPI/Players/PlayerEngine.cs @@ -5,6 +5,7 @@ using RobocraftX.Character; using RobocraftX.Character.Movement; using RobocraftX.Common.Players; using RobocraftX.Common.Input; +using RobocraftX.CR.MachineEditing.BoxSelect; using RobocraftX.Physics; using RobocraftX.Blocks.Ghost; using RobocraftX.Character.Camera; @@ -408,5 +409,26 @@ namespace GamecraftModdingAPI.Players return null; } + + public unsafe Block[] GetSelectedBlocks(uint playerid) + { + if (!entitiesDB.Exists(playerid, + BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup)) + return new Block[0]; + var state = entitiesDB.QueryEntity(playerid, + BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup); + var blocks = entitiesDB.QueryEntity(playerid, + BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup); + if (!state.active) return new Block[0]; + var pointer = (EGID*) blocks.selectedBlocks.ToPointer(); + var ret = new Block[blocks.count]; + for (int j = 0; j < blocks.count; j++) + { + var egid = pointer[j]; + ret[j] = new Block(egid); + } + + return ret; + } } }