NorbiPeti
f403feb298
Removed BlockIdentifiers.OWNED_BLOCKS as the original got replaced with an array Added the correct group for each supported functional block Removed EntityFactory property from IEntitySerializer as it is provided on deserialization
111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
using System;
|
|
|
|
using RobocraftX.Blocks;
|
|
using RobocraftX.Common;
|
|
using Svelto.ECS;
|
|
using Unity.Mathematics;
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
public class Servo : Block
|
|
{
|
|
/// <summary>
|
|
/// Places a new servo.
|
|
/// Any valid servo type is accepted.
|
|
/// This re-implements Block.PlaceNew(...)
|
|
/// </summary>
|
|
public static new Servo PlaceNew(BlockIDs block, float3 position,
|
|
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
|
|
int uscale = 1, float3 scale = default, Player player = null)
|
|
{
|
|
if (!(block == BlockIDs.ServoAxle || block == BlockIDs.ServoHinge || block == BlockIDs.ServoPiston))
|
|
{
|
|
throw new BlockTypeException($"Block is not a {nameof(Servo)} block");
|
|
}
|
|
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
|
|
{
|
|
EGID id = PlacementEngine.PlaceBlock(block, color, darkness,
|
|
position, uscale, scale, player, rotation);
|
|
return new Servo(id);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public Servo(EGID id) : base(id)
|
|
{
|
|
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
|
|
{
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
}
|
|
}
|
|
|
|
public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP))
|
|
{
|
|
if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
|
|
{
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
}
|
|
}
|
|
|
|
// custom servo properties
|
|
|
|
/// <summary>
|
|
/// The servo's minimum angle.
|
|
/// </summary>
|
|
public float MinimumAngle
|
|
{
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).minDeviation;
|
|
|
|
set
|
|
{
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
servo.minDeviation = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The servo's maximum angle.
|
|
/// </summary>
|
|
public float MaximumAngle
|
|
{
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxDeviation;
|
|
|
|
set
|
|
{
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
servo.maxDeviation = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The servo's maximum force.
|
|
/// </summary>
|
|
public float MaximumForce
|
|
{
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).maxForce;
|
|
|
|
set
|
|
{
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
servo.maxForce = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The servo's direction.
|
|
/// </summary>
|
|
public bool Reverse
|
|
{
|
|
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id).reverse;
|
|
|
|
set
|
|
{
|
|
ref ServoReadOnlyStruct servo = ref BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(Id);
|
|
servo.reverse = value;
|
|
}
|
|
}
|
|
}
|
|
}
|