From a122b38bf9f72f4c9cf90728bbe3e5a37ed243a6 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 2 Jan 2020 19:43:36 +0100 Subject: [PATCH] Create cube placer engine I thought I committed this yesterday --- GCMC/CubePlacerEngine.cs | 104 +++++++++++++++++++++++++++++++++++++++ GCMC/GCMC.csproj | 54 ++++++++++++++++++++ GCMC/GCMCPlugin.cs | 47 ++++++++++++++++++ GCMC/IllusionPlugin.dll | Bin 0 -> 6656 bytes GCMC/PlaceBlockPatch.cs | 47 ++++++++++++++++++ 5 files changed, 252 insertions(+) create mode 100644 GCMC/CubePlacerEngine.cs create mode 100644 GCMC/GCMCPlugin.cs create mode 100644 GCMC/IllusionPlugin.dll create mode 100644 GCMC/PlaceBlockPatch.cs diff --git a/GCMC/CubePlacerEngine.cs b/GCMC/CubePlacerEngine.cs new file mode 100644 index 0000000..e57190a --- /dev/null +++ b/GCMC/CubePlacerEngine.cs @@ -0,0 +1,104 @@ +using System; +using DataLoader; +using RobocraftX.Blocks; +using RobocraftX.Blocks.Ghost; +using RobocraftX.Blocks.Scaling; +using RobocraftX.Character; +using RobocraftX.CommandLine.Custom; +using RobocraftX.Common; +using RobocraftX.Common.Input; +using RobocraftX.Common.Utilities; +using RobocraftX.CR.MachineEditing; +using RobocraftX.StateSync; +using Svelto.ECS; +using Svelto.ECS.EntityStructs; +using Unity.Jobs; +using Unity.Mathematics; +using uREPL; + +namespace GCMC +{ + public class CubePlacerEngine : IQueryingEntitiesEngine, IDeterministicSim + { + public void Ready() + { + RuntimeCommands.Register("importWorld", ImportWorld, "Imports a Minecraft world."); + } + + public IEntitiesDB entitiesDB { get; set; } + private readonly BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine - TODO + + private void ImportWorld(string name) + { + PlaceBlock(1, 1, 0); + } + + private void PlaceBlock(ushort block, byte color, uint playerId) + { + BuildBlock(block, color).Init(new BlockPlacementInfoStruct() + { + loadedFromDisk = false, + placedBy = playerId + }); + } + + private EntityStructInitializer BuildBlock(ushort block, byte color) + { + //RobocraftX.CR.MachineEditing.PlaceBlockEngine + ScalingEntityStruct scaling = new ScalingEntityStruct {scale = new float3(1, 1, 1)}; + RotationEntityStruct rotation = new RotationEntityStruct {rotation = quaternion.identity}; + GridRotationStruct gridRotation = new GridRotationStruct + {position = float3.zero, rotation = quaternion.identity}; + CubeCategoryStruct category = new CubeCategoryStruct + {category = CubeCategory.General, type = CubeType.Block}; + uint dbid = block; + DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid}; + uint num = PrefabsID.DBIDMAP[dbid]; + GFXPrefabEntityStructGO gfx = new GFXPrefabEntityStructGO {prefabID = num}; + BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct + { + blockPlacementHeight = 1, blockPlacementWidth = 1, desiredScaleFactor = 1, snapGridScale = 1, + unitSnapOffset = 0, isUsingUnitSize = true + }; + EquippedColourStruct colour = new EquippedColourStruct {indexInPalette = color}; + EGID egid2; + switch (category.category) + { + case CubeCategory.SpawnPoint: + case CubeCategory.BuildingSpawnPoint: + egid2 = MachineEditingGroups.NewSpawnPointBlockID; + break; + default: + egid2 = MachineEditingGroups.NewBlockID; + break; + } + + int cubeId = PrefabsID.GenerateDBID((ushort) category.category, block); + EntityStructInitializer structInitializer = _blockEntityFactory.Build(egid2, (uint) cubeId); //The ghost block index is only used for triggers + if (colour.indexInPalette != byte.MaxValue) + structInitializer.Init(new ColourParameterEntityStruct + { + indexInPalette = colour.indexInPalette + }); + structInitializer.Init(new GFXPrefabEntityStructGPUI(gfx.prefabID)); + structInitializer.Init(new PhysicsPrefabEntityStruct(gfx.prefabID)); + structInitializer.Init(dbEntity); + structInitializer.Init(new PositionEntityStruct {position = 0}); + structInitializer.Init(rotation); + structInitializer.Init(scaling); + structInitializer.Init(gridRotation); + structInitializer.Init(new UniformBlockScaleEntityStruct + { + scaleFactor = placementScale.desiredScaleFactor + }); + return structInitializer; + } + + public JobHandle SimulatePhysicsStep(in float deltaTime, in PhysicsUtility utility, in PlayerInput[] playerInputs) + { + return new JobHandle(); + } + + public string name { get; } + } +} \ No newline at end of file diff --git a/GCMC/GCMC.csproj b/GCMC/GCMC.csproj index 0d6279c..2f13d0f 100644 --- a/GCMC/GCMC.csproj +++ b/GCMC/GCMC.csproj @@ -8,4 +8,58 @@ + + + bin\Debug\netstandard2.0\0Harmony.dll + + + ..\ref\BlockEntityFactory.dll + + + ..\ref\CommandLine.dll + + + ..\ref\DataLoader.dll + + + IllusionPlugin.dll + + + ..\ref\RobocraftX.Blocks.dll + + + ..\ref\RobocraftX.Character.dll + + + ..\ref\RobocraftX.Common.dll + + + ..\ref\RobocraftX.Input.dll + + + ..\ref\RobocraftX.MachineEditor.dll + + + ..\ref\RobocraftX.StateSync.dll + + + ..\ref\Svelto.Common.dll + + + ..\ref\Svelto.ECS.dll + + + ..\ref\Unity.Entities.dll + + + ..\ref\Unity.Mathematics.dll + + + ..\ref\UnityEngine.CoreModule.dll + + + ..\ref\uREPL.dll + + + diff --git a/GCMC/GCMCPlugin.cs b/GCMC/GCMCPlugin.cs new file mode 100644 index 0000000..e748ca2 --- /dev/null +++ b/GCMC/GCMCPlugin.cs @@ -0,0 +1,47 @@ +using System.Reflection; +using Harmony; +using IllusionPlugin; +using UnityEngine; + +namespace GCMC +{ + public class GCMCPlugin : IPlugin + { + public string Name { get; } = "GCMC"; + public string Version { get; } = "v0.0.1"; + public static HarmonyInstance harmony { get; protected set; } + public const string HarmonyID = "io.github.norbipeti.GCMC"; + + public void OnApplicationStart() + { + if (harmony == null) + { + harmony = HarmonyInstance.Create(HarmonyID); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + } + + Debug.Log("GCMC loaded"); + } + + public void OnApplicationQuit() + { + harmony?.UnpatchAll(HarmonyID); + } + + public void OnLevelWasLoaded(int level) + { + } + + public void OnLevelWasInitialized(int level) + { + } + + public void OnUpdate() + { + } + + public void OnFixedUpdate() + { + } + } +} \ No newline at end of file diff --git a/GCMC/IllusionPlugin.dll b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ZZ__qS#nP}!5o)@-CfZXHZwOj3@2Oij$W&R0DNdJW=kYLh6r{7m8XN=Vk>&2h03X|Fz`X}#S&_)U3(M4OEr z1w-Glv)FZ0p?9{ce|zuFuATk)zOLE6ZQEwI7xO(k4QM9dqzAum@W;!-t@d4oZ^3Ke z=6$^8y^r70_4@K49jc#}ks_%v{0d7#0sIV9BzKI`$fquU1X9Sa#E^AtoPMT<=PkvGkzO>Be`J;IE(Z z;v37=7%9;(?3M9{TN_ry#{yX2R41zl{|lI{F7!g@@U$9Qwa7ED;88)uQCSve7Li+2 zg*1qLOi(2eFWc%y=~=Qf1v~DdF3WpR%exmJg2y)K^Gf+b*G61cU36FSm&P5z(Qw;~ z_iuawfQ^!{z$;O~?+RYY63xLn>c|S7hF>Wf{(2EpkN8%$1y<_q1UpuQ-7@UD_$5(W zRYH^;`@zr$?-<8kTSKOJCkV6q_%*Aa!>wWu#$buUm;L+u=3n7i+(K{G~f^ x>H6;wV+JuRzJtriCJU>kA(NNy+@<5#->24asQJ6tTwTrk)O`Kl@MmrX{sWhp^B({J literal 0 HcmV?d00001 diff --git a/GCMC/PlaceBlockPatch.cs b/GCMC/PlaceBlockPatch.cs new file mode 100644 index 0000000..a4848ca --- /dev/null +++ b/GCMC/PlaceBlockPatch.cs @@ -0,0 +1,47 @@ +using System.Reflection; +using DataLoader; +using Harmony; +using RobocraftX.Blocks.GUI; +using RobocraftX.Common; +using RobocraftX.CR.MachineEditing; +using RobocraftX.StateSync; +using Svelto.ECS; +using Unity.Entities; +using UnityEngine; + +namespace GCMC +{ + [HarmonyPatch] + public class PlaceBlockPatch + { + static void Postfix(EnginesRoot enginesRoot, ref StateSyncRegistrationHelper stateSyncReg, bool isAuthoritative) + { + if (isAuthoritative) + { + stateSyncReg.AddEngine(new CubePlacerEngine()); + Debug.Log($"Added Minecraft world import engine"); + } + else + Debug.Log("Not authoritative, not adding MC engine"); + } + + static MethodBase TargetMethod(HarmonyInstance instance) + { + return _ComposeMethodInfo(MachineEditingCompositionRoot.StateSyncCompose); + } + + private delegate void ComposeAction(EnginesRoot enginesRoot, + IDataDB dataDB, + RCXMode currentMode, + World physicsWorld, + ref StateSyncRegistrationHelper stateSyncReg, + bool isAuthoritative, + LabelResourceManager labelResourceManager, + LabelResourceManager textBlockLabelResourceManager, + MainGameOptions.Options mainGameOptions); + private static MethodInfo _ComposeMethodInfo(ComposeAction a) + { + return a.Method; + } + } +} \ No newline at end of file