Magically import images and more into Gamecraft as blocks
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.

48 lines
1.4KB

  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text;
  6. using Unity.Mathematics;
  7. using GamecraftModdingAPI;
  8. using GamecraftModdingAPI.Blocks;
  9. using GamecraftModdingAPI.Commands;
  10. using GamecraftModdingAPI.Players;
  11. using GamecraftModdingAPI.Utility;
  12. using Pixi.Common;
  13. namespace Pixi.Robots
  14. {
  15. public static class RobotCommands
  16. {
  17. public static void CreatePartDumpCommand()
  18. {
  19. CommandBuilder.Builder()
  20. .Name("DumpVON")
  21. .Description("Dump a block structure to a JSON file compatible with Pixi's internal VON format")
  22. .Action<string>(DumpBlockStructure)
  23. .Build();
  24. }
  25. private static void DumpBlockStructure(string filename)
  26. {
  27. Player local = new Player(PlayerType.Local);
  28. Block baseBlock = local.GetBlockLookedAt();
  29. Block[] blocks = local.GetSelectedBlocks();
  30. if (blocks.Length == 0)
  31. blocks = baseBlock.GetConnectedCubes();
  32. bool isBaseScaled = !(baseBlock.Scale.x > 0 && baseBlock.Scale.x < 2 && baseBlock.Scale.y > 0 && baseBlock.Scale.y < 2 && baseBlock.Scale.z > 0 && baseBlock.Scale.z < 2);
  33. if (isBaseScaled)
  34. {
  35. Logging.CommandLogWarning($"Detected scaled base block. This is not currently supported");
  36. }
  37. float3 basePos = baseBlock.Position;
  38. string von = VoxelObjectNotationUtility.SerializeBlocks(blocks, new float[] { basePos.x, basePos.y, basePos.z });
  39. File.WriteAllText(filename, von);
  40. }
  41. }
  42. }