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.

57 lines
2.2KB

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