GrowingPlant.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include "Block.h"
  3. class GrowingPlantBlockType;
  4. struct GrowthState
  5. {
  6. GrowthState();
  7. GrowthState(float percentage, ModelInfo model);
  8. GrowthState(const GrowthState& right);
  9. GrowthState& operator=(const GrowthState& right);
  10. float percentage;
  11. ModelInfo model;
  12. };
  13. class GrowingPlantBlock : public Block
  14. {
  15. private:
  16. float seblingTicks;
  17. int seblingTicksMax;
  18. const char* name;
  19. Framework::Array<GrowthState> states;
  20. int blockTypeAfterGrowth;
  21. bool plantSpawned;
  22. public:
  23. GrowingPlantBlock(int typeId,
  24. const ItemType* zTool,
  25. Framework::Vec3<int> pos,
  26. int dimensionId,
  27. int maxTicks,
  28. const char* name,
  29. int blockTypeAfterGrowth);
  30. virtual bool onTick(
  31. TickQueue* zQueue, int numTicks, bool& blocked) override;
  32. virtual void onPostTick() override;
  33. virtual void sendModelInfo(NetworkMessage* zMessage) override;
  34. virtual Framework::Text getTargetUIML();
  35. GrowingPlantBlock* addGrowthState(GrowthState state);
  36. friend GrowingPlantBlockType;
  37. };
  38. class GrowingPlantBlockType : public BlockType
  39. {
  40. private:
  41. bool transparent;
  42. bool passable;
  43. float hardness;
  44. const ItemType* zTool;
  45. float speedModifier;
  46. bool interactable;
  47. Framework::Array<GrowthState> states;
  48. int blockTypeAfterGrowth;
  49. const char* readableName;
  50. int ticksNeeded;
  51. protected:
  52. virtual void loadSuperBlock(Block* zBlock,
  53. Framework::StreamReader* zReader,
  54. int dimensionId) const override;
  55. void createSuperBlock(Block* zBlock, Item* zItem) const override;
  56. virtual void saveSuperBlock(
  57. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  58. virtual Item* createItem() const override;
  59. virtual Block* createBlock(
  60. Framework::Vec3<int> position, int dimensionId) const override;
  61. public:
  62. GrowingPlantBlockType(int typeId,
  63. ModelInfo model,
  64. const char* name,
  65. int blockTypeAfterGrowth,
  66. const char* readableName,
  67. int ticksNeeded,
  68. int mapColor);
  69. GrowingPlantBlockType* setHardness(float hardness);
  70. GrowingPlantBlockType* addGrowthState(
  71. float growthPercentage, ModelInfo model);
  72. };