BasicBlocks.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. class BasicBlockType : public BlockType
  23. {
  24. private:
  25. Framework::Text itemTypeName;
  26. int itemTypeId;
  27. bool transparent;
  28. bool passable;
  29. float speedModifier;
  30. bool interactable;
  31. protected:
  32. virtual void createSuperBlock(Block* zBlock, Item* zItem) const override;
  33. public:
  34. BasicBlockType();
  35. virtual bool initialize(Game* zGame) override;
  36. virtual Block* createBlock(
  37. Framework::Vec3<int> position, int dimensionId) const override;
  38. virtual Item* createItem() const override;
  39. Framework::Text getItemTypeName() const;
  40. virtual ItemType* createItemType() const override;
  41. void setItemTypeName(Framework::Text itemTypeName);
  42. int getItemTypeId() const;
  43. void setTransparent(bool transparent);
  44. bool isTransparent() const;
  45. void setPassable(bool passable);
  46. bool isPassable() const;
  47. void setSpeedModifier(float speedModifier);
  48. float getSpeedModifier() const;
  49. void setInteractable(bool interactable);
  50. bool isInteractable() const;
  51. };
  52. class BasicBlockTypeFactory : public BlockTypeFactoryBase<BasicBlockType>
  53. {
  54. public:
  55. BasicBlockTypeFactory();
  56. virtual BasicBlockType* createValue(
  57. Framework::JSON::JSONObject* zJson) const override;
  58. virtual BasicBlockType* fromJson(
  59. Framework::JSON::JSONObject* zJson) const override;
  60. virtual Framework::JSON::JSONObject* toJsonObject(
  61. BasicBlockType* zObject) const override;
  62. virtual JSONObjectValidationBuilder* addToValidator(
  63. JSONObjectValidationBuilder* builder) const override;
  64. virtual const char* getTypeToken() const override;
  65. };