|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Reflection;
-
- using HarmonyLib;
- using RobocraftX.Blocks;
- using RobocraftX.Common;
- using Svelto.ECS;
-
- using GamecraftModdingAPI.Utility;
- using GamecraftModdingAPI.Engines;
-
- namespace GamecraftModdingAPI.Blocks
- {
- public class RemovalEngine : IApiEngine
- {
- private static IEntityFunctions _entityFunctions;
- private static MachineGraphConnectionEntityFactory _connectionFactory;
-
- public bool RemoveBlock(EGID target)
- {
- if (!entitiesDB.Exists<MachineGraphConnectionsEntityStruct>(target))
- return false;
- var connections = entitiesDB.QueryEntity<MachineGraphConnectionsEntityStruct>(target);
- for (int i = connections.connections.Length - 1; i >= 0; i--)
- _connectionFactory.RemoveConnection(connections, i, entitiesDB);
- _entityFunctions.RemoveEntity<BlockEntityDescriptor>(target);
- return true;
- }
-
- public void Ready()
- {
- /*CommandManager.AddCommand(new SimpleCustomCommandEngine(() =>
- {
- var block = BlockUtility.GetBlockLookedAt(LocalPlayerIDUtility.GetLocalPlayerID(entitiesDB), entitiesDB);
- if (block.HasValue)
- {
- RemoveBlock(block.Value);
- Log.Output("Removed block.");
- }
- else
- Log.Output("No block found where you're looking at.");
- }, "removeCube", "Removes the cube you're looking at."));*/
- }
-
- public EntitiesDB entitiesDB { get; set; }
-
- public void Dispose()
- {
- }
-
- public string Name { get; } = "GamecraftModdingAPIRemovalGameEngine";
-
- public bool isRemovable => false;
-
- [HarmonyPatch]
- public class FactoryObtainerPatch
- {
- static void Postfix(IEntityFunctions entityFunctions,
- MachineGraphConnectionEntityFactory machineGraphConnectionEntityFactory)
- {
- _entityFunctions = entityFunctions;
- _connectionFactory = machineGraphConnectionEntityFactory;
- Logging.MetaDebugLog("Requirements injected.");
- }
-
- static MethodBase TargetMethod(Harmony instance)
- {
- return AccessTools.TypeByName("RobocraftX.CR.MachineEditing.RemoveBlockEngine").GetConstructors()[0];
- }
- }
- }
- }
|