diff --git a/GCMC/Blocks.cs b/GCMC/Blocks.cs new file mode 100644 index 0000000..b779e48 --- /dev/null +++ b/GCMC/Blocks.cs @@ -0,0 +1,11 @@ +using Unity.Mathematics; + +namespace GCMC +{ + public struct Blocks + { + public float3 Start { get; set; } + public float3 End { get; set; } + public string Material { get; set; } + } +} \ No newline at end of file diff --git a/GCMC/CubePlacerEngine.cs b/GCMC/CubePlacerEngine.cs index e5a6953..5a9cf0f 100644 --- a/GCMC/CubePlacerEngine.cs +++ b/GCMC/CubePlacerEngine.cs @@ -1,6 +1,8 @@ using System; +using System.IO; using DataLoader; using GamecraftModdingAPI.Blocks; +using Newtonsoft.Json; using RobocraftX.Blocks; using RobocraftX.Blocks.Ghost; using RobocraftX.Blocks.Scaling; @@ -31,6 +33,60 @@ namespace GCMC private void ImportWorld(string name) { + try + { + Log.Output("Starting..."); + var blocksArray = JsonSerializer.Create() + .Deserialize(new JsonTextReader(File.OpenText(name))); + int C = 0; + foreach (var blocks in blocksArray) + { + BlockIDs id; + BlockColors color; + byte darkness = 0; + switch (blocks.Material) + { + case "DIRT": + id = BlockIDs.DirtCube; + color = BlockColors.Default; + break; + case "GRASS": + id = BlockIDs.GrassCube; + color = BlockColors.Default; + break; + case "STONE": + id = BlockIDs.ConcreteCube; + color = BlockColors.White; + darkness = 5; + break; + case "LEAVES": + id = BlockIDs.AluminiumCube; + color = BlockColors.Green; + darkness = 5; + break; + case "AIR": + continue; + case "LOG": + id = BlockIDs.WoodCube; + color = BlockColors.Default; + break; + default: + Log.Output("Unknown block: " + blocks.Material); + continue; + } + + Placement.PlaceBlock(id, (blocks.Start + blocks.End) / 2, color: color, darkness: darkness, + scale: (blocks.End - blocks.Start + 1) * 5, rotation: quaternion.identity); + C++; + } + + Log.Output(C + " blocks placed."); + } + catch (Exception e) + { + Console.WriteLine(e); + Log.Error(e.Message); + } } private void PlaceBlock(string args) diff --git a/GCMC/GCMC.csproj b/GCMC/GCMC.csproj index 9a0dabb..9a4c82d 100644 --- a/GCMC/GCMC.csproj +++ b/GCMC/GCMC.csproj @@ -27,6 +27,9 @@ IllusionPlugin.dll + + ..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net48\Newtonsoft.Json.dll + ..\ref\RobocraftX.Blocks.dll diff --git a/GCMC/Location.cs b/GCMC/Location.cs new file mode 100644 index 0000000..6f9675f --- /dev/null +++ b/GCMC/Location.cs @@ -0,0 +1,9 @@ +namespace GCMC +{ + public struct Location + { + public int X { get; set; } + public int Y { get; set; } + public int Z { get; set; } + } +} \ No newline at end of file