TechbloxModdingAPI/GamecraftModdingAPI/Blocks/Movement.cs

62 lines
2.2 KiB
C#
Raw Normal View History

2019-12-17 01:55:52 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.Mathematics;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
2020-02-25 23:05:13 +00:00
/// Common block movement operations.
/// The functionality of this class only works in build mode.
2019-12-17 01:55:52 +00:00
/// </summary>
public static class Movement
{
private static MovementEngine movementEngine = new MovementEngine();
/// <summary>
2020-02-25 23:05:13 +00:00
/// Move a single block by a specific (x,y,z) amount (offset).
/// The moved block will remain connected to the blocks it was touching before it was moved.
/// The block's placement grid and collision box are also moved.
2019-12-17 01:55:52 +00:00
/// </summary>
/// <param name="id">The block's id</param>
/// <param name="vector">The movement amount (x,y,z)</param>
2020-01-04 00:54:35 +00:00
/// <returns>Whether the operation was successful</returns>
2019-12-17 01:55:52 +00:00
public static bool MoveBlock(uint id, float3 vector)
{
if (movementEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsBuildMode())
2019-12-17 01:55:52 +00:00
{
movementEngine.MoveBlock(id, vector);
return true;
}
return false;
}
/// <summary>
2020-02-25 23:05:13 +00:00
/// Move all connected blocks by a specific (x,y,z) amount (offset).
/// The moved blocks will remain connected to the block they're touching.
/// All of the block's placement grids and collision boxes are also moved.
/// This is equivalent to calling MoveBlock() for every connected block.
2019-12-17 01:55:52 +00:00
/// </summary>
/// <param name="id">The starting block's id</param>
/// <param name="vector">The movement amount (x,y,z)</param>
2020-01-04 00:54:35 +00:00
/// <returns>Whether the operation was successful</returns>
2019-12-17 01:55:52 +00:00
public static bool MoveConnectedBlocks(uint id, float3 vector)
{
if (movementEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsBuildMode())
2019-12-17 01:55:52 +00:00
{
movementEngine.MoveConnectedBlocks(id, vector);
return true;
}
return false;
}
public static void Init()
{
GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(movementEngine);
}
}
}