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.

41 lines
1.3KB

  1. using Gamecraft.Wires;
  2. using Svelto.ECS;
  3. namespace GamecraftModdingAPI.Blocks
  4. {
  5. public class ObjectIdentifier : Block
  6. {
  7. public ObjectIdentifier(EGID id) : base(id)
  8. {
  9. if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
  10. {
  11. throw new BlockTypeException($"Block is not a {GetType().Name} block");
  12. }
  13. }
  14. public ObjectIdentifier(uint id) : base(id)
  15. {
  16. if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
  17. {
  18. throw new BlockTypeException($"Block is not a {GetType().Name} block");
  19. }
  20. }
  21. public char Identifier
  22. {
  23. get => (char) (BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId + 'A');
  24. set
  25. {
  26. BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).objectId = (byte) (value - 'A');
  27. Label = value + ""; //The label isn't updated automatically
  28. }
  29. }
  30. /// <summary>
  31. /// Finds the identfier blocks with the given ID.
  32. /// </summary>
  33. /// <param name="id">The ID to look for</param>
  34. /// <returns>An array that may be empty</returns>
  35. public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'));
  36. }
  37. }