A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.2KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Unity.Mathematics;
  7. namespace GamecraftModdingAPI.Blocks
  8. {
  9. /// <summary>
  10. /// Common block movement operations.
  11. /// The functionality of this class only works in build mode.
  12. /// </summary>
  13. public static class Movement
  14. {
  15. private static MovementEngine movementEngine = new MovementEngine();
  16. /// <summary>
  17. /// Move a single block by a specific (x,y,z) amount (offset).
  18. /// The moved block will remain connected to the blocks it was touching before it was moved.
  19. /// The block's placement grid and collision box are also moved.
  20. /// </summary>
  21. /// <param name="id">The block's id</param>
  22. /// <param name="vector">The movement amount (x,y,z)</param>
  23. /// <returns>Whether the operation was successful</returns>
  24. public static bool MoveBlock(uint id, float3 vector)
  25. {
  26. if (movementEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsBuildMode())
  27. {
  28. movementEngine.MoveBlock(id, vector);
  29. return true;
  30. }
  31. return false;
  32. }
  33. /// <summary>
  34. /// Move all connected blocks by a specific (x,y,z) amount (offset).
  35. /// The moved blocks will remain connected to the block they're touching.
  36. /// All of the block's placement grids and collision boxes are also moved.
  37. /// This is equivalent to calling MoveBlock() for every connected block.
  38. /// </summary>
  39. /// <param name="id">The starting block's id</param>
  40. /// <param name="vector">The movement amount (x,y,z)</param>
  41. /// <returns>Whether the operation was successful</returns>
  42. public static bool MoveConnectedBlocks(uint id, float3 vector)
  43. {
  44. if (movementEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsBuildMode())
  45. {
  46. movementEngine.MoveConnectedBlocks(id, vector);
  47. return true;
  48. }
  49. return false;
  50. }
  51. public static void Init()
  52. {
  53. GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(movementEngine);
  54. }
  55. }
  56. }