LightSources.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include "BasicBlocks.h"
  3. #include "Block.h"
  4. #include "BlockType.h"
  5. class BasicLightSourceBlockType;
  6. class LightSourceItemType;
  7. class LightSourceItem : public BasicBlockItem
  8. {
  9. protected:
  10. int color;
  11. public:
  12. LightSourceItem(int itemType, int blockType, Framework::Text name);
  13. virtual bool canBeStackedWith(const Item* zItem) const override;
  14. friend LightSourceItemType;
  15. friend BasicLightSourceBlockType;
  16. };
  17. class LightSourceItemType : public BasicBlockItemType
  18. {
  19. private:
  20. int color;
  21. public:
  22. LightSourceItemType(Framework::Text name,
  23. ModelInfo* model,
  24. Framework::Text blockTypeName,
  25. int maxStackSize,
  26. Framework::RCArray<Framework::Text> groups);
  27. protected:
  28. virtual void loadSuperItem(
  29. Item* zItem, Framework::StreamReader* zReader) const override;
  30. virtual void saveSuperItem(
  31. const Item* zItem, Framework::StreamWriter* zWriter) const override;
  32. virtual Item* createItem() const override;
  33. public:
  34. LightSourceItemType* setColor(int color);
  35. };
  36. class BasicLightSource : public Block
  37. {
  38. public:
  39. BasicLightSource(int typeId, Framework::Vec3<int> pos, int dimensionId);
  40. protected:
  41. void setLight(int light);
  42. public:
  43. virtual bool onTick(
  44. TickQueue* zQueue, int numTicks, bool& blocked) override;
  45. virtual void onPostTick() override;
  46. friend BasicLightSourceBlockType;
  47. };
  48. class BasicLightSourceBlockType : public BlockType
  49. {
  50. private:
  51. Framework::Text itemTypeName;
  52. int itemTypeId;
  53. bool transparent;
  54. bool passable;
  55. bool interactable;
  56. int lightColor;
  57. public:
  58. BasicLightSourceBlockType();
  59. protected:
  60. virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
  61. virtual void loadSuperBlock(Block* zBlock,
  62. Framework::StreamReader* zReader,
  63. int dimensionId) const override;
  64. virtual void saveSuperBlock(
  65. Block* zBlock, Framework::StreamWriter* zWriter) const override;
  66. public:
  67. virtual bool initialize(Game* zGame) override;
  68. virtual Block* createBlock(
  69. Framework::Vec3<int> position, int dimensionId) const override;
  70. virtual Item* createItem() const override;
  71. virtual ItemType* createItemType() const override;
  72. void setItemTypeName(Framework::Text itemTypeName);
  73. Framework::Text getItemTypeName() const;
  74. void setTransparent(bool transparent);
  75. bool isTransparent() const;
  76. void setPassable(bool passable);
  77. bool isPassable() const;
  78. void setInteractable(bool interactable);
  79. bool isInteractable() const;
  80. void setLightColor(int lightColor);
  81. int getLightColor() const;
  82. };
  83. class BasicLightSourceBlockTypeFactory
  84. : public BlockTypeFactoryBase<BasicLightSourceBlockType>
  85. {
  86. public:
  87. BasicLightSourceBlockTypeFactory();
  88. BasicLightSourceBlockType* createValue(
  89. Framework::JSON::JSONObject* zJson) const override;
  90. void fromJson(BasicLightSourceBlockType* zResult,
  91. Framework::JSON::JSONObject* zJson) const override;
  92. void toJson(BasicLightSourceBlockType* zObject,
  93. Framework::JSON::JSONObject* zResult) const override;
  94. JSONObjectValidationBuilder* addToValidator(
  95. JSONObjectValidationBuilder* builder) const override;
  96. Framework::Text getTypeToken() const override;
  97. };