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.

56 lines
2.3KB

  1. using System;
  2. using Unity.Mathematics;
  3. using Svelto.ECS;
  4. using GamecraftModdingAPI.Utility;
  5. namespace GamecraftModdingAPI.Blocks
  6. {
  7. /// <summary>
  8. /// Common block placement operations.
  9. /// The functionality in this class is for build mode.
  10. /// </summary>
  11. public static class Placement
  12. {
  13. private static PlacementEngine placementEngine = new PlacementEngine();
  14. /// <summary>
  15. /// 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.
  16. /// Place blocks next to each other to connect them.
  17. /// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
  18. /// </summary>
  19. /// <param name="block">The block's type</param>
  20. /// <param name="color">The block's color</param>
  21. /// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
  22. /// <param name="position">The block's position in the grid - default block size is 0.2</param>
  23. /// <param name="rotation">The block's rotation in degrees</param>
  24. /// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
  25. /// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
  26. /// <param name="playerId">The player who placed the block</param>
  27. /// <returns>The placed block's ID or null if failed</returns>
  28. public static EGID? PlaceBlock(BlockIDs block, float3 position,
  29. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  30. int uscale = 1, float3 scale = default, uint playerId = 0)
  31. {
  32. if (placementEngine.IsInGame && GameState.IsBuildMode())
  33. {
  34. try
  35. {
  36. return placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation);
  37. }
  38. catch (Exception e)
  39. {
  40. Logging.MetaDebugLog(e);
  41. }
  42. }
  43. return null;
  44. }
  45. public static void Init()
  46. {
  47. GameEngineManager.AddGameEngine(placementEngine);
  48. }
  49. }
  50. }