Browse Source

Add method to get selected blocks by player

tags/v1.2.0
NorbiPeti 4 years ago
parent
commit
3dcce18ceb
3 changed files with 32 additions and 0 deletions
  1. +1
    -0
      GamecraftModdingAPI/GamecraftModdingAPI.csproj
  2. +9
    -0
      GamecraftModdingAPI/Player.cs
  3. +22
    -0
      GamecraftModdingAPI/Players/PlayerEngine.cs

+ 1
- 0
GamecraftModdingAPI/GamecraftModdingAPI.csproj View File

@@ -8,6 +8,7 @@
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>
<NeutralLanguage>en-CA</NeutralLanguage>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>


+ 9
- 0
GamecraftModdingAPI/Player.cs View File

@@ -366,6 +366,15 @@ namespace GamecraftModdingAPI
: null;
}

/// <summary>
/// Returns the blocks that are in the player's current selection.
/// </summary>
/// <returns>An array of blocks or an empty array</returns>
public Block[] GetSelectedBlocks()
{
return playerEngine.GetSelectedBlocks(Id);
}

public bool Equals(Player other)
{
if (ReferenceEquals(null, other)) return false;


+ 22
- 0
GamecraftModdingAPI/Players/PlayerEngine.cs View File

@@ -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<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup))
return new Block[0];
var state = entitiesDB.QueryEntity<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
var blocks = entitiesDB.QueryEntity<SelectedBlocksStruct>(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;
}
}
}

Loading…
Cancel
Save