Browse Source

It works! It places a pink axle

tags/v1.0.0
NorbiPeti 5 years ago
parent
commit
ac75bdd371
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
3 changed files with 49 additions and 6 deletions
  1. +16
    -6
      GCMC/CubePlacerEngine.cs
  2. +31
    -0
      GCMC/FactoryObtainerPatch.cs
  3. +2
    -0
      GCMC/PlaceBlockPatch.cs

+ 16
- 6
GCMC/CubePlacerEngine.cs View File

@@ -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";
}
}

+ 31
- 0
GCMC/FactoryObtainerPatch.cs View File

@@ -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];
}
}
}

+ 2
- 0
GCMC/PlaceBlockPatch.cs View File

@@ -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)


Loading…
Cancel
Save