Block fixes, add mass and complexity properties, make Player.LocalPlayer return null if not found
This commit is contained in:
parent
c6dae688fe
commit
7f63944a6e
5 changed files with 53 additions and 6 deletions
|
@ -67,7 +67,7 @@ namespace TechbloxModdingAPI
|
|||
/// <returns>The block object or null if doesn't exist</returns>
|
||||
public static Block GetLastPlacedBlock()
|
||||
{
|
||||
uint lastBlockID = (uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null) - 1;
|
||||
uint lastBlockID = CommonExclusiveGroups.blockIDGeneratorClient.Peek() - 1;
|
||||
EGID? egid = BlockEngine.FindBlockEGID(lastBlockID);
|
||||
return egid.HasValue ? New(egid.Value) : null;
|
||||
}
|
||||
|
@ -366,8 +366,12 @@ namespace TechbloxModdingAPI
|
|||
get
|
||||
{
|
||||
if (blockGroup != null) return blockGroup;
|
||||
if (!GameState.IsBuildMode()) return null; // Breaks in simulation
|
||||
var bgec = BlockEngine.GetBlockInfo<BlockGroupEntityComponent>(this);
|
||||
return blockGroup = bgec.currentBlockGroup == -1 ? null : new BlockGroup(bgec.currentBlockGroup, this);
|
||||
return blockGroup = bgec.currentBlockGroup == -1
|
||||
? null
|
||||
: GetInstance(new EGID((uint)bgec.currentBlockGroup, BlockGroupExclusiveGroups.BlockGroupEntityGroup),
|
||||
egid => new BlockGroup((int)egid.entityID, this));
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -395,6 +399,23 @@ namespace TechbloxModdingAPI
|
|||
set => BlockEngine.GetBlockInfo<BlockStaticComponent>(this).isStatic = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mass of the block.
|
||||
/// </summary>
|
||||
public float Mass
|
||||
{
|
||||
get => BlockEngine.GetBlockInfo<MassStruct>(this).mass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Block complexity used for build rules. Determines the 'cost' of the block.
|
||||
/// </summary>
|
||||
public BlockComplexity Complexity
|
||||
{
|
||||
get => new(BlockEngine.GetBlockInfo<BlockComplexityComponent>(this));
|
||||
set => BlockEngine.GetBlockInfo<BlockComplexityComponent>(this) = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the block exists. The other properties will return a default value if the block doesn't exist.
|
||||
/// If the block was just placed, then this will also return false but the properties will work correctly.
|
||||
|
|
17
TechbloxModdingAPI/Blocks/BlockComplexity.cs
Normal file
17
TechbloxModdingAPI/Blocks/BlockComplexity.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using RobocraftX.Blocks;
|
||||
|
||||
namespace TechbloxModdingAPI.Blocks
|
||||
{
|
||||
public record BlockComplexity(int Cpu, int Power)
|
||||
{
|
||||
public BlockComplexity(BlockComplexityComponent component) : this(component.cpu, component.power)
|
||||
{
|
||||
}
|
||||
|
||||
public int Cpu { get; } = Cpu;
|
||||
public int Power { get; } = Power;
|
||||
|
||||
public static implicit operator BlockComplexityComponent(BlockComplexity complexity) =>
|
||||
new() { cpu = complexity.Cpu, power = complexity.Power };
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using Gamecraft.Damage;
|
||||
using RobocraftX.Common;
|
||||
using Svelto.ECS;
|
||||
using Techblox.Physics;
|
||||
|
||||
namespace TechbloxModdingAPI
|
||||
{
|
||||
|
@ -36,6 +37,11 @@ namespace TechbloxModdingAPI
|
|||
set => Block.BlockEngine.GetBlockInfo<HealthEntityComponent>(this).healthMultiplier = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mass of the cluster.
|
||||
/// </summary>
|
||||
public float Mass => Block.BlockEngine.GetBlockInfo<ClusterMassComponent>(this).mass;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the simulation-time rigid bodies for the chunks in this cluster.
|
||||
/// </summary>
|
||||
|
|
|
@ -66,13 +66,16 @@ namespace TechbloxModdingAPI
|
|||
|
||||
/// <summary>
|
||||
/// Returns the current player belonging to this client. It will be different after entering/leaving simulation.
|
||||
/// May return null if the local player doesn't exist.
|
||||
/// </summary>
|
||||
public static Player LocalPlayer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (localPlayer == null || localPlayer.Id != playerEngine.GetLocalPlayer())
|
||||
localPlayer = GetInstance(playerEngine.GetLocalPlayer());
|
||||
var playerId = playerEngine.GetLocalPlayer();
|
||||
if (playerId == uint.MaxValue) return null;
|
||||
if (localPlayer == null || localPlayer.Id != playerId)
|
||||
localPlayer = GetInstance(playerId);
|
||||
return localPlayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,13 +75,13 @@ namespace TechbloxModdingAPI
|
|||
|
||||
public float Mass
|
||||
{
|
||||
get => math.rcp(GetStruct().physicsMass.InverseMass);
|
||||
get => 0f; //TODO: Get mass from UECS entity
|
||||
//set => GetStruct().physicsMass.InverseMass = math.rcp(value);
|
||||
}
|
||||
|
||||
public float3 CenterOfMass
|
||||
{
|
||||
get => GetStruct().physicsMass.CenterOfMass;
|
||||
get => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(this).centreOfMass;
|
||||
//set => GetStruct().physicsMass.CenterOfMass = value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue