From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/shared/item/block.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/shared/item/block.hh (limited to 'src/shared/item/block.hh') 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::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 + block(const enum shared::world::block::type& type, Args&&... args) noexcept + : item(get_type(type), std::forward(args)...), type(type) {} + + template + block(const shared::item::item::type_t& type, Args&&... args) noexcept + : item(type, std::forward(args)...), + type(static_cast(type - + type_offset)) {} + virtual ~block() noexcept {} +}; + +} // namespace item +} // namespace shared + +#endif -- cgit v1.2.3