Make blocks static via a workaround of constant positioning

This commit is contained in:
Norbi Peti 2021-06-08 01:03:23 +02:00
parent 415012d425
commit d57bf0513a
3 changed files with 55 additions and 13 deletions

View file

@ -83,5 +83,9 @@
<!- the ILMergePath property points to the location of ILMerge.exe console application -> <!- the ILMergePath property points to the location of ILMerge.exe console application ->
<Exec Command="$(ILMergeConsolePath) /ndebug /out:bin\Debug\net472\GCMC.dll bin\$(Configuration)\net472\GCMC.dll bin\$(Configuration)\net472\INIFileParser.dll" /> <Exec Command="$(ILMergeConsolePath) /ndebug /out:bin\Debug\net472\GCMC.dll bin\$(Configuration)\net472\GCMC.dll bin\$(Configuration)\net472\INIFileParser.dll" />
</Target> --> </Target> -->
<Target Name="CopyToPlugins" AfterTargets="AfterBuild">
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(OutputPath)\GCMC.dll" DestinationFolder="$(MSBuildProjectDirectory)\..\..\ref\Plugins" />
</Target>
</Project> </Project>

View file

@ -6,12 +6,14 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using IllusionPlugin; using IllusionPlugin;
using Newtonsoft.Json; using Newtonsoft.Json;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean; using Svelto.Tasks.ExtraLean;
using TechbloxModdingAPI; using TechbloxModdingAPI;
using TechbloxModdingAPI.App; using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Blocks; using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Commands; using TechbloxModdingAPI.Commands;
using TechbloxModdingAPI.Tasks; using TechbloxModdingAPI.Tasks;
using TechbloxModdingAPI.Utility;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine; using UnityEngine;
using uREPL; using uREPL;
@ -23,9 +25,10 @@ namespace GCMC
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
private readonly Dictionary<string, BlockType> mapping = new Dictionary<string, BlockType>(10); private readonly Dictionary<string, BlockType> _mapping = new Dictionary<string, BlockType>(10);
private JsonSerializer _serializer = JsonSerializer.Create(); private readonly List<(Block, SimBody, float3)> _simulationBlocks = new List<(Block, SimBody, float3)>();
private JsonTraceWriter _traceWriter = new JsonTraceWriter(); private readonly JsonSerializer _serializer = JsonSerializer.Create();
private readonly JsonTraceWriter _traceWriter = new JsonTraceWriter();
private async void ImportWorld(string name) private async void ImportWorld(string name)
{ {
@ -34,7 +37,7 @@ namespace GCMC
Log.Output("Reading block mappings..."); Log.Output("Reading block mappings...");
var parser = new IniParser.FileIniDataParser(); var parser = new IniParser.FileIniDataParser();
var ini = parser.ReadFile("BlockTypes.ini"); var ini = parser.ReadFile("BlockTypes.ini");
mapping.Clear(); _mapping.Clear();
foreach (var section in ini.Sections) foreach (var section in ini.Sections)
{ {
var mcblocks = section.SectionName.Split(','); var mcblocks = section.SectionName.Split(',');
@ -76,7 +79,7 @@ namespace GCMC
foreach (var mcblock in mcblocks) foreach (var mcblock in mcblocks)
{ {
mapping.Add(mcblock.ToUpper(), new BlockType _mapping.Add(mcblock.ToUpper(), new BlockType
{ {
Material = mcblock.ToUpper(), Material = mcblock.ToUpper(),
Type = type, Type = type,
@ -98,7 +101,7 @@ namespace GCMC
for (i = 0; i < blocksArray.Length; i++) for (i = 0; i < blocksArray.Length; i++)
{ {
var blocks = blocksArray[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); Console.WriteLine("Unknown block: " + blocks.Material);
continue; continue;
@ -109,9 +112,12 @@ namespace GCMC
var block = new Block(type.Type, (blocks.Start + blocks.End) / 10 * 3 + new float3(5000, 0, 5000)) var block = new Block(type.Type, (blocks.Start + blocks.End) / 10 * 3 + new float3(5000, 0, 5000))
{ {
Color = type.Color, 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."); 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() public override void OnApplicationStart()
{ {
TechbloxModdingAPI.Main.Init(); TechbloxModdingAPI.Main.Init();

View file

@ -1,18 +1,18 @@
# GCMC # TBMC
Minecraft world importer for Gamecraft. Minecraft world importer for Techblox.
## Usage ## 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. 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 <x1> <y1> <z1> <x2> <y2> <z2>` on the server with the starting and ending coordinates of the area you want to export. Then run `/export <x1> <y1> <z1> <x2> <y2> <z2>` 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. After that, copy the `result.json` from the server folder into Techblox'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. 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. 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. 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... I have big plans for this project. One day...