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.

60 lines
2.4KB

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