A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

580 lines
21KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection.Emit;
  5. using Gamecraft.Blocks.BlockGroups;
  6. using Svelto.ECS;
  7. using Svelto.ECS.EntityStructs;
  8. using RobocraftX.Common;
  9. using RobocraftX.Blocks;
  10. using Unity.Mathematics;
  11. using Gamecraft.Blocks.GUI;
  12. using GamecraftModdingAPI.Blocks;
  13. using GamecraftModdingAPI.Utility;
  14. using RobocraftX.Rendering.GPUI;
  15. namespace GamecraftModdingAPI
  16. {
  17. /// <summary>
  18. /// A single (perhaps scaled) block. Properties may return default values if the block is removed and then setting them is ignored.
  19. /// For specific block type operations, use the specialised block classes in the GamecraftModdingAPI.Blocks namespace.
  20. /// </summary>
  21. public class Block : IEquatable<Block>, IEquatable<EGID>
  22. {
  23. protected static readonly PlacementEngine PlacementEngine = new PlacementEngine();
  24. protected static readonly MovementEngine MovementEngine = new MovementEngine();
  25. protected static readonly RotationEngine RotationEngine = new RotationEngine();
  26. protected static readonly RemovalEngine RemovalEngine = new RemovalEngine();
  27. protected static readonly SignalEngine SignalEngine = new SignalEngine();
  28. protected static readonly BlockEventsEngine BlockEventsEngine = new BlockEventsEngine();
  29. protected static readonly ScalingEngine ScalingEngine = new ScalingEngine();
  30. protected static readonly BlockCloneEngine BlockCloneEngine = new BlockCloneEngine();
  31. protected internal static readonly BlockEngine BlockEngine = new BlockEngine();
  32. /// <summary>
  33. /// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
  34. /// Place blocks next to each other to connect them.
  35. /// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
  36. /// </summary>
  37. /// <param name="block">The block's type</param>
  38. /// <param name="color">The block's color</param>
  39. /// <param name="material">The block's material</param>
  40. /// <param name="position">The block's position - default block size is 0.2</param>
  41. /// <param name="rotation">The block's rotation in degrees</param>
  42. /// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
  43. /// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
  44. /// <param name="isFlipped">Whether the block should be flipped</param>
  45. /// <param name="autoWire">Whether the block should be auto-wired (if functional)</param>
  46. /// <param name="player">The player who placed the block</param>
  47. /// <returns>The placed block or null if failed</returns>
  48. public static Block PlaceNew(BlockIDs block, float3 position, bool autoWire = false, Player player = null)
  49. {
  50. return PlaceNew<Block>(block, position, autoWire, player);
  51. }
  52. /// <summary>
  53. /// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
  54. /// Place blocks next to each other to connect them.
  55. /// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
  56. /// </summary>
  57. /// <param name="block">The block's type</param>
  58. /// <param name="color">The block's color</param>
  59. /// <param name="material">The block's materialr</param>
  60. /// <param name="position">The block's position - default block size is 0.2</param>
  61. /// <param name="rotation">The block's rotation in degrees</param>
  62. /// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
  63. /// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
  64. /// <param name="isFlipped">Whether the block should be flipped</param>
  65. /// <param name="autoWire">Whether the block should be auto-wired (if functional)</param>
  66. /// <param name="player">The player who placed the block</param>
  67. /// <returns>The placed block or null if failed</returns>
  68. public static T PlaceNew<T>(BlockIDs block, float3 position, bool autoWire = false, Player player = null)
  69. where T : Block
  70. {
  71. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  72. {
  73. var initializer = PlacementEngine.PlaceBlock(block, position, player, autoWire);
  74. var egid = initializer.EGID;
  75. var bl = New<T>(egid.entityID, egid.groupID);
  76. bl.InitData.Group = BlockEngine.InitGroup(initializer);
  77. Placed += bl.OnPlacedInit;
  78. return bl;
  79. }
  80. return null;
  81. }
  82. /// <summary>
  83. /// Returns the most recently placed block.
  84. /// </summary>
  85. /// <returns>The block object</returns>
  86. public static Block GetLastPlacedBlock()
  87. {
  88. return New<Block>(BlockIdentifiers.LatestBlockID);
  89. }
  90. /// <summary>
  91. /// An event that fires each time a block is placed.
  92. /// </summary>
  93. public static event EventHandler<BlockPlacedRemovedEventArgs> Placed
  94. {
  95. add => BlockEventsEngine.Placed += value;
  96. remove => BlockEventsEngine.Placed -= value;
  97. }
  98. /// <summary>
  99. /// An event that fires each time a block is removed.
  100. /// </summary>
  101. public static event EventHandler<BlockPlacedRemovedEventArgs> Removed
  102. {
  103. add => BlockEventsEngine.Removed += value;
  104. remove => BlockEventsEngine.Removed -= value;
  105. }
  106. private static Dictionary<Type, Func<EGID, Block>> initializers = new Dictionary<Type, Func<EGID, Block>>();
  107. private static Dictionary<Type, ExclusiveBuildGroup[]> typeToGroup =
  108. new Dictionary<Type, ExclusiveBuildGroup[]>
  109. {
  110. {typeof(LogicGate), new [] {CommonExclusiveGroups.LOGIC_BLOCK_GROUP}},
  111. {typeof(Motor), new[] {CommonExclusiveGroups.MOTOR_BLOCK_GROUP}},
  112. {typeof(MusicBlock), new[] {CommonExclusiveGroups.MUSIC_BLOCK_GROUP}},
  113. {typeof(ObjectIdentifier), new[]{CommonExclusiveGroups.OBJID_BLOCK_GROUP}},
  114. {typeof(Piston), new[] {CommonExclusiveGroups.PISTON_BLOCK_GROUP}},
  115. {typeof(Servo), new[] {CommonExclusiveGroups.SERVO_BLOCK_GROUP}},
  116. {
  117. typeof(SpawnPoint),
  118. new[]
  119. {
  120. CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP,
  121. CommonExclusiveGroups.BUILDINGSPAWN_BLOCK_GROUP
  122. }
  123. },
  124. {
  125. typeof(SfxBlock),
  126. new[]
  127. {
  128. CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP,
  129. CommonExclusiveGroups.LOOPEDSFX_BLOCK_GROUP
  130. }
  131. },
  132. {typeof(DampedSpring), new [] {CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP}},
  133. {typeof(TextBlock), new[] {CommonExclusiveGroups.TEXT_BLOCK_GROUP}},
  134. {typeof(Timer), new[] {CommonExclusiveGroups.TIMER_BLOCK_GROUP}}
  135. };
  136. /// <summary>
  137. /// Constructs a new instance of T with the given ID and group using dynamically created delegates.
  138. /// It's equivalent to new T(EGID) with a minimal overhead thanks to caching the created delegates.
  139. /// </summary>
  140. /// <param name="id">The block ID</param>
  141. /// <param name="group">The block group</param>
  142. /// <typeparam name="T">The block's type or Block itself</typeparam>
  143. /// <returns>An instance of the provided type</returns>
  144. /// <exception cref="BlockTypeException">The block group doesn't match or cannot be found</exception>
  145. /// <exception cref="MissingMethodException">The block class doesn't have the needed constructor</exception>
  146. private static T New<T>(uint id, ExclusiveGroupStruct? group = null) where T : Block
  147. {
  148. var type = typeof(T);
  149. EGID egid;
  150. if (!group.HasValue)
  151. {
  152. if (typeToGroup.TryGetValue(type, out var gr) && gr.Length == 1)
  153. egid = new EGID(id, gr[0]);
  154. else
  155. egid = BlockEngine.FindBlockEGID(id) ?? throw new BlockTypeException("Could not find block group!");
  156. }
  157. else
  158. {
  159. egid = new EGID(id, group.Value);
  160. if (typeToGroup.TryGetValue(type, out var gr)
  161. && gr.All(egs => egs != group.Value)) //If this subclass has a specific group, then use that - so Block should still work
  162. throw new BlockTypeException($"Incompatible block type! Type {type.Name} belongs to group {gr.Select(g => ((uint)g).ToString()).Aggregate((a, b) => a + ", " + b)} instead of {(uint)group.Value}");
  163. }
  164. if (initializers.TryGetValue(type, out var func))
  165. {
  166. var bl = (T) func(egid);
  167. return bl;
  168. }
  169. //https://stackoverflow.com/a/10593806/2703239
  170. var ctor = type.GetConstructor(new[] {typeof(EGID)});
  171. if (ctor == null)
  172. throw new MissingMethodException("There is no constructor with an EGID parameter for this object");
  173. DynamicMethod dynamic = new DynamicMethod(string.Empty,
  174. type,
  175. new[] {typeof(EGID)},
  176. type);
  177. ILGenerator il = dynamic.GetILGenerator();
  178. //il.DeclareLocal(type);
  179. il.Emit(OpCodes.Ldarg_0); //Load EGID and pass to constructor
  180. il.Emit(OpCodes.Newobj, ctor); //Call constructor
  181. //il.Emit(OpCodes.Stloc_0); - doesn't seem like we need these
  182. //il.Emit(OpCodes.Ldloc_0);
  183. il.Emit(OpCodes.Ret);
  184. func = (Func<EGID, T>) dynamic.CreateDelegate(typeof(Func<EGID, T>));
  185. initializers.Add(type, func);
  186. var block = (T) func(egid);
  187. return block;
  188. }
  189. public Block(EGID id)
  190. {
  191. Id = id;
  192. var type = GetType();
  193. if (typeToGroup.TryGetValue(type, out var groups))
  194. {
  195. if (groups.All(gr => gr != id.groupID))
  196. throw new BlockTypeException("The block has the wrong group! The type is " + GetType() +
  197. " while the group is " + id.groupID);
  198. }
  199. else if (type != typeof(Block) && !typeof(CustomBlock).IsAssignableFrom(type))
  200. Logging.LogWarning($"Unknown block type! Add {type} to the dictionary.");
  201. }
  202. /// <summary>
  203. /// This overload searches for the correct group the block is in.
  204. /// It will throw an exception if the block doesn't exist.
  205. /// Use the EGID constructor where possible or subclasses of Block as those specify the group.
  206. /// </summary>
  207. public Block(uint id)
  208. {
  209. Id = BlockEngine.FindBlockEGID(id) ?? throw new BlockTypeException("Could not find the appropriate group for the block. The block probably doesn't exist or hasn't been submitted.");
  210. }
  211. /// <summary>
  212. /// Places a new block in the world.
  213. /// </summary>
  214. /// <param name="type">The block's type</param>
  215. /// <param name="position">The block's position (a block is 0.2 wide in terms of position)</param>
  216. /// <param name="autoWire">Whether the block should be auto-wired (if functional)</param>
  217. /// <param name="player">The player who placed the block</param>
  218. public Block(BlockIDs type, float3 position, bool autoWire = false, Player player = null)
  219. {
  220. if (!PlacementEngine.IsInGame || !GameState.IsBuildMode())
  221. throw new BlockException("Blocks can only be placed in build mode.");
  222. var initializer = PlacementEngine.PlaceBlock(type, position, player, autoWire);
  223. Id = initializer.EGID;
  224. InitData.Group = BlockEngine.InitGroup(initializer);
  225. Placed += OnPlacedInit;
  226. }
  227. public EGID Id { get; }
  228. internal BlockEngine.BlockInitData InitData;
  229. private EGID copiedFrom;
  230. /// <summary>
  231. /// The block's current position or zero if the block no longer exists.
  232. /// A block is 0.2 wide by default in terms of position.
  233. /// </summary>
  234. public float3 Position
  235. {
  236. get => MovementEngine.GetPosition(Id, InitData);
  237. set
  238. {
  239. MovementEngine.MoveBlock(Id, InitData, value);
  240. if (blockGroup != null)
  241. blockGroup.PosAndRotCalculated = false;
  242. BlockEngine.UpdateDisplayedBlock(Id);
  243. }
  244. }
  245. /// <summary>
  246. /// The block's current rotation in degrees or zero if the block doesn't exist.
  247. /// </summary>
  248. public float3 Rotation
  249. {
  250. get => RotationEngine.GetRotation(Id, InitData);
  251. set
  252. {
  253. RotationEngine.RotateBlock(Id, InitData, value);
  254. if (blockGroup != null)
  255. blockGroup.PosAndRotCalculated = false;
  256. BlockEngine.UpdateDisplayedBlock(Id);
  257. }
  258. }
  259. /// <summary>
  260. /// The block's non-uniform scale or zero if the block's invalid. Independent of the uniform scaling.
  261. /// The default scale of 1 means 0.2 in terms of position.
  262. /// </summary>
  263. public float3 Scale
  264. {
  265. get => BlockEngine.GetBlockInfo(this, (ScalingEntityStruct st) => st.scale);
  266. set
  267. {
  268. int uscale = UniformScale;
  269. if (value.x < 4e-5) value.x = uscale;
  270. if (value.y < 4e-5) value.y = uscale;
  271. if (value.z < 4e-5) value.z = uscale;
  272. BlockEngine.SetBlockInfo(this, (ref ScalingEntityStruct st, float3 val) => st.scale = val, value);
  273. if (!Exists) return; //UpdateCollision needs the block to exist
  274. ScalingEngine.UpdateCollision(Id);
  275. BlockEngine.UpdateDisplayedBlock(Id);
  276. }
  277. }
  278. /// <summary>
  279. /// The block's uniform scale or zero if the block's invalid. Also sets the non-uniform scale.
  280. /// The default scale of 1 means 0.2 in terms of position.
  281. /// </summary>
  282. public int UniformScale
  283. {
  284. get => BlockEngine.GetBlockInfo(this, (UniformBlockScaleEntityStruct st) => st.scaleFactor);
  285. set
  286. {
  287. if (value < 1) value = 1;
  288. BlockEngine.SetBlockInfo(this, (ref UniformBlockScaleEntityStruct st, int val) => st.scaleFactor = val,
  289. value);
  290. Scale = new float3(value, value, value);
  291. }
  292. }
  293. /**
  294. * Whether the block is flipped.
  295. */
  296. public bool Flipped
  297. {
  298. get => BlockEngine.GetBlockInfo(this, (ScalingEntityStruct st) => st.scale.x < 0);
  299. set
  300. {
  301. BlockEngine.SetBlockInfo(this, (ref ScalingEntityStruct st, bool val) =>
  302. st.scale.x = math.abs(st.scale.x) * (val ? -1 : 1), value);
  303. BlockEngine.SetBlockInfo(this, (ref GFXPrefabEntityStructGPUI st, bool val) =>
  304. {
  305. uint prefabId = PrefabsID.GetOrCreatePrefabID((ushort) Type, (byte) Material, 0, value);
  306. st.prefabID = prefabId;
  307. }, value);
  308. }
  309. }
  310. /// <summary>
  311. /// The block's type (ID). Returns BlockIDs.Invalid if the block doesn't exist anymore.
  312. /// </summary>
  313. public BlockIDs Type
  314. {
  315. get
  316. {
  317. return BlockEngine.GetBlockInfo(this, (DBEntityStruct st) => (BlockIDs) st.DBID, BlockIDs.Invalid);
  318. }
  319. }
  320. /// <summary>
  321. /// The block's color. Returns BlockColors.Default if the block no longer exists.
  322. /// </summary>
  323. public BlockColor Color
  324. {
  325. get
  326. {
  327. byte index = BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.indexInPalette,
  328. byte.MaxValue);
  329. return new BlockColor(index);
  330. }
  331. set
  332. {
  333. BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, BlockColor val) =>
  334. { //TODO: Check if setting to 255 works
  335. color.indexInPalette = val.Index;
  336. color.hasNetworkChange = true;
  337. color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
  338. }, value);
  339. }
  340. }
  341. /// <summary>
  342. /// The block's exact color. Gets reset to the palette color (Color property) after reentering the game.
  343. /// </summary>
  344. public float4 CustomColor
  345. {
  346. get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.paletteColour);
  347. set
  348. {
  349. BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) =>
  350. {
  351. color.paletteColour = val;
  352. color.hasNetworkChange = true;
  353. }, value);
  354. }
  355. }
  356. /**
  357. * The block's material.
  358. */
  359. public BlockMaterial Material
  360. {
  361. get => BlockEngine.GetBlockInfo(this, (CubeMaterialStruct cmst) => (BlockMaterial) cmst.materialId, BlockMaterial.Default);
  362. set => BlockEngine.SetBlockInfo(this,
  363. (ref CubeMaterialStruct cmst, BlockMaterial val) => cmst.materialId = (byte) val, value);
  364. }
  365. /// <summary>
  366. /// The text displayed on the block if applicable, or null.
  367. /// Setting it is temporary to the session, it won't be saved.
  368. /// </summary>
  369. public string Label
  370. {
  371. get => BlockEngine.GetBlockInfoViewStruct(this, (TextLabelEntityViewStruct st) => st.textLabelComponent?.text);
  372. set
  373. {
  374. BlockEngine.SetBlockInfoViewStruct(this, (ref TextLabelEntityViewStruct text, string val) =>
  375. {
  376. if (text.textLabelComponent != null) text.textLabelComponent.text = val;
  377. }, value);
  378. }
  379. }
  380. private BlockGroup blockGroup;
  381. /// <summary>
  382. /// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
  383. /// Returns null if not part of a group.<br />
  384. /// Setting the group after the block has been initialized will not update everything properly,
  385. /// so you can only set this property on blocks newly placed by your code.<br />
  386. /// To set it for existing blocks, you can use the Copy() method and set the property on the resulting block
  387. /// (and remove this block).
  388. /// </summary>
  389. public BlockGroup BlockGroup
  390. {
  391. get
  392. {
  393. if (blockGroup != null) return blockGroup;
  394. return blockGroup = BlockEngine.GetBlockInfo(this,
  395. (BlockGroupEntityComponent bgec) =>
  396. bgec.currentBlockGroup == -1 ? null : new BlockGroup(bgec.currentBlockGroup, this));
  397. }
  398. set
  399. {
  400. if (Exists)
  401. {
  402. Logging.LogWarning("Attempted to set group of existing block. This is not supported."
  403. + " Copy the block and set the group of the resulting block.");
  404. return;
  405. }
  406. blockGroup?.RemoveInternal(this);
  407. BlockEngine.SetBlockInfo(this,
  408. (ref BlockGroupEntityComponent bgec, BlockGroup val) => bgec.currentBlockGroup = val?.Id ?? -1,
  409. value);
  410. value?.AddInternal(this);
  411. blockGroup = value;
  412. }
  413. }
  414. /// <summary>
  415. /// Whether the block exists. The other properties will return a default value if the block doesn't exist.
  416. /// If the block was just placed, then this will also return false but the properties will work correctly.
  417. /// </summary>
  418. public bool Exists => BlockEngine.BlockExists(Id);
  419. /// <summary>
  420. /// Returns an array of blocks that are connected to this one. Returns an empty array if the block doesn't exist.
  421. /// </summary>
  422. public Block[] GetConnectedCubes() => BlockEngine.GetConnectedBlocks(Id);
  423. /// <summary>
  424. /// Removes this block.
  425. /// </summary>
  426. /// <returns>True if the block exists and could be removed.</returns>
  427. public bool Remove() => RemovalEngine.RemoveBlock(Id);
  428. /// <summary>
  429. /// Returns the rigid body of the chunk of blocks this one belongs to during simulation.
  430. /// Can be used to apply forces or move the block around while the simulation is running.
  431. /// </summary>
  432. /// <returns>The SimBody of the chunk or null if the block doesn't exist or not in simulation mode.</returns>
  433. public SimBody GetSimBody()
  434. {
  435. return BlockEngine.GetBlockInfo(this,
  436. (GridConnectionsEntityStruct st) => st.machineRigidBodyId != uint.MaxValue
  437. ? new SimBody(st.machineRigidBodyId, st.clusterId)
  438. : null);
  439. }
  440. /// <summary>
  441. /// Creates a copy of the block in the game with the same properties, stats and wires.
  442. /// </summary>
  443. /// <returns></returns>
  444. public T Copy<T>() where T : Block
  445. {
  446. var block = PlaceNew<T>(Type, Position);
  447. block.Rotation = Rotation;
  448. block.Color = Color;
  449. block.Material = Material;
  450. block.UniformScale = UniformScale;
  451. block.Scale = Scale;
  452. block.copiedFrom = Id;
  453. return block;
  454. }
  455. private void OnPlacedInit(object sender, BlockPlacedRemovedEventArgs e)
  456. { //Member method instead of lambda to avoid constantly creating delegates
  457. if (e.ID != Id) return;
  458. Placed -= OnPlacedInit; //And we can reference it
  459. InitData = default; //Remove initializer as it's no longer valid - if the block gets removed it shouldn't be used again
  460. if (copiedFrom != EGID.Empty)
  461. BlockCloneEngine.CopyBlockStats(copiedFrom, Id);
  462. }
  463. public override string ToString()
  464. {
  465. return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";
  466. }
  467. public bool Equals(Block other)
  468. {
  469. if (ReferenceEquals(null, other)) return false;
  470. if (ReferenceEquals(this, other)) return true;
  471. return Id.Equals(other.Id);
  472. }
  473. public bool Equals(EGID other)
  474. {
  475. return Id.Equals(other);
  476. }
  477. public override bool Equals(object obj)
  478. {
  479. if (ReferenceEquals(null, obj)) return false;
  480. if (ReferenceEquals(this, obj)) return true;
  481. if (obj.GetType() != this.GetType()) return false;
  482. return Equals((Block) obj);
  483. }
  484. public override int GetHashCode()
  485. {
  486. return Id.GetHashCode();
  487. }
  488. public static void Init()
  489. {
  490. GameEngineManager.AddGameEngine(PlacementEngine);
  491. GameEngineManager.AddGameEngine(MovementEngine);
  492. GameEngineManager.AddGameEngine(RotationEngine);
  493. GameEngineManager.AddGameEngine(RemovalEngine);
  494. GameEngineManager.AddGameEngine(BlockEngine);
  495. GameEngineManager.AddGameEngine(BlockEventsEngine);
  496. GameEngineManager.AddGameEngine(ScalingEngine);
  497. GameEngineManager.AddGameEngine(SignalEngine);
  498. GameEngineManager.AddGameEngine(BlockCloneEngine);
  499. Wire.signalEngine = SignalEngine; // requires same functionality, no need to duplicate the engine
  500. }
  501. /// <summary>
  502. /// Convert the block to a specialised block class.
  503. /// </summary>
  504. /// <returns>The block.</returns>
  505. /// <typeparam name="T">The specialised block type.</typeparam>
  506. public T Specialise<T>() where T : Block
  507. {
  508. // What have I gotten myself into?
  509. // C# can't cast to a child of Block unless the object was originally that child type
  510. // And C# doesn't let me make implicit cast operators for child types
  511. // So thanks to Microsoft, we've got this horrible implementation using reflection
  512. //Lets improve that using delegates
  513. var block = New<T>(Id.entityID, Id.groupID);
  514. if (this.InitData.Group != null)
  515. {
  516. block.InitData = this.InitData;
  517. Placed += block.OnPlacedInit; //Reset InitData of new object
  518. }
  519. return block;
  520. }
  521. #if DEBUG
  522. public static EntitiesDB entitiesDB
  523. {
  524. get
  525. {
  526. return BlockEngine.GetEntitiesDB();
  527. }
  528. }
  529. #endif
  530. }
  531. }