diff options
Diffstat (limited to 'src/shared/item/block.hh')
| -rw-r--r-- | src/shared/item/block.hh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/shared/item/block.hh b/src/shared/item/block.hh new file mode 100644 index 0000000..2aa7cef --- /dev/null +++ b/src/shared/item/block.hh @@ -0,0 +1,41 @@ +#ifndef SHARED_ITEM_BLOCK_HH_ +#define SHARED_ITEM_BLOCK_HH_ + +#include "shared/item/item.hh" +#include "shared/world/block.hh" + +namespace shared { +namespace item { + +class block : virtual public shared::item::item { +public: + // Blocks are offset by 256 in their type so they do not collide with tools + // I'd prefer it was the other way around so TODO + static constexpr auto type_offset{std::numeric_limits<std::uint8_t>::max()}; + +public: + enum shared::world::block::type type; + +public: + static type_t get_type(const enum shared::world::block::type&) noexcept; + +public: + virtual type_t get_type() const noexcept; + +public: + template <typename... Args> + block(const enum shared::world::block::type& type, Args&&... args) noexcept + : item(get_type(type), std::forward<Args>(args)...), type(type) {} + + template <typename... Args> + block(const shared::item::item::type_t& type, Args&&... args) noexcept + : item(type, std::forward<Args>(args)...), + type(static_cast<enum shared::world::block::type>(type - + type_offset)) {} + virtual ~block() noexcept {} +}; + +} // namespace item +} // namespace shared + +#endif |
