FluidBlock.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #include "Block.h"
  3. #include "TickQueue.h"
  4. class FluidBlockType;
  5. class FluidContainerItem;
  6. class FluidBlock : public Block
  7. {
  8. private:
  9. char flowOptions;
  10. char distanceToSource;
  11. int nextFlow;
  12. Framework::Vec3<float> lightWeights;
  13. bool neighborChanged;
  14. unsigned char maxFlowDistance;
  15. protected:
  16. virtual bool onTick(
  17. TickQueue* zQueue, int numTicks, bool& blocked) override;
  18. virtual void onPostTick() override;
  19. void doFlow();
  20. public:
  21. FluidBlock(int typeId,
  22. Framework::Vec3<int> pos,
  23. int dimensionId,
  24. Framework::Vec3<float> lightWeights);
  25. virtual ~FluidBlock();
  26. virtual void setNeighbourType(Direction dir, int type) override;
  27. virtual void sendModelInfo(NetworkMessage* zMessage) override;
  28. virtual bool isInteractable(const Item* zItem) const override;
  29. virtual void filterPassingLight(unsigned char rgb[3]) const override;
  30. virtual TickSourceType isTickSource() const override;
  31. virtual bool needsTick() const override;
  32. char getDistanceToSource() const;
  33. char getFlowOptions() const;
  34. friend FluidBlockType;
  35. };
  36. class FluidBlockType : public BlockType
  37. {
  38. private:
  39. Framework::Vec3<float> lightWeights;
  40. int ticktsToFlow;
  41. unsigned char flowDistance;
  42. float hungerRecoveryPerL;
  43. float thirstRecoveryPerL;
  44. float heat;
  45. public:
  46. FluidBlockType();
  47. protected:
  48. virtual void loadSuperBlock(Block* zBlock,
  49. Framework::StreamReader* zReader,
  50. int dimensionId) const override;
  51. virtual void saveSuperBlock(
  52. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  53. virtual Item* createItem() const override;
  54. virtual Block* createBlock(
  55. Framework::Vec3<int> position, int dimesionId) const override;
  56. public:
  57. bool isFluid() const override;
  58. virtual ItemType* createItemType() const override;
  59. void setTicktsToFlow(int ticksToFlow);
  60. int getTicktsToFlow() const;
  61. void setFlowDistance(unsigned char flowDistance);
  62. unsigned char getFlowDistance() const override;
  63. void setLightWeights(Framework::Vec3<float> lightWeights);
  64. Framework::Vec3<float> getLightWeights() const;
  65. void setHungerRecoveryPerL(float hungerRecoveryPerL);
  66. float getHungerRecoveryPerL() const;
  67. void setThirstRecoveryPerL(float thirstRecoveryPerL);
  68. float getThirstRecoveryPerL() const;
  69. void setHeat(float heat);
  70. float getHeat() const;
  71. };
  72. class FluidBlockTypeFactory : public BlockTypeFactoryBase<FluidBlockType>
  73. {
  74. public:
  75. FluidBlockTypeFactory();
  76. FluidBlockType* createValue(
  77. Framework::JSON::JSONObject* zJson) const override;
  78. void fromJson(FluidBlockType* zResult,
  79. Framework::JSON::JSONObject* zJson) const override;
  80. void toJson(FluidBlockType* zObject,
  81. Framework::JSON::JSONObject* zResult) const override;
  82. JSONObjectValidationBuilder* addToValidator(
  83. JSONObjectValidationBuilder* builder) const override;
  84. Framework::Text getTypeToken() const override;
  85. };