Block.h 1.6 KB

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