2020-01-03 00:14:26 +00:00
|
|
|
|
using System;
|
2020-01-04 00:54:35 +00:00
|
|
|
|
|
2020-01-03 00:14:26 +00:00
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
2020-01-04 00:54:35 +00:00
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
2020-01-03 00:14:26 +00:00
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-01-04 00:54:35 +00:00
|
|
|
|
/// Common block placement operations
|
2020-01-03 00:14:26 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static class Placement
|
|
|
|
|
{
|
|
|
|
|
private static PlacementEngine placementEngine = new PlacementEngine();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Place a 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.
|
|
|
|
|
/// </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>
|
2020-01-15 19:41:50 +00:00
|
|
|
|
/// <param name="rotation">The block's rotation in degrees</param>
|
2020-01-03 00:14:26 +00:00
|
|
|
|
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
2020-01-03 13:38:59 +00:00
|
|
|
|
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
2020-01-03 00:14:26 +00:00
|
|
|
|
/// <param name="playerId">The player who placed the block</param>
|
2020-01-04 00:54:35 +00:00
|
|
|
|
/// <returns>Whether the operation was successful</returns>
|
2020-01-03 13:38:59 +00:00
|
|
|
|
public static bool PlaceBlock(BlockIDs block, float3 position,
|
2020-01-15 19:41:50 +00:00
|
|
|
|
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
|
|
|
|
|
int uscale = 1, float3 scale = default, uint playerId = 0)
|
2020-01-03 00:14:26 +00:00
|
|
|
|
{
|
|
|
|
|
if (placementEngine.IsInGame && GameState.IsBuildMode())
|
|
|
|
|
{
|
2020-01-04 00:54:35 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Logging.LogException(e);
|
|
|
|
|
#endif
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-01-03 00:14:26 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
GameEngineManager.AddGameEngine(placementEngine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|