@@ -1,5 +1,8 @@ | |||
namespace GamecraftModdingAPI.Blocks | |||
{ | |||
/// <summary> | |||
/// Preset block colours | |||
/// </summary> | |||
public enum BlockColors | |||
{ | |||
Default = byte.MaxValue, | |||
@@ -1,5 +1,8 @@ | |||
namespace GamecraftModdingAPI.Blocks | |||
{ | |||
/// <summary> | |||
/// Possible block types | |||
/// </summary> | |||
public enum BlockIDs | |||
{ | |||
AluminiumCube, | |||
@@ -20,7 +20,7 @@ namespace GamecraftModdingAPI.Blocks | |||
/// </summary> | |||
/// <param name="id">The block's id</param> | |||
/// <param name="vector">The movement amount (x,y,z)</param> | |||
/// <returns></returns> | |||
/// <returns>Whether the operation was successful</returns> | |||
public static bool MoveBlock(uint id, float3 vector) | |||
{ | |||
if (movementEngine.IsInGame && movementEngine.IsBuildMode()) | |||
@@ -36,7 +36,7 @@ namespace GamecraftModdingAPI.Blocks | |||
/// </summary> | |||
/// <param name="id">The starting block's id</param> | |||
/// <param name="vector">The movement amount (x,y,z)</param> | |||
/// <returns></returns> | |||
/// <returns>Whether the operation was successful</returns> | |||
public static bool MoveConnectedBlocks(uint id, float3 vector) | |||
{ | |||
if (movementEngine.IsInGame && movementEngine.IsBuildMode()) | |||
@@ -1,12 +1,13 @@ | |||
using System; | |||
using GamecraftModdingAPI.Utility; | |||
using GCMC; | |||
using Unity.Mathematics; | |||
using GamecraftModdingAPI.Utility; | |||
namespace GamecraftModdingAPI.Blocks | |||
{ | |||
/// <summary> | |||
/// Common block movement operations | |||
/// Common block placement operations | |||
/// </summary> | |||
public static class Placement | |||
{ | |||
@@ -24,17 +25,26 @@ namespace GamecraftModdingAPI.Blocks | |||
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param> | |||
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param> | |||
/// <param name="playerId">The player who placed the block</param> | |||
/// <exception cref="Exception"></exception> | |||
/// <returns>Whether the operation was successful</returns> | |||
public static bool PlaceBlock(BlockIDs block, float3 position, | |||
quaternion rotation = new quaternion(), BlockColors color = BlockColors.Default, byte darkness = 0, | |||
int uscale = 1, float3 scale = new float3(), uint playerId = 0) | |||
{ | |||
if (placementEngine.IsInGame && GameState.IsBuildMode()) | |||
{ | |||
placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation); | |||
try | |||
{ | |||
placementEngine.PlaceBlock(block, color, darkness, position, uscale, scale, playerId, rotation); | |||
} | |||
catch (Exception e) | |||
{ | |||
#if DEBUG | |||
Logging.LogException(e); | |||
#endif | |||
return false; | |||
} | |||
return true; | |||
} | |||
return false; | |||
} | |||
@@ -1,10 +1,8 @@ | |||
using System; | |||
using System.Reflection; | |||
using DataLoader; | |||
using GamecraftModdingAPI.Blocks; | |||
using GamecraftModdingAPI.Utility; | |||
using Harmony; | |||
using JetBrains.Annotations; | |||
using RobocraftX.Blocks; | |||
using RobocraftX.Blocks.Ghost; | |||
using RobocraftX.Blocks.Scaling; | |||
@@ -22,8 +20,13 @@ using Unity.Mathematics; | |||
using UnityEngine; | |||
using uREPL; | |||
namespace GCMC | |||
using GamecraftModdingAPI.Utility; | |||
namespace GamecraftModdingAPI.Blocks | |||
{ | |||
/// <summary> | |||
/// Engine which executes block placement actions | |||
/// </summary> | |||
public class PlacementEngine : IApiEngine | |||
{ | |||
public bool IsInGame = false; | |||
@@ -55,22 +58,14 @@ namespace GCMC | |||
public void PlaceBlock(BlockIDs block, BlockColors color, byte darkness, float3 position, int uscale, | |||
float3 scale, uint playerId, quaternion rotation) | |||
{ //It appears that only the non-uniform scale has any visible effect, but if that's not given here it will be set to the uniform one | |||
try | |||
{ | |||
if (darkness > 9) | |||
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)"); | |||
BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation).Init( | |||
new BlockPlacementInfoStruct() | |||
{ | |||
loadedFromDisk = false, | |||
placedBy = playerId | |||
}); | |||
} | |||
catch (Exception e) | |||
{ | |||
Console.WriteLine(e); | |||
Log.Error(e.Message); | |||
} | |||
if (darkness > 9) | |||
throw new Exception("That is too dark. Make sure to use 0-9 as darkness. (0 is default.)"); | |||
BuildBlock((ushort) block, (byte) (color + darkness * 10), position, uscale, scale, rotation).Init( | |||
new BlockPlacementInfoStruct() | |||
{ | |||
loadedFromDisk = false, | |||
placedBy = playerId | |||
}); | |||
} | |||
private EntityStructInitializer BuildBlock(ushort block, byte color, float3 position, int uscale, float3 scale, quaternion rot) | |||
@@ -135,16 +130,15 @@ namespace GCMC | |||
return structInitializer; | |||
} | |||
public string Name { get; } = nameof(PlacementEngine); | |||
public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine"; | |||
[HarmonyPatch] | |||
[UsedImplicitly] | |||
public class FactoryObtainerPatch | |||
{ | |||
static void Postfix(BlockEntityFactory blockEntityFactory) | |||
{ | |||
_blockEntityFactory = blockEntityFactory; | |||
Debug.Log("Block entity factory injected."); | |||
Logging.MetaDebugLog("Block entity factory injected."); | |||
} | |||
static MethodBase TargetMethod(HarmonyInstance instance) | |||
@@ -19,8 +19,8 @@ namespace GamecraftModdingAPI.Blocks | |||
/// Rotate a single block by a specific amount in degrees | |||
/// </summary> | |||
/// <param name="id">The block's id</param> | |||
/// <param name="vector">The rotation amount around the x,y,z-planes</param> | |||
/// <returns></returns> | |||
/// <param name="vector">The rotation amount around the x,y,z-axis</param> | |||
/// <returns>Whether the operation was successful</returns> | |||
public static bool RotateBlock(uint id, float3 vector) | |||
{ | |||
if (rotationEngine.IsInGame && rotationEngine.IsBuildMode()) | |||
@@ -35,8 +35,8 @@ namespace GamecraftModdingAPI.Blocks | |||
/// Rotate all connected blocks by a specific amount in degrees | |||
/// </summary> | |||
/// <param name="id">The starting block's id</param> | |||
/// <param name="vector">The rotation around the x,y,z-planes</param> | |||
/// <returns></returns> | |||
/// <param name="vector">The rotation around the x,y,z-axis</param> | |||
/// <returns>Whether the operation was successful</returns> | |||
public static bool RotateConnectedBlocks(uint id, float3 vector) | |||
{ | |||
if (rotationEngine.IsInGame && rotationEngine.IsBuildMode()) | |||
@@ -24,7 +24,7 @@ using GamecraftModdingAPI.Utility; | |||
namespace GamecraftModdingAPI.Blocks | |||
{ | |||
/// <summary> | |||
/// Engine which executes block movement actions | |||
/// Engine which executes signal actions | |||
/// </summary> | |||
public class SignalEngine : IApiEngine | |||
{ | |||