BlockType.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 MAX_VALUE = 21;
  36. };
  37. class BlockType : public virtual Framework::ReferenceCounter
  38. {
  39. private:
  40. const int id;
  41. const ModelInfo model;
  42. int initialMaxHP;
  43. const bool needsClientInstance;
  44. bool lightSource;
  45. protected:
  46. Block* defaultBlock;
  47. BlockType(int id,
  48. Block* defaultBlock,
  49. ModelInfo model,
  50. bool needsClientInstance,
  51. int initialMaxHP,
  52. bool lightSource);
  53. virtual ~BlockType();
  54. virtual void loadSuperBlock(
  55. Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const;
  56. virtual void saveSuperBlock(
  57. Block* zBlock, Framework::StreamWriter* zWriter) const;
  58. virtual void createSuperBlock(Block* zBlock, Item* zItem) const;
  59. virtual void createSuperItem(Block* zBlock, Item* zItem) const;
  60. virtual Block* createBlock(Framework::Vec3<int> position) const = 0;
  61. virtual Item* createItem() const = 0;
  62. public:
  63. virtual Block* loadBlock(Framework::Vec3<int> position,
  64. Framework::StreamReader* zReader,
  65. int dimensionId) const;
  66. virtual void saveBlock(
  67. Block* zBlock, Framework::StreamWriter* zWriter) const;
  68. virtual Item* getItemFromBlock(Block* zBlock) const;
  69. virtual Block* createBlockAt(
  70. Framework::Vec3<int> position, Item* zUsedItem) const;
  71. virtual const Block* zDefault() const;
  72. bool doesNeedClientInstance() const;
  73. const ModelInfo& getModel() const;
  74. int getId() const;
  75. int getInitialMaxHP() const;
  76. bool isLightSource() const;
  77. BlockType* initializeDefault();
  78. };
  79. const Block* getDefaultBlock(Framework::Either<Block*, int> b);