LightSources.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "BlockType.h"
  3. #include "BasicBlocks.h"
  4. #include "Block.h"
  5. class BasicLightSourceBlockType;
  6. class LightSourceItemType;
  7. class LightSourceItem : public BasicBlockItem
  8. {
  9. protected:
  10. int color;
  11. public:
  12. LightSourceItem(const ItemType* zType, const BlockType* zPlacedBlockType, const char* name);
  13. virtual bool canBeStackedWith(const Item* zItem) const override;
  14. friend LightSourceItemType;
  15. friend BasicLightSourceBlockType;
  16. };
  17. class LightSourceItemType : public BasicBlockItemType
  18. {
  19. protected:
  20. LightSourceItemType(int id, const char* name, const ModelInfo model);
  21. virtual void loadSuperItem(Item* zItem, Framework::StreamReader* zReader) const override;
  22. virtual void saveSuperItem(const Item* zItem, Framework::StreamWriter* zWriter) const override;
  23. void initializeItem(LightSourceItem* zItem, int color, bool transparent = 1, bool passable = 1, float hardness = 0, int toolId = 0, float speedModifier = 1) const;
  24. };
  25. class BasicLightSource : public Block
  26. {
  27. protected:
  28. void setLight(int light);
  29. public:
  30. BasicLightSource(const BlockType* zType, Framework::Vec3<int> pos);
  31. virtual bool onTick(TickQueue* zQueue, int numTicks, bool& blocked) override;
  32. virtual void onPostTick() override;
  33. friend BasicLightSourceBlockType;
  34. };
  35. class BasicLightSourceBlockType : public BlockType
  36. {
  37. private:
  38. int itemType;
  39. protected:
  40. bool transparent;
  41. bool passable;
  42. float hardness;
  43. bool interactable;
  44. int color;
  45. BasicLightSourceBlockType(int typeId, int itemTypeId, ModelInfo model);
  46. virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
  47. virtual void loadSuperBlock(Block* zBlock, Framework::StreamReader* zReader) const override;
  48. virtual void saveSuperBlock(Block* zBlock, Framework::StreamWriter* zWriter) const override;
  49. public:
  50. virtual Block* createBlock(Framework::Vec3<int> position) const override;
  51. virtual Item* createItem() const override;
  52. };
  53. class TorchBlockItemType : public LightSourceItemType
  54. {
  55. REGISTRABLE(TorchBlockItemType)
  56. protected:
  57. TorchBlockItemType();
  58. public:
  59. virtual Item* createItem() const override;
  60. };
  61. REGISTER(TorchBlockItemType, ItemType)
  62. class TorchBlockType : public BasicLightSourceBlockType
  63. {
  64. REGISTRABLE(TorchBlockType)
  65. protected:
  66. TorchBlockType();
  67. };
  68. REGISTER(TorchBlockType, BlockType)