FluidBlock.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. char getDistanceToSource() const;
  31. char getFlowOptions() const;
  32. friend FluidBlockType;
  33. };
  34. class FluidBlockType : public BlockType
  35. {
  36. private:
  37. Framework::Vec3<float> lightWeights;
  38. int ticktsToFlow;
  39. unsigned char flowDistance;
  40. float hungerRecoveryPerL;
  41. float thirstRecoveryPerL;
  42. float heat;
  43. public:
  44. FluidBlockType();
  45. protected:
  46. virtual void loadSuperBlock(Block* zBlock,
  47. Framework::StreamReader* zReader,
  48. int dimensionId) const override;
  49. virtual void saveSuperBlock(
  50. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  51. virtual Item* createItem() const override;
  52. virtual Block* createBlock(
  53. Framework::Vec3<int> position, int dimesionId) const override;
  54. public:
  55. bool isFluid() const override;
  56. virtual ItemType* createItemType() const override;
  57. void setTicktsToFlow(int ticksToFlow);
  58. int getTicktsToFlow() const;
  59. void setFlowDistance(unsigned char flowDistance);
  60. unsigned char getFlowDistance() const override;
  61. void setLightWeights(Framework::Vec3<float> lightWeights);
  62. Framework::Vec3<float> getLightWeights() const;
  63. void setHungerRecoveryPerL(float hungerRecoveryPerL);
  64. float getHungerRecoveryPerL() const;
  65. void setThirstRecoveryPerL(float thirstRecoveryPerL);
  66. float getThirstRecoveryPerL() const;
  67. void setHeat(float heat);
  68. float getHeat() const;
  69. };
  70. class FluidBlockTypeFactory : public BlockTypeFactoryBase<FluidBlockType>
  71. {
  72. public:
  73. FluidBlockTypeFactory();
  74. FluidBlockType* createValue(
  75. Framework::JSON::JSONObject* zJson) const override;
  76. void fromJson(FluidBlockType* zResult,
  77. Framework::JSON::JSONObject* zJson) const override;
  78. void toJson(FluidBlockType* zObject,
  79. Framework::JSON::JSONObject* zResult) const override;
  80. JSONObjectValidationBuilder* addToValidator(
  81. JSONObjectValidationBuilder* builder) const override;
  82. Framework::Text getTypeToken() const override;
  83. };