BlockType.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include <Array.h>
  3. #include <Either.h>
  4. #include <Vec3.h>
  5. #include <Writer.h>
  6. #include "ModelInfo.h"
  7. #include "StaticRegistry.h"
  8. class Item;
  9. class Block;
  10. class BlockTypeEnum
  11. {
  12. public:
  13. static const int NO_BLOCK = 0;
  14. static const int AIR = 1;
  15. static const int DIRT = 2;
  16. static const int SAND = 3;
  17. static const int GRAVEL = 4;
  18. static const int STONE = 5;
  19. static const int STONE_GRANITE = 6;
  20. static const int STONE_COBBLE = 7;
  21. static const int STONE_BASALT = 8;
  22. static const int WOOD_OAK = 9;
  23. static const int WOOD_BIRCH = 10;
  24. static const int WOOD_BEECH = 11;
  25. static const int WOOD_PINE = 12;
  26. static const int LEAVES_WOOD_OAK = 13;
  27. static const int LEAVES_WOOD_BIRCH = 14;
  28. static const int LEAVES_WOOD_BEECH = 15;
  29. static const int LEAVES_WOOD_PINE = 16;
  30. static const int SEBLING_WOOD_OAK = 17;
  31. static const int SEBLING_WOOD_BIRCH = 18;
  32. static const int SEBLING_WOOD_BEECH = 19;
  33. static const int SEBLING_WOOD_PINE = 20;
  34. static const int TORCH = 21;
  35. static const int GRASS = 22;
  36. static const int FARMLAND = 23;
  37. static const int WHEAT_SEED = 24;
  38. static const int WHEAT = 25;
  39. static const int WATER = 26;
  40. static const int CRAFTING_TABLE = 27;
  41. static const int CHEST = 28;
  42. static const int MAX_VALUE = 100000; // leve enough space for other blocks
  43. };
  44. class BlockType : public virtual Framework::ReferenceCounter
  45. {
  46. private:
  47. const int id;
  48. const ModelInfo model;
  49. int initialMaxHP;
  50. const bool needsClientInstance;
  51. bool lightSource;
  52. const char* name;
  53. const bool needModelSubscription;
  54. protected:
  55. int initialMapColor;
  56. Block* defaultBlock;
  57. BlockType(int id,
  58. Block* defaultBlock,
  59. ModelInfo model,
  60. bool needsClientInstance,
  61. int initialMaxHP,
  62. bool lightSource,
  63. const char* name,
  64. bool needModelSubscription,
  65. int initialMapColor);
  66. virtual ~BlockType();
  67. virtual void loadSuperBlock(
  68. Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const;
  69. virtual void saveSuperBlock(
  70. Block* zBlock, Framework::StreamWriter* zWriter) const;
  71. virtual void createSuperBlock(Block* zBlock, Item* zItem) const;
  72. virtual void createSuperItem(Block* zBlock, Item* zItem) const;
  73. virtual Block* createBlock(Framework::Vec3<int> position, int dimensionId) const = 0;
  74. virtual Item* createItem() const = 0;
  75. public:
  76. virtual Framework::Text getTargetUIML() const;
  77. virtual Block* loadBlock(Framework::Vec3<int> position,
  78. Framework::StreamReader* zReader,
  79. int dimensionId) const;
  80. virtual void saveBlock(
  81. Block* zBlock, Framework::StreamWriter* zWriter) const;
  82. virtual Item* getItemFromBlock(Block* zBlock) const;
  83. virtual Block* createBlockAt(
  84. Framework::Vec3<int> position, int dimensionId, Item* zUsedItem) const;
  85. virtual const Block* zDefault() const;
  86. bool doesNeedClientInstance() const;
  87. const ModelInfo& getModel() const;
  88. int getId() const;
  89. int getInitialMaxHP() const;
  90. bool isLightSource() const;
  91. BlockType* initializeDefault();
  92. const char* getName() const;
  93. const bool doesNeedModelSubscription() const;
  94. void writeTypeInfo(Framework::StreamWriter* zWriter) const;
  95. static int getTypeId(const char* name);
  96. };
  97. const Block* getDefaultBlock(Framework::Either<Block*, int> b);