From d57bf0513aabcd88118ed64b2c84a3532dd42496 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 8 Jun 2021 01:03:23 +0200 Subject: [PATCH] Make blocks static via a workaround of constant positioning --- GCMC/GCMC.csproj | 4 ++++ GCMC/GCMCPlugin.cs | 52 +++++++++++++++++++++++++++++++++++++++------- README.md | 12 +++++------ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/GCMC/GCMC.csproj b/GCMC/GCMC.csproj index d5704aa..39895fa 100644 --- a/GCMC/GCMC.csproj +++ b/GCMC/GCMC.csproj @@ -83,5 +83,9 @@ --> + + + + diff --git a/GCMC/GCMCPlugin.cs b/GCMC/GCMCPlugin.cs index e85176b..b017568 100644 --- a/GCMC/GCMCPlugin.cs +++ b/GCMC/GCMCPlugin.cs @@ -6,12 +6,14 @@ using System.Reflection; using System.Threading.Tasks; using IllusionPlugin; using Newtonsoft.Json; +using Svelto.Tasks; using Svelto.Tasks.ExtraLean; using TechbloxModdingAPI; using TechbloxModdingAPI.App; using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Commands; using TechbloxModdingAPI.Tasks; +using TechbloxModdingAPI.Utility; using Unity.Mathematics; using UnityEngine; using uREPL; @@ -23,9 +25,10 @@ namespace GCMC public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - private readonly Dictionary mapping = new Dictionary(10); - private JsonSerializer _serializer = JsonSerializer.Create(); - private JsonTraceWriter _traceWriter = new JsonTraceWriter(); + private readonly Dictionary _mapping = new Dictionary(10); + private readonly List<(Block, SimBody, float3)> _simulationBlocks = new List<(Block, SimBody, float3)>(); + private readonly JsonSerializer _serializer = JsonSerializer.Create(); + private readonly JsonTraceWriter _traceWriter = new JsonTraceWriter(); private async void ImportWorld(string name) { @@ -34,7 +37,7 @@ namespace GCMC Log.Output("Reading block mappings..."); var parser = new IniParser.FileIniDataParser(); var ini = parser.ReadFile("BlockTypes.ini"); - mapping.Clear(); + _mapping.Clear(); foreach (var section in ini.Sections) { var mcblocks = section.SectionName.Split(','); @@ -76,7 +79,7 @@ namespace GCMC foreach (var mcblock in mcblocks) { - mapping.Add(mcblock.ToUpper(), new BlockType + _mapping.Add(mcblock.ToUpper(), new BlockType { Material = mcblock.ToUpper(), Type = type, @@ -98,7 +101,7 @@ namespace GCMC for (i = 0; i < blocksArray.Length; i++) { var blocks = blocksArray[i]; - if (!mapping.TryGetValue(blocks.Material, out var type)) + if (!_mapping.TryGetValue(blocks.Material, out var type)) { Console.WriteLine("Unknown block: " + blocks.Material); continue; @@ -109,9 +112,12 @@ namespace GCMC var block = new Block(type.Type, (blocks.Start + blocks.End) / 10 * 3 + new float3(5000, 0, 5000)) { Color = type.Color, - Scale = (blocks.End - blocks.Start + 1) * 3 + Scale = (blocks.End - blocks.Start + 1) * 3, + //Static = true - Doesn't seem to work }; + _simulationBlocks.Add((block, null, default)); } + Game.Simulate += GameOnSimulate; Log.Output(i + " blocks placed."); } @@ -122,6 +128,38 @@ namespace GCMC } } + private void GameOnSimulate(object sender, GameEventArgs e) + { + Game.Simulate -= GameOnSimulate; + GameWhileSimulating().RunOn(Scheduler.extraLeanRunner); + } + + private IEnumerator GameWhileSimulating() + { + while (!GameState.IsSimulationMode()) + yield return Yield.It; + + for (var i = 0; i < _simulationBlocks.Count; i++) + { + var (block, body, _) = _simulationBlocks[i]; + if (body is null) body = block.GetSimBody(); + _simulationBlocks[i] = (block, body, body.Position); + } + + while (GameState.IsSimulationMode()) + { + foreach (var (_, body, pos) in _simulationBlocks) + { + body.Velocity = 0; + body.AngularVelocity = 0; + body.Position = pos; + body.Rotation = float3.zero; + } + + yield return Yield.It; + } + } + public override void OnApplicationStart() { TechbloxModdingAPI.Main.Init(); diff --git a/README.md b/README.md index 3ccb5cd..496f0f4 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ -# GCMC +# TBMC -Minecraft world importer for Gamecraft. +Minecraft world importer for Techblox. ## Usage You'll need a Bukkit/Spigot/Paper server first. Download the Bukkit plugin from [releases](https://git.exmods.org/NorbiPeti/GCMC/releases) and put it in the server's plugins directory. Then run `/export ` on the server with the starting and ending coordinates of the area you want to export. -Make sure to not select a large area as it can make Gamecraft lag. +Make sure to not select a large area as it can make Techblox lag. -After that, copy the `result.json` from the server folder into Gamecraft's folder. -Then, using the Gamecraft mod, do `importWorld "result.json"` in the GC console (opened by pressing the button near right shift by default) to import the Minecraft blocks. +After that, copy the `result.json` from the server folder into Techblox's folder. +Then, using the Techblox mod, do `importWorld "result.json"` in the GC console (opened by pressing the button near right shift by default) to import the Minecraft blocks. It can take a while to load the file and place the blocks, depending on how many are there to place. -Open the game log (and scroll to the end) to see the blocks that the mod doesn't know how to place in GC. You can add block mappings to the BlockTypes.ini file in Gamecraft's folder following the format (Minecraft block goes in brackets, the rest are Gamecraft block settings, color darkness goes 0-9). +Open the game log (and scroll to the end) to see the blocks that the mod doesn't know how to place in GC. You can add block mappings to the BlockTypes.ini file in Techblox's folder following the format (Minecraft block goes in brackets, the rest are Techblox block settings, color darkness goes 0-9). If you're up to contributing to this mod, please send this file to me (NorbiPeti) after adding more block types. I have big plans for this project. One day...