FluidBlock.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. unsigned char maxFlowDistance;
  14. protected:
  15. virtual bool onTick(
  16. TickQueue* zQueue, int numTicks, bool& blocked) override;
  17. virtual void onPostTick() override;
  18. void doFlow();
  19. public:
  20. FluidBlock(int typeId,
  21. Framework::Vec3<int> pos,
  22. int dimensionId,
  23. Framework::Vec3<float> lightWeights);
  24. virtual ~FluidBlock();
  25. virtual void sendModelInfo(NetworkMessage* zMessage) override;
  26. virtual bool isInteractable(const Item* zItem) const override;
  27. virtual void filterPassingLight(unsigned char rgb[3]) const override;
  28. virtual TickSourceType isTickSource() const override;
  29. virtual bool needsTick() 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. FluidBlockType* fromJson(Framework::JSON::JSONObject* zJson) const override;
  77. Framework::JSON::JSONObject* toJsonObject(
  78. FluidBlockType* zObject) const override;
  79. JSONObjectValidationBuilder* addToValidator(
  80. JSONObjectValidationBuilder* builder) const override;
  81. const char* getTypeToken() const override;
  82. };