From ac75bdd371a69ebe6fdbb1f1608108354eb0422e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 2 Jan 2020 20:28:17 +0100 Subject: [PATCH] It works! It places a pink axle --- GCMC/CubePlacerEngine.cs | 22 ++++++++++++++++------ GCMC/FactoryObtainerPatch.cs | 31 +++++++++++++++++++++++++++++++ GCMC/PlaceBlockPatch.cs | 2 ++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 GCMC/FactoryObtainerPatch.cs diff --git a/GCMC/CubePlacerEngine.cs b/GCMC/CubePlacerEngine.cs index e57190a..0a2d387 100644 --- a/GCMC/CubePlacerEngine.cs +++ b/GCMC/CubePlacerEngine.cs @@ -26,7 +26,7 @@ namespace GCMC } public IEntitiesDB entitiesDB { get; set; } - private readonly BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine - TODO + internal static BlockEntityFactory _blockEntityFactory; //Injected from PlaceBlockEngine private void ImportWorld(string name) { @@ -35,15 +35,25 @@ namespace GCMC private void PlaceBlock(ushort block, byte color, uint playerId) { - BuildBlock(block, color).Init(new BlockPlacementInfoStruct() + try { - loadedFromDisk = false, - placedBy = playerId - }); + BuildBlock(block, color).Init(new BlockPlacementInfoStruct() + { + loadedFromDisk = false, + placedBy = playerId + }); + } + catch (Exception e) + { + Console.WriteLine(e); + Log.Error(e.Message); + } } private EntityStructInitializer BuildBlock(ushort block, byte color) { + if (_blockEntityFactory == null) + throw new Exception("The factory is null."); //RobocraftX.CR.MachineEditing.PlaceBlockEngine ScalingEntityStruct scaling = new ScalingEntityStruct {scale = new float3(1, 1, 1)}; RotationEntityStruct rotation = new RotationEntityStruct {rotation = quaternion.identity}; @@ -99,6 +109,6 @@ namespace GCMC return new JobHandle(); } - public string name { get; } + public string name { get; } = "Cube placer engine"; } } \ No newline at end of file diff --git a/GCMC/FactoryObtainerPatch.cs b/GCMC/FactoryObtainerPatch.cs new file mode 100644 index 0000000..aec6b75 --- /dev/null +++ b/GCMC/FactoryObtainerPatch.cs @@ -0,0 +1,31 @@ +using System.Reflection; +using DataLoader; +using Harmony; +using JetBrains.Annotations; +using RobocraftX.Blocks; +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] + [UsedImplicitly] + public class FactoryObtainerPatch + { + static void Postfix(BlockEntityFactory blockEntityFactory) + { + CubePlacerEngine._blockEntityFactory = blockEntityFactory; + Debug.Log("Block entity factory injected."); + } + + static MethodBase TargetMethod(HarmonyInstance instance) + { + return typeof(PlaceBlockEngine).GetConstructors()[0]; + } + } +} \ No newline at end of file diff --git a/GCMC/PlaceBlockPatch.cs b/GCMC/PlaceBlockPatch.cs index a4848ca..34df92f 100644 --- a/GCMC/PlaceBlockPatch.cs +++ b/GCMC/PlaceBlockPatch.cs @@ -1,6 +1,7 @@ using System.Reflection; using DataLoader; using Harmony; +using JetBrains.Annotations; using RobocraftX.Blocks.GUI; using RobocraftX.Common; using RobocraftX.CR.MachineEditing; @@ -12,6 +13,7 @@ using UnityEngine; namespace GCMC { [HarmonyPatch] + [UsedImplicitly] public class PlaceBlockPatch { static void Postfix(EnginesRoot enginesRoot, ref StateSyncRegistrationHelper stateSyncReg, bool isAuthoritative)