VoxelEngine
 
Loading...
Searching...
No Matches
Block.h
1#pragma once
2
3#include "BlockMaterial.h"
4#include "Globals.h"
5#include "Side.h"
6
7#include "Contexts.h"
8
9
10// #include "render/BlockMaterial.h"
11
12namespace engine {
13 class Geometry;
14
21 enum class RotationMode {
22 None,
23 AxisY,
24 AxisYSnap,
25 AxisXYZ,
26 AxisXYZSnap,
27 AxisAngleXYZSnap,
28 AxisAlign,
29 };
30
31 class Block {
32 public:
38 static constexpr BlockID AirID = 0;
39 static constexpr BlockID MultiblockID = 1;
40
41 Block(BlockID id, Layer layer, const Geometry* geo);
42 Block(BlockID id, Layer layer, const Geometry* geo, RotationMode rotationMode);
43 virtual ~Block() = default;
44
45 virtual bool onInteract(InteractContext* context) const { return false; };
46 virtual void onDestroyed(const BlockSetContext& context) const {};
47 virtual void onPlaced(const BlockSetContext& context) const {};
48
49 static Block& air();
50 static Block& multiblock();
51
52 bool isAir() const { return m_id == AirID; }
53 bool isMultiblock() const { return m_id == MultiblockID; }
54
55 BlockID getID() const { return m_id; }
56
57 const Geometry* geometry() const { return m_geometry; }
58
59 bool isSolid() const { return m_isSolid; }
60 bool isVoxel() const { return m_isVoxel; }
61 bool facingUp() const { return m_faceUp; }
62 Layer layer() const { return m_layer; }
63 RotationMode rotationMode() const { return m_rotationMode; }
64
65 Block& rotationMode(RotationMode mode);
66 Block& isSolid(bool solid);
67 Block& isVoxel(bool voxel);
69 Block& facingUp(bool state);
70
71 Block& material(const BlockMaterial& mat);
72 const BlockMaterial& material() const;
73
74 protected:
75 bool m_isSolid;
76 bool m_isVoxel;
77 bool m_faceUp = false;
78 Layer m_layer;
79 RotationMode m_rotationMode = RotationMode::None;
80
81 const Geometry* m_geometry;
82 BlockMaterial m_material;
83
84 private:
85 BlockID m_id;
86 };
87} // namespace engine
Definition Block.h:31
static constexpr BlockID AirID
Reserved block ID range: 0-8 (inclusive).
Definition Block.h:38
Definition Geometry.h:13
Definition Contexts.h:26
Definition Contexts.h:13