From 63bbe540bc1fb1695215b6abc783358653180290 Mon Sep 17 00:00:00 2001 From: alexei-zebra Date: Thu, 4 Jan 2024 00:19:06 +0300 Subject: [PATCH] add custom state and value --- src/voxels/voxel.h | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/voxels/voxel.h b/src/voxels/voxel.h index a2ace6a93..19d967836 100644 --- a/src/voxels/voxel.h +++ b/src/voxels/voxel.h @@ -25,11 +25,45 @@ struct voxel { inline void setDir(u_char8 dir) { states &= ~BLOCK_ROT_MASK; - states |= dir; - } + states |= dir; + } - inline u_char8 variant() const { - return (states & BLOCK_VARIANT_MASK) >> 4; + inline u_char8 getVariant() const { + return states & BLOCK_VARIANT_MASK; + } + + inline void setVariant(u_char8 variant) { + states &= ~BLOCK_VARIANT_MASK; + states |= variant; + } + + // id of the state in range 0 to 3 + inline bool getCustomState(u_char8 id) const { + return states & (1 << id+24); + } + + // id of the state in range 0 to 3 + inline void setCustomState(u_char8 id, bool state) { + if (state) { + states |= (1 << id+24); + } else { + states &= ~(1 << id+24); + } + } + + /* if the block has a custom state you + can use value in range 0 to 15 else + you can use value in range 0 to 255 */ + inline u_char8 getCustomValue() const { + return states >> 20; + } + + /* if the block has a custom state you + can use value in range 0 to 15 else + you can use value in range 0 to 255 */ + inline void setCustomValue(u_char8 value) { + states &= ~(0xF << 20); + states |= (value << 20); } };