Block.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <Model3D.h>
  3. #include "Inventory.h"
  4. #include "BlockType.h"
  5. #include "Registries.h"
  6. using namespace Framework;
  7. #define CONST_BLOCK(maybeBlock, type) (maybeBlock ? maybeBlock : STATIC_REGISTRY( BlockType ).zElement((int)type)->zDefault())
  8. class BasicBlockItemType;
  9. class Chunk;
  10. class Block : public Model3D, public Inventory
  11. {
  12. protected:
  13. bool transparent;
  14. bool passable;
  15. float hp;
  16. float maxHP;
  17. float hardness;
  18. float speedModifier;
  19. const BlockType* zType;
  20. ItemType* zTool;
  21. bool sideVisible[6];
  22. public:
  23. Block(const BlockType* zType, ItemType* zTool, Vec3<int> position, bool hasInventory);
  24. virtual ~Block();
  25. void api(char* message);
  26. bool isTransparent() const;
  27. bool isPassable() const;
  28. void setSideVisible(Direction dir, bool visible);
  29. const BlockType* zBlockType() const;
  30. friend Chunk;
  31. friend BlockType;
  32. };
  33. class BasicBlockItem : public Item
  34. {
  35. protected:
  36. bool transparent;
  37. bool passable;
  38. float hp;
  39. float maxHP;
  40. float hardness;
  41. int toolId;
  42. float speedModifier;
  43. bool interactable;
  44. public:
  45. BasicBlockItem(const ItemType* zType, const char* name);
  46. friend BasicBlockItemType;
  47. friend BlockType;
  48. };
  49. class BasicBlockItemType : public ItemType
  50. {
  51. private:
  52. const char* name;
  53. const char* texturPath;
  54. protected:
  55. BasicBlockItemType(int id, const char* name, const char* texturPath);
  56. virtual void loadSuperItem(Item* zItem, Framework::StreamReader* zReader) const override;
  57. public:
  58. virtual Framework::Model3DData* getItemModel() const override;
  59. virtual Framework::Model3DTextur* getItemTextur() const override;
  60. virtual Item* createItem() const override;
  61. };