GrowingPlant.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 Framework::Text getTargetUIML();
  37. GrowingPlantBlock* addGrowthState(GrowthState* state);
  38. friend GrowingPlantBlockType;
  39. };
  40. class GrowingPlantBlockType : public BlockType
  41. {
  42. private:
  43. bool transparent;
  44. bool passable;
  45. float speedModifier;
  46. bool interactable;
  47. Framework::RCArray<GrowthState> states;
  48. int blockTypeIdAfterGrowth;
  49. Framework::Text blockTypeNameAfterGrowth;
  50. const char* readableName;
  51. int ticksNeeded;
  52. public:
  53. GrowingPlantBlockType();
  54. protected:
  55. virtual void loadSuperBlock(Block* zBlock,
  56. Framework::StreamReader* zReader,
  57. int dimensionId) const override;
  58. void createSuperBlock(Block* zBlock, Item* zItem) const override;
  59. virtual void saveSuperBlock(
  60. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  61. virtual Item* createItem() const override;
  62. virtual Block* createBlock(
  63. Framework::Vec3<int> position, int dimensionId) const override;
  64. public:
  65. virtual ItemType* createItemType() const override;
  66. GrowingPlantBlockType* addGrowthState(
  67. float growthPercentage, ModelInfo* model);
  68. const Framework::RCArray<GrowthState>& getStates() const;
  69. void setBlockTypeNameAfterGrowth(Framework::Text blockTypeIdAfterGrowth);
  70. Framework::Text getBlockTypeNameAfterGrowth() const;
  71. void setReadableName(const char* readableName);
  72. const char* getReadableName() const;
  73. void setTicksNeeded(int ticksNeeded);
  74. int getTicksNeeded() const;
  75. void setTransparent(bool transparent);
  76. bool isTransparent() const;
  77. void setPassable(bool passable);
  78. bool isPassable() const;
  79. void setSpeedModifier(float speedModifier);
  80. float getSpeedModifier() const;
  81. void setInteractable(bool interactable);
  82. bool isInteractable() const;
  83. };
  84. class GrowingPlantBlockTypeFactory
  85. : public BlockTypeFactoryBase<GrowingPlantBlockType>
  86. {
  87. public:
  88. GrowingPlantBlockTypeFactory();
  89. GrowingPlantBlockType* createValue(
  90. Framework::JSON::JSONObject* zJson) const override;
  91. void fromJson(GrowingPlantBlockType* zResult,
  92. Framework::JSON::JSONObject* zJson) const override;
  93. void toJson(GrowingPlantBlockType* zObject,
  94. Framework::JSON::JSONObject* zResult) const override;
  95. JSONObjectValidationBuilder* addToValidator(
  96. JSONObjectValidationBuilder* builder) const override;
  97. Framework::Text getTypeToken() const override;
  98. };