GrowingPlant.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "Block.h"
  3. class GrowingPlantBlockType;
  4. struct GrowthState : public Framework::ReferenceCounter
  5. {
  6. private:
  7. float percentage;
  8. ModelInfo* model;
  9. public:
  10. GrowthState(float percentage, ModelInfo* model);
  11. ~GrowthState();
  12. float getPercentage() const;
  13. ModelInfo* zModel() const;
  14. };
  15. class GrowingPlantBlock : public Block
  16. {
  17. private:
  18. float seblingTicks;
  19. int seblingTicksMax;
  20. Framework::Text name;
  21. Framework::RCArray<GrowthState> states;
  22. int blockTypeAfterGrowth;
  23. bool plantSpawned;
  24. int lastSendState;
  25. public:
  26. GrowingPlantBlock(int typeId,
  27. Framework::Vec3<int> pos,
  28. int dimensionId,
  29. int maxTicks,
  30. Framework::Text name,
  31. int blockTypeAfterGrowth);
  32. virtual bool onTick(
  33. TickQueue* zQueue, int numTicks, bool& blocked) override;
  34. virtual void onPostTick() override;
  35. virtual void sendModelInfo(NetworkMessage* zMessage) override;
  36. virtual TickSourceType isTickSource() const override;
  37. virtual Framework::Text getTargetUIML();
  38. GrowingPlantBlock* addGrowthState(GrowthState* state);
  39. friend GrowingPlantBlockType;
  40. };
  41. class GrowingPlantBlockType : public BlockType
  42. {
  43. private:
  44. bool transparent;
  45. bool passable;
  46. float speedModifier;
  47. bool interactable;
  48. Framework::RCArray<GrowthState> states;
  49. int blockTypeIdAfterGrowth;
  50. Framework::Text blockTypeNameAfterGrowth;
  51. Framework::Text readableName;
  52. int ticksNeeded;
  53. public:
  54. GrowingPlantBlockType();
  55. protected:
  56. virtual void loadSuperBlock(Block* zBlock,
  57. Framework::StreamReader* zReader,
  58. int dimensionId) const override;
  59. void createSuperBlock(Block* zBlock, Item* zItem) const override;
  60. virtual void saveSuperBlock(
  61. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  62. virtual Item* createItem() const override;
  63. virtual Block* createBlock(
  64. Framework::Vec3<int> position, int dimensionId) const override;
  65. public:
  66. virtual ItemType* createItemType() const override;
  67. GrowingPlantBlockType* addGrowthState(
  68. float growthPercentage, ModelInfo* model);
  69. const Framework::RCArray<GrowthState>& getStates() const;
  70. void setBlockTypeNameAfterGrowth(Framework::Text blockTypeIdAfterGrowth);
  71. Framework::Text getBlockTypeNameAfterGrowth() const;
  72. void setReadableName(Framework::Text readableName);
  73. Framework::Text getReadableName() const;
  74. void setTicksNeeded(int ticksNeeded);
  75. int getTicksNeeded() const;
  76. void setTransparent(bool transparent);
  77. bool isTransparent() const;
  78. void setPassable(bool passable);
  79. bool isPassable() const;
  80. void setSpeedModifier(float speedModifier);
  81. float getSpeedModifier() const;
  82. void setInteractable(bool interactable);
  83. bool isInteractable() const;
  84. };
  85. class GrowingPlantBlockTypeFactory
  86. : public BlockTypeFactoryBase<GrowingPlantBlockType>
  87. {
  88. public:
  89. GrowingPlantBlockTypeFactory();
  90. GrowingPlantBlockType* createValue(
  91. Framework::JSON::JSONObject* zJson) const override;
  92. void fromJson(GrowingPlantBlockType* zResult,
  93. Framework::JSON::JSONObject* zJson) const override;
  94. void toJson(GrowingPlantBlockType* zObject,
  95. Framework::JSON::JSONObject* zResult) const override;
  96. JSONObjectValidationBuilder* addToValidator(
  97. JSONObjectValidationBuilder* builder) const override;
  98. Framework::Text getTypeToken() const override;
  99. };