Block.h 1.7 KB

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