BasicBlocks.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "Block.h"
  3. #include "BlockType.h"
  4. #include "Item.h"
  5. #include "TypeRegistry.h"
  6. class BlockType;
  7. class ItemType;
  8. class BasicBlockType;
  9. class BasicBlock : public Block
  10. {
  11. public:
  12. BasicBlock(int typeId, Framework::Vec3<int> pos, int dimensionId);
  13. BasicBlock(int typeId,
  14. Framework::Vec3<int> pos,
  15. int dimensionId,
  16. bool hasInventory);
  17. virtual bool onTick(
  18. TickQueue* zQueue, int numTicks, bool& blocked) override;
  19. virtual void onPostTick() override;
  20. friend BasicBlockType;
  21. };
  22. struct SpawnConfig
  23. {
  24. int min;
  25. int max;
  26. double chance;
  27. Framework::Text itemTypeName;
  28. int typeId;
  29. };
  30. class BasicBlockType : public BlockType
  31. {
  32. private:
  33. Framework::Text itemTypeName;
  34. int itemTypeId;
  35. bool transparent;
  36. bool passable;
  37. float speedModifier;
  38. bool interactable;
  39. protected:
  40. virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
  41. public:
  42. BasicBlockType();
  43. virtual bool initialize(Game* zGame) override;
  44. virtual Block* createBlock(
  45. Framework::Vec3<int> position, int dimensionId) const override;
  46. virtual Item* createItem() const override;
  47. Framework::Text getItemTypeName() const;
  48. virtual ItemType* createItemType() const override;
  49. void setItemTypeName(Framework::Text itemTypeName);
  50. int getItemTypeId() const;
  51. void setTransparent(bool transparent);
  52. bool isTransparent() const;
  53. void setPassable(bool passable);
  54. bool isPassable() const;
  55. void setSpeedModifier(float speedModifier);
  56. float getSpeedModifier() const;
  57. void setInteractable(bool interactable);
  58. bool isInteractable() const;
  59. };
  60. class BasicBlockTypeFactory : public BlockTypeFactoryBase<BasicBlockType>
  61. {
  62. public:
  63. BasicBlockTypeFactory();
  64. BasicBlockType* createValue(
  65. Framework::JSON::JSONObject* zJson) const override;
  66. void fromJson(BasicBlockType* zResult,
  67. Framework::JSON::JSONObject* zJson) const override;
  68. void toJson(BasicBlockType* zObject,
  69. Framework::JSON::JSONObject* zResult) const override;
  70. JSONObjectValidationBuilder* addToValidator(
  71. JSONObjectValidationBuilder* builder) const override;
  72. Framework::Text getTypeToken() const override;
  73. };
  74. class AdditionalItemSpawningBlock : public BasicBlock
  75. {
  76. private:
  77. Framework::Array<SpawnConfig> spawns;
  78. public:
  79. AdditionalItemSpawningBlock(
  80. int typeId, Framework::Vec3<int> pos, int dimensionId);
  81. void addSpawn(SpawnConfig config);
  82. virtual void onDestroy() override;
  83. };
  84. class AdditionalItemSpawningBlockType : public BasicBlockType
  85. {
  86. private:
  87. Framework::Array<SpawnConfig> spawns;
  88. public:
  89. AdditionalItemSpawningBlockType();
  90. protected:
  91. virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
  92. public:
  93. virtual bool initialize(Game* zGame) override;
  94. virtual Block* createBlock(
  95. Framework::Vec3<int> position, int dimensionId) const override;
  96. void addSpawn(SpawnConfig config);
  97. const Framework::Array<SpawnConfig>& getSpawns() const;
  98. };
  99. class AdditionalItemSpawningBlockTypeFactory
  100. : public BlockTypeFactoryBase<AdditionalItemSpawningBlockType>
  101. {
  102. private:
  103. BasicBlockTypeFactory super;
  104. public:
  105. AdditionalItemSpawningBlockTypeFactory();
  106. AdditionalItemSpawningBlockType* createValue(
  107. Framework::JSON::JSONObject* zJson) const override;
  108. void fromJson(AdditionalItemSpawningBlockType* zResult,
  109. Framework::JSON::JSONObject* zJson) const override;
  110. void toJson(AdditionalItemSpawningBlockType* zObject,
  111. Framework::JSON::JSONObject* zResult) const override;
  112. JSONObjectValidationBuilder* addToValidator(
  113. JSONObjectValidationBuilder* builder) const override;
  114. Framework::Text getTypeToken() const override;
  115. };