diff --git a/TechbloxModdingAPI/FlyCam.cs b/TechbloxModdingAPI/FlyCam.cs
deleted file mode 100644
index edf0691..0000000
--- a/TechbloxModdingAPI/FlyCam.cs
+++ /dev/null
@@ -1,132 +0,0 @@
-using RobocraftX.Physics;
-using Svelto.ECS;
-using Svelto.ECS.EntityStructs;
-using Techblox.FlyCam;
-using TechbloxModdingAPI.Blocks;
-using TechbloxModdingAPI.Players;
-using TechbloxModdingAPI.Utility;
-using Unity.Mathematics;
-using UnityEngine;
-
-namespace TechbloxModdingAPI
-{
- public class FlyCam : EcsObjectBase
- {
- private static FlyCamEngine Engine = new FlyCamEngine();
-
- public override EGID Id { get; }
-
- public FlyCam(uint id) => Id = new EGID(id, Techblox.FlyCam.FlyCam.Group);
-
- ///
- /// The local player's camera.
- ///
- public static FlyCam LocalCamera => new FlyCam(Player.LocalPlayer.Id);
-
- ///
- /// The current position of the camera.
- ///
- public float3 Position
- {
- get => Engine.GetComponent(this).position;
- set
- {
- Engine.GetComponent(this).position = value;
- Engine.GetComponent(this).position = value;
- }
- }
-
- ///
- /// The current rotation of the camera.
- ///
- public float3 Rotation
- {
- get => ((Quaternion) Engine.GetComponent(this).rotation).eulerAngles;
- set
- {
- Engine.GetComponent(this).rotation = Quaternion.Euler(value);
- Engine.GetComponent(this).rotation = Quaternion.Euler(value);
- }
- }
-
- ///
- /// The current direction the camera is moving.
- ///
- public float3 MovementDirection
- {
- get => Engine.GetComponent(this).movementDirection;
- set => Engine.GetComponent(this).movementDirection = value;
- }
-
- ///
- /// Whether the camera (player) is sprinting.
- ///
- public bool Sprinting
- {
- get => Engine.GetComponent(this).sprinting;
- set => Engine.GetComponent(this).sprinting = value;
- }
-
- ///
- /// The speed setting of the camera.
- ///
- public float Speed
- {
- get => Engine.GetComponent(this).speed;
- set => Engine.GetComponent(this).speed = value;
- }
-
- ///
- /// The multiplier setting to use when sprinting.
- ///
- public float SpeedSprintMultiplier
- {
- get => Engine.GetComponent(this).speedSprintMultiplier;
- set => Engine.GetComponent(this).speedSprintMultiplier = value;
- }
-
- ///
- /// The acceleration setting of the camera.
- ///
- public float Acceleration
- {
- get => Engine.GetComponent(this).acceleration;
- set => Engine.GetComponent(this).acceleration = value;
- }
-
- ///
- /// The current velocity of the camera.
- ///
- public float3 Velocity
- {
- get => Engine.GetComponent(this).velocity;
- set => Engine.GetComponent(this).velocity = value;
- }
-
- ///
- /// The current angular velocity of the camera.
- ///
- public float3 AngularVelocity
- {
- get => Engine.GetComponent(this).angularVelocity;
- set => Engine.GetComponent(this).angularVelocity = value;
- }
-
- ///
- /// The player's selected block ID in their hand.
- ///
- /// The selected block.
- public BlockIDs SelectedBlock => (BlockIDs)Engine.GetSelectedBlock(this);
-
- ///
- /// The player's selected block color in their hand.
- ///
- /// The selected block's color.
- public BlockColor SelectedColor => new BlockColor(Engine.GetSelectedColor(this));
-
- public static void Init()
- {
- GameEngineManager.AddGameEngine(Engine);
- }
- }
-}
\ No newline at end of file
diff --git a/TechbloxModdingAPI/Main.cs b/TechbloxModdingAPI/Main.cs
index af25bde..a390021 100644
--- a/TechbloxModdingAPI/Main.cs
+++ b/TechbloxModdingAPI/Main.cs
@@ -71,7 +71,6 @@ namespace TechbloxModdingAPI
Input.FakeInput.Init();
// init object-oriented classes
Player.Init();
- FlyCam.Init();
Block.Init();
BlockGroup.Init();
Wire.Init();
diff --git a/TechbloxModdingAPI/Player.FlyCamSettings.cs b/TechbloxModdingAPI/Player.FlyCamSettings.cs
new file mode 100644
index 0000000..b947477
--- /dev/null
+++ b/TechbloxModdingAPI/Player.FlyCamSettings.cs
@@ -0,0 +1,51 @@
+using RobocraftX.Physics;
+using Svelto.ECS;
+using Svelto.ECS.EntityStructs;
+using Techblox.FlyCam;
+using TechbloxModdingAPI.Blocks;
+using TechbloxModdingAPI.Players;
+using TechbloxModdingAPI.Utility;
+using Unity.Mathematics;
+using UnityEngine;
+
+namespace TechbloxModdingAPI
+{
+ public partial class Player
+ {
+ ///
+ /// Whether the camera (player) is sprinting.
+ ///
+ public bool Sprinting
+ {
+ get => playerEngine.GetCharacterStruct(Id).Get().sprinting;
+ set => playerEngine.GetCharacterStruct(Id).Get().sprinting = value;
+ }
+
+ ///
+ /// The speed setting of the camera.
+ ///
+ public float Speed
+ {
+ get => playerEngine.GetCharacterStruct(Id).Get().speed;
+ set => playerEngine.GetCharacterStruct(Id).Get().speed = value;
+ }
+
+ ///
+ /// The multiplier setting to use when sprinting.
+ ///
+ public float SpeedSprintMultiplier
+ {
+ get => playerEngine.GetCharacterStruct(Id).Get().speedSprintMultiplier;
+ set => playerEngine.GetCharacterStruct(Id).Get().speedSprintMultiplier = value;
+ }
+
+ ///
+ /// The acceleration setting of the camera.
+ ///
+ public float Acceleration
+ {
+ get => playerEngine.GetCharacterStruct(Id).Get().acceleration;
+ set => playerEngine.GetCharacterStruct(Id).Get().acceleration = value;
+ }
+ }
+}
\ No newline at end of file
diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs
index 7d37f9b..02e28f5 100644
--- a/TechbloxModdingAPI/Player.cs
+++ b/TechbloxModdingAPI/Player.cs
@@ -1,17 +1,23 @@
using System;
+using RobocraftX.Character;
using Unity.Mathematics;
using RobocraftX.Common;
using RobocraftX.Common.Players;
+using RobocraftX.Physics;
using Svelto.ECS;
+using Techblox.Camera;
+using Techblox.FlyCam;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Players;
+using TechbloxModdingAPI.Utility;
+using UnityEngine;
namespace TechbloxModdingAPI
{
///
/// An in-game player character. Any Leo you see is a player.
///
- public class Player : IEquatable, IEquatable
+ public partial class Player : IEquatable, IEquatable
{
// static functionality
private static PlayerEngine playerEngine = new PlayerEngine();
@@ -123,50 +129,33 @@ namespace TechbloxModdingAPI
/// The position.
public float3 Position
{
- get
- {
- return playerEngine.GetLocation(Id);
- }
-
- set
- {
- playerEngine.SetLocation(Id, value, false);
- }
- }
+ get => playerEngine.GetCharacterStruct(Id).Get().position;
+ set => playerEngine.SetLocation(Id, value, false);
+ }
///
/// The player's current rotation.
///
/// The rotation.
public float3 Rotation
- {
- get
- {
- return playerEngine.GetRotation(Id);
- }
-
- set
- {
- playerEngine.SetRotation(Id, value);
- }
- }
+ {
+ get => ((Quaternion) (GameState.IsBuildMode()
+ ? playerEngine.GetCameraStruct(Id).Get().rotation
+ : playerEngine.GetCharacterStruct(Id).Get().rotation)).eulerAngles;
+ set => _ = GameState.IsBuildMode()
+ ? playerEngine.GetCameraStruct(Id).Get().rotation = quaternion.Euler(value)
+ : playerEngine.GetCharacterStruct(Id).Get().rotation = quaternion.Euler(value);
+ }
///
/// The player's current velocity.
///
/// The velocity.
public float3 Velocity
- {
- get
- {
- return playerEngine.GetLinearVelocity(Id);
- }
-
- set
- {
- playerEngine.SetLinearVelocity(Id, value);
- }
- }
+ {
+ get => playerEngine.GetCharacterStruct(Id).Get().velocity;
+ set => playerEngine.GetCharacterStruct(Id).Get().velocity = value;
+ }
///
/// The player's current angular velocity.
@@ -174,36 +163,18 @@ namespace TechbloxModdingAPI
/// The angular velocity.
public float3 AngularVelocity
{
- get
- {
- return playerEngine.GetAngularVelocity(Id);
- }
-
- set
- {
- playerEngine.SetAngularVelocity(Id, value);
- }
+ get => playerEngine.GetCharacterStruct(Id).Get().angularVelocity;
+ set => playerEngine.GetCharacterStruct(Id).Get().angularVelocity = value;
}
///
/// The player's mass.
///
/// The mass.
- public float Mass
- {
- get
- {
- return 1f / playerEngine.GetMass(Id).InverseMass;
- }
-
- // FIXME: Setting mass doesn't do anything
- /*set
- {
- playerEngine.SetInverseMass(Id, 1f / value);
- }*/
- }
+ public float Mass =>
+ 1f / playerEngine.GetCharacterStruct(Id).Get().physicsMass.InverseMass;
- private float _ping = -1f;
+ private float _ping = -1f;
///
/// The player's latest network ping time.
@@ -213,10 +184,10 @@ namespace TechbloxModdingAPI
{
get
{
- float? temp = playerEngine.GetLastPingTime(Id, Type);
- if (temp.HasValue)
+ var opt = playerEngine.GetPlayerStruct(Id, Type);
+ if (opt)
{
- _ping = temp.Value;
+ _ping = opt.Get().lastPingTimeSinceLevelLoad ?? _ping;
}
return _ping;
}
@@ -227,14 +198,15 @@ namespace TechbloxModdingAPI
///
/// The initial health.
public float InitialHealth
- {
- get => playerEngine.GetInitialHealth(Id);
+ {
+ get
+ {
+ var opt = playerEngine.GetCharacterStruct(Id);
+ return opt ? opt.Get().initialHealth : -1f;
+ }
- set
- {
- playerEngine.SetInitialHealth(Id, value);
- }
- }
+ set => playerEngine.GetCharacterStruct(Id).Get().initialHealth = value;
+ }
///
/// The player's current health in Simulation (aka Time Running) mode.
@@ -242,12 +214,13 @@ namespace TechbloxModdingAPI
/// The current health.
public float CurrentHealth
{
- get => playerEngine.GetCurrentHealth(Id);
+ get
+ {
+ var opt = playerEngine.GetCharacterStruct(Id);
+ return opt ? opt.Get().currentHealth : -1f;
+ }
- set
- {
- playerEngine.DamagePlayer(Id, CurrentHealth - value);
- }
+ set => playerEngine.GetCharacterStruct(Id).Get().currentHealth = value;
}
///
@@ -255,14 +228,20 @@ namespace TechbloxModdingAPI
///
/// true if damageable; otherwise, false.
public bool Damageable
- {
- get => playerEngine.GetDamageable(Id);
+ {
+ get
+ {
+ var opt = playerEngine.GetCharacterStruct(Id);
+ return opt.Get().canTakeDamageStat;
+ }
- set
- {
- playerEngine.SetDamageable(Id, value);
- }
- }
+ set
+ {
+ ref var healthStruct = ref playerEngine.GetCharacterStruct(Id).Get();
+ healthStruct.canTakeDamage = value;
+ healthStruct.canTakeDamageStat = value;
+ }
+ }
///
/// The player's lives when initially entering Simulation (aka Time Running) mode.
@@ -270,9 +249,13 @@ namespace TechbloxModdingAPI
/// The initial lives.
public uint InitialLives
{
- get => playerEngine.GetInitialLives(Id);
+ get
+ {
+ var opt = playerEngine.GetCharacterStruct(Id);
+ return opt ? opt.Get().initialLives : uint.MaxValue;
+ }
- set => playerEngine.SetInitialLives(Id, value);
+ set => playerEngine.GetCharacterStruct(Id).Get().initialLives = value;
}
///
@@ -281,19 +264,23 @@ namespace TechbloxModdingAPI
/// The current lives.
public uint CurrentLives
{
- get => playerEngine.GetCurrentLives(Id);
+ get
+ {
+ var opt = playerEngine.GetCharacterStruct(Id);
+ return opt ? opt.Get().currentLives : uint.MaxValue;
+ }
- set => playerEngine.SetCurrentLives(Id, value);
+ set => playerEngine.GetCharacterStruct(Id).Get().currentLives = value;
}
- ///
+ /*///
/// Whether the Game Over screen is displayed for the player.
///
/// true if game over; otherwise, false.
public bool GameOver
{
get => playerEngine.GetGameOverScreen(Id);
- }
+ }*/
///
/// Whether the player is dead.
@@ -313,7 +300,8 @@ namespace TechbloxModdingAPI
{
get
{
- return BuildCamera.SelectedBlock;
+ var optstruct = playerEngine.GetCharacterStruct(Id);
+ return optstruct ? (BlockIDs) optstruct.Get().SelectedDBPartID : BlockIDs.Invalid;
}
}
@@ -325,7 +313,8 @@ namespace TechbloxModdingAPI
{
get
{
- return BuildCamera.SelectedColor;
+ var optstruct = playerEngine.GetCharacterStruct(Id);
+ return optstruct ? new BlockColor(optstruct.Get().indexInPalette) : BlockColors.Default;
}
}
@@ -337,7 +326,8 @@ namespace TechbloxModdingAPI
{
get
{
- return new BlockColor(playerEngine.GetSelectedColor(Id));
+ var optstruct = playerEngine.GetCharacterStruct(Id);
+ return optstruct ? new BlockColor(optstruct.Get().indexInPalette) : BlockColors.Default;
}
}
@@ -346,9 +336,11 @@ namespace TechbloxModdingAPI
///
public Blueprint SelectedBlueprint
{
- get => playerEngine.GetPlayerStruct(Id, out LocalBlueprintInputStruct lbis)
- ? new Blueprint(lbis.selectedBlueprintId)
- : null;
+ get
+ {
+ var lbiso = playerEngine.GetPlayerStruct(Id, Type);
+ return lbiso ? new Blueprint(lbiso.Get().selectedBlueprintId) : null;
+ }
set => BlockGroup._engine.SelectBlueprint(value?.Id ?? uint.MaxValue);
}
@@ -356,7 +348,7 @@ namespace TechbloxModdingAPI
/// The player's mode in time stopped mode, determining what they place.
///
public PlayerBuildingMode BuildingMode => (PlayerBuildingMode) playerEngine
- .GetCharacterStruct(Id, out _).timeStoppedContext;
+ .GetCharacterStruct(Id).Get().timeStoppedContext;
// object methods
@@ -373,7 +365,7 @@ namespace TechbloxModdingAPI
float3 location = new float3(x, y, z);
if (relative)
{
- location += playerEngine.GetLocation(Id);
+ location += Position;
}
playerEngine.SetLocation(Id, location, exitSeat: exitSeat);
}
@@ -395,7 +387,7 @@ namespace TechbloxModdingAPI
/// Returns the rigid body the player is currently looking at during simulation.
///
/// The maximum distance from the player (default is the player's building reach)
- /// The block or null if not found
+ /// The body or null if not found
public SimBody GetSimBodyLookedAt(float maxDistance = -1f)
{
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
@@ -413,11 +405,6 @@ namespace TechbloxModdingAPI
return playerEngine.GetSelectedBlocks(Id);
}
- ///
- /// The camera of this player used when building.
- ///
- public FlyCam BuildCamera => new FlyCam(Id);
-
public bool Equals(Player other)
{
if (ReferenceEquals(null, other)) return false;
diff --git a/TechbloxModdingAPI/Players/FlyCamEngine.cs b/TechbloxModdingAPI/Players/FlyCamEngine.cs
deleted file mode 100644
index 7cad252..0000000
--- a/TechbloxModdingAPI/Players/FlyCamEngine.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using Svelto.ECS;
-using Techblox.FlyCam;
-using TechbloxModdingAPI.Engines;
-using TechbloxModdingAPI.Utility;
-
-namespace TechbloxModdingAPI.Players
-{
- public class FlyCamEngine : IApiEngine
- {
- public void Ready()
- {
- }
-
- public EntitiesDB entitiesDB { get; set; }
- public void Dispose()
- {
- }
-
- public string Name => "TechbloxModdingAPIFlyCamEngine";
- public bool isRemovable => false;
-
- public ref T GetComponent(FlyCam cam) where T : unmanaged, IEntityComponent
- {
- return ref entitiesDB.QueryEntityOrDefault(cam);
- }
-
- public ushort GetSelectedBlock(FlyCam cam)
- {
- var oc = entitiesDB.QueryEntityOptional(cam);
- return oc ? (ushort) oc.Get().SelectedDBPartID : ushort.MaxValue;
- }
-
- public byte GetSelectedColor(FlyCam cam)
- {
- var oc = entitiesDB.QueryEntityOptional(cam);
- return oc ? oc.Get().indexInPalette : (byte) 255;
- }
- }
-}
\ No newline at end of file
diff --git a/TechbloxModdingAPI/Players/PlayerBuildingMode.cs b/TechbloxModdingAPI/Players/PlayerBuildingMode.cs
index 383e1af..5e75555 100644
--- a/TechbloxModdingAPI/Players/PlayerBuildingMode.cs
+++ b/TechbloxModdingAPI/Players/PlayerBuildingMode.cs
@@ -5,6 +5,7 @@
BlockMode,
ColourMode,
ConfigMode,
- BlueprintMode
+ BlueprintMode,
+ MaterialMode
}
}
\ No newline at end of file
diff --git a/TechbloxModdingAPI/Players/PlayerEngine.cs b/TechbloxModdingAPI/Players/PlayerEngine.cs
index b4df628..f5fbb26 100644
--- a/TechbloxModdingAPI/Players/PlayerEngine.cs
+++ b/TechbloxModdingAPI/Players/PlayerEngine.cs
@@ -21,6 +21,7 @@ using HarmonyLib;
using RobocraftX.Common;
using Svelto.ECS.DataStructures;
using TechbloxModdingAPI.Engines;
+using TechbloxModdingAPI.Utility;
namespace TechbloxModdingAPI.Players
{
@@ -98,17 +99,6 @@ namespace TechbloxModdingAPI.Players
|| entitiesDB.Exists(playerId, PlayersExclusiveGroups.RemotePlayers);
}
- public float3 GetLocation(uint playerId)
- {
- if (entitiesDB == null) return float3.zero;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return rbes.position;
- }
- return float3.zero;
- }
-
public bool SetLocation(uint playerId, float3 location, bool exitSeat = true)
{
if (entitiesDB == null) return false;
@@ -131,233 +121,6 @@ namespace TechbloxModdingAPI.Players
return false;
}
- public float3 GetRotation(uint playerId)
- {
- if (entitiesDB == null) return float3.zero;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return ((Quaternion) rbes.rotation).eulerAngles;
- }
- return default(float3);
- }
-
- public bool SetRotation(uint playerId, float3 value)
- {
- if (entitiesDB == null) return false;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- Quaternion q = rbes.rotation;
- q.eulerAngles = value;
- rbes.rotation = q;
- return true;
- }
- return false;
- }
-
- public float3 GetLinearVelocity(uint playerId)
- {
- if (entitiesDB == null) return float3.zero;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return rbes.velocity;
- }
- return float3.zero;
- }
-
- public bool SetLinearVelocity(uint playerId, float3 value)
- {
- if (entitiesDB == null) return false;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- rbes.velocity = value;
- return true;
- }
- return false;
- }
-
- public float3 GetAngularVelocity(uint playerId)
- {
- if (entitiesDB == null) return float3.zero;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return rbes.angularVelocity;
- }
- return float3.zero;
- }
-
- public bool SetAngularVelocity(uint playerId, float3 value)
- {
- if (entitiesDB == null) return false;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- rbes.angularVelocity = value;
- return true;
- }
- return false;
- }
-
- public PhysicsMass GetMass(uint playerId)
- {
- if (entitiesDB == null) return default(PhysicsMass);
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return rbes.physicsMass;
- }
- return default(PhysicsMass);
- }
-
- public bool SetInverseMass(uint playerId, float inverseMass)
- {
- if (entitiesDB == null) return false;
- ref var rbes = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- rbes.physicsMass.InverseInertia = inverseMass;
- return true;
- }
- return false;
- }
-
- public float? GetLastPingTime(uint playerId, PlayerType type)
- {
- if (entitiesDB == null) return null;
- EGID egid = new EGID(playerId, PlayerGroupFromEnum(type));
- if (entitiesDB.Exists(egid))
- {
- //return entitiesDB.QueryEntity(egid).lastPingTimeSinceLevelLoad; - TODO
- }
- return null;
- }
-
- public float GetInitialHealth(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.initialHealth;
- }
- return -1f;
- }
-
- public bool SetInitialHealth(uint playerId, float val)
- {
- if (entitiesDB == null) return false;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- c.initialHealth = val;
- return true;
- }
- return false;
- }
-
- public float GetCurrentHealth(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.currentHealth;
- }
- return -1f;
- }
-
- public bool SetCurrentHealth(uint playerId, float val)
- {
- if (entitiesDB == null) return false;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- c.currentHealth = val;
- return true;
- }
- return false;
- }
-
- public bool DamagePlayer(uint playerId, float amount)
- {
- if (entitiesDB == null) return false;
- return SetCurrentHealth(playerId, GetCurrentHealth(playerId) - amount);
- }
-
- public bool GetDamageable(uint playerId)
- {
- if (entitiesDB == null) return false;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.canTakeDamageStat;
- }
- return false;
- }
-
- public bool SetDamageable(uint playerId, bool val)
- {
- if (entitiesDB == null) return false;
- ref var ches = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- ches.canTakeDamage = val;
- ches.canTakeDamage = val;
- return true;
- }
- return false;
- }
-
- public uint GetInitialLives(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.initialLives;
- }
- return uint.MaxValue;
- }
-
- public bool SetInitialLives(uint playerId, uint val)
- {
- if (entitiesDB == null) return false;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- c.initialLives = val;
- return true;
- }
- return false;
- }
-
- public uint GetCurrentLives(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.currentLives;
- }
- return uint.MaxValue;
- }
-
- public bool SetCurrentLives(uint playerId, uint val)
- {
- if (entitiesDB == null) return false;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- c.currentLives = val;
- return true;
- }
- return false;
- }
-
public bool GetGameOverScreen(uint playerId)
{
if (entitiesDB == null) return false;
@@ -372,78 +135,44 @@ namespace TechbloxModdingAPI.Players
return entitiesDB.Exists(playerId, CharacterExclusiveGroups.DeadCharacters);
}
- public int GetSelectedBlock(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.SelectedDBPartID;
- }
- return ushort.MaxValue;
- }
-
- public byte GetSelectedColor(uint playerId)
- {
- if (entitiesDB == null) return 0;
- ref var c = ref GetCharacterStruct(playerId, out bool exists);
- if (exists)
- {
- return c.indexInPalette;
- }
- return 255;
- }
-
// reusable methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private ExclusiveGroup PlayerGroupFromEnum(PlayerType type)
+ public OptionalRef GetCharacterStruct(uint playerId) where T : unmanaged, IEntityComponent
{
- return type == PlayerType.Local ? PlayersExclusiveGroups.LocalPlayers : PlayersExclusiveGroups.RemotePlayers;
+ if (GameState.IsBuildMode())
+ return entitiesDB.QueryEntityOptional(new EGID(playerId, Techblox.FlyCam.FlyCam.Group));
+
+ var characterGroups = CharacterExclusiveGroups.AllCharacters;
+ for (int i = 0; i < characterGroups.count; i++)
+ {
+ EGID egid = new EGID(playerId, characterGroups[i]);
+ var opt = entitiesDB.QueryEntityOptional(egid);
+ if (opt.Exists)
+ return opt;
+ }
+
+ return new OptionalRef();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public ref T GetCharacterStruct(uint playerId, out bool exists) where T : unmanaged, IEntityComponent
+ public OptionalRef GetPlayerStruct(uint playerId, PlayerType type) where T : unmanaged, IEntityComponent
{
- var characterGroups = CharacterExclusiveGroups.AllCharacters;
- for (int i = 0; i < characterGroups.count; i++)
- {
- EGID egid = new EGID(playerId, characterGroups[i]);
- if (entitiesDB.Exists(egid))
- {
- exists = true;
- return ref entitiesDB.QueryEntity(egid);
- }
- }
-
- exists = false;
- T[] arr = new T[1];
- return ref arr[0]; //Return default value
+ var playerGroup = type == PlayerType.Local ? PlayersExclusiveGroups.LocalPlayers : PlayersExclusiveGroups.RemotePlayers;
+ EGID egid = new EGID(playerId, playerGroup);
+ return entitiesDB.QueryEntityOptional(egid);
}
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool GetPlayerStruct(uint playerId, out T s) where T : unmanaged, IEntityComponent
+ public OptionalRef GetCameraStruct(uint playerId) where T : unmanaged, IEntityComponent
{
- var playerGroups = PlayersExclusiveGroups.AllPlayers;
- for (int i = 0; i < playerGroups.count; i++)
- {
- EGID egid = new EGID(playerId, playerGroups[i]);
- if (entitiesDB.Exists(egid))
- {
- s = entitiesDB.QueryEntity(egid);
- return true;
- }
- }
- s = default;
- return false;
+ return entitiesDB.QueryEntityOptional(new EGID(playerId, CameraExclusiveGroups.CameraGroup));
}
public EGID GetThingLookedAt(uint playerId, float maxDistance = -1f)
{
- if (!entitiesDB.TryQueryMappedEntities(
- CameraExclusiveGroups.CameraGroup, out var mapper))
- return EGID.Empty;
- mapper.TryGetEntity(playerId, out CharacterCameraRayCastEntityStruct rayCast);
+ var opt = GetCameraStruct(playerId);
+ if (!opt) return EGID.Empty;
+ CharacterCameraRayCastEntityStruct rayCast = opt;
float distance = maxDistance < 0
? GhostBlockUtils.GetBuildInteractionDistance(entitiesDB, rayCast,
GhostBlockUtils.GhostCastMethod.GhostCastProportionalToBlockSize)
diff --git a/TechbloxModdingAPI/TechbloxModdingAPI.csproj b/TechbloxModdingAPI/TechbloxModdingAPI.csproj
index 8af0a13..ca99746 100644
--- a/TechbloxModdingAPI/TechbloxModdingAPI.csproj
+++ b/TechbloxModdingAPI/TechbloxModdingAPI.csproj
@@ -8,6 +8,7 @@
https://git.exmods.org/modtainers/GamecraftModdingAPI
en-CA
true
+ 8