Create cube placer engine
I thought I committed this yesterday
This commit is contained in:
parent
93b272f791
commit
a122b38bf9
5 changed files with 252 additions and 0 deletions
104
GCMC/CubePlacerEngine.cs
Normal file
104
GCMC/CubePlacerEngine.cs
Normal file
|
@ -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<string>("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; }
|
||||
}
|
||||
}
|
|
@ -8,4 +8,58 @@
|
|||
<PackageReference Include="fNbt" Version="0.6.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>bin\Debug\netstandard2.0\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="BlockEntityFactory, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\BlockEntityFactory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="CommandLine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\CommandLine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DataLoader, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\DataLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>IllusionPlugin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Blocks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.Blocks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Character, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.Character.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.Input, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.Input.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.MachineEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.MachineEditor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RobocraftX.StateSync, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\RobocraftX.StateSync.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Svelto.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\Svelto.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Svelto.ECS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\Svelto.ECS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\Unity.Entities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Mathematics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\Unity.Mathematics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="uREPL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\ref\uREPL.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
47
GCMC/GCMCPlugin.cs
Normal file
47
GCMC/GCMCPlugin.cs
Normal file
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
BIN
GCMC/IllusionPlugin.dll
Normal file
BIN
GCMC/IllusionPlugin.dll
Normal file
Binary file not shown.
47
GCMC/PlaceBlockPatch.cs
Normal file
47
GCMC/PlaceBlockPatch.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue