NorbiPeti
9609187cff
Removed GameState methods from block APIs Created a BlockUtility class to get the block the player is looking at Changed the return type of PlaceBlock, returning the ID of the newly placed block or null
55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
using System;
|
|
|
|
using Unity.Mathematics;
|
|
using Svelto.ECS;
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
{
|
|
/// <summary>
|
|
/// Common block placement operations.
|
|
/// The functionality in this class is for build mode.
|
|
/// </summary>
|
|
public static class Placement
|
|
{
|
|
private static PlacementEngine placementEngine = new PlacementEngine();
|
|
|
|
/// <summary>
|
|
/// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
|
|
/// Place blocks next to each other to connect them.
|
|
/// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
|
|
/// </summary>
|
|
/// <param name="block">The block's type</param>
|
|
/// <param name="color">The block's color</param>
|
|
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
|
|
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
|
|
/// <param name="rotation">The block's rotation in degrees</param>
|
|
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
|
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
|
/// <param name="playerId">The player who placed the block</param>
|
|
/// <returns>The placed block's ID or null if failed</returns>
|
|
public static EGID? PlaceBlock(BlockIDs block, float3 position,
|
|
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
|
|
int uscale = 1, float3 scale = default, uint playerId = 0)
|
|
{
|
|
if (placementEngine.IsInGame && GameState.IsBuildMode())
|
|
{
|
|
try
|
|
{
|
|
return placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logging.MetaDebugLog(e);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void Init()
|
|
{
|
|
GameEngineManager.AddGameEngine(placementEngine);
|
|
}
|
|
}
|
|
}
|