Block.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include "EventListener.h"
  3. #include "BlockType.h"
  4. #include "ReferenceCounter.h"
  5. #include "EventThrower.h"
  6. #include "Item.h"
  7. #include "Inventory.h"
  8. #include "NetworkResponse.h"
  9. #include <Trie.h>
  10. #include <Vec3.h>
  11. class BlockType;
  12. class ItemType;
  13. class Chunk;
  14. class BasicBlockItemType;
  15. class TickQueue;
  16. class Block : public Inventory
  17. {
  18. private:
  19. int ticksLeftCounter;
  20. int currentTickTimeout;
  21. bool wasTicked;
  22. bool onTickCalled;
  23. int dimansionId;
  24. protected:
  25. bool transparent;
  26. bool passable;
  27. float hp;
  28. float maxHP;
  29. float hardness;
  30. const BlockType *zType;
  31. ItemType *zTool;
  32. float speedModifier;
  33. Block *neighbours[ 6 ];
  34. int minTickTimeout;
  35. int maxTickTimeout;
  36. bool tickSource;
  37. /// <summary>
  38. /// executes block specific things
  39. /// </summary>
  40. /// <param name="zqueue">a queue to add neighbor blocks that should be ticked after this block</param>
  41. /// <param name="numTicks">the number of ticks passed since the last call (only for tickSources)</param>
  42. /// <param name="blocked">can be set to one to tell that this block needs to be tickt again later in the queue of this tick</param>
  43. /// <returns>true, iff the block needs to be ticked more often</returns>
  44. virtual bool onTick( TickQueue *zQueue, int numTicks, bool &blocked ) = 0;
  45. /// <summary>
  46. /// gets called after each block was tickt.
  47. /// the order of blocks called will be exactly the same as onTick
  48. /// </summary>
  49. virtual void onPostTick() = 0;
  50. public:
  51. Block( const BlockType *zType, ItemType *zTool, Framework::Vec3<int> pos );
  52. void tick( TickQueue *zQueue );
  53. void postTick();
  54. void setDimensionId( int id );
  55. void api( Framework::StreamReader *zRequest, NetworkResponse *zResponse );
  56. bool isTickSource() const;
  57. const BlockType *zBlockType() const;
  58. bool isTransparent() const;
  59. bool isPassable() const;
  60. float getHP() const;
  61. float getMaxHP() const;
  62. float getHardness() const;
  63. ItemType *zEffectiveTool() const;
  64. float getSpeedModifier() const;
  65. const Framework::Vec3<int> getPos() const;
  66. int getDimensionId() const;
  67. friend Chunk;
  68. friend BlockType;
  69. };
  70. class BasicBlockItem : public Item
  71. {
  72. protected:
  73. bool transparent;
  74. bool passable;
  75. float hp;
  76. float maxHP;
  77. float hardness;
  78. int toolId;
  79. float speedModifier;
  80. public:
  81. BasicBlockItem( const ItemType *zType, const char *name );
  82. virtual bool canBeStackedWith( Item *zItem ) const override;
  83. friend BasicBlockItemType;
  84. friend BlockType;
  85. };
  86. class BasicBlockItemType : public ItemType
  87. {
  88. protected:
  89. BasicBlockItemType( int id, ItemSkillLevelUpRule *levelUpRule, const ItemType *zBrokenType );
  90. virtual void loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const override;
  91. virtual void saveSuperItem( const Item *zItem, Framework::StreamWriter *zWriter ) const override;
  92. void initializeItem( BasicBlockItem *zItem, bool transparent, bool passable, float hp, float maxHP, float hardness, int toolId, float speedModifier ) const;
  93. };