Block.h 3.0 KB

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