Block.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 isTransparent() const;
  33. void remove();
  34. bool isVisible() const;
  35. const BlockType* zBlockType() const;
  36. friend Chunk;
  37. friend BlockType;
  38. };
  39. class BasicBlockItem : public Item
  40. {
  41. protected:
  42. bool transparent;
  43. bool passable;
  44. float hp;
  45. float maxHP;
  46. float hardness;
  47. int toolId;
  48. float speedModifier;
  49. public:
  50. BasicBlockItem( const ItemType* zType, const char* name );
  51. friend BasicBlockItemType;
  52. friend BlockType;
  53. };
  54. class BasicBlockItemType : public ItemType
  55. {
  56. protected:
  57. BasicBlockItemType( int id );
  58. virtual void loadSuperItem( Item* zItem, Framework::StreamReader* zReader ) const override;
  59. };