From 7fdfb8644169a25805afd32f00ced38c1c14cec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Havl=C3=AD=C4=8Dek?= <80639037+havel06@users.noreply.github.com> Date: Wed, 25 Jan 2023 21:46:34 +0100 Subject: Allow certain blocks to be placed on top of upside-down stairs/slabs (#5468) * Placing certain blocks on top of upside down slabs and stairs * remove TODO * fix style errors * IsAnyStairType helper function * Block placement on stairs and slabs --- src/Blocks/BlockRail.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/Blocks/BlockRail.h') diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 6c4367334..4e2e6211f 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -1,6 +1,14 @@ - #pragma once +#include "BlockHandler.h" +#include "BlockSlab.h" +#include "BlockStairs.h" +#include "BlockType.h" +#include "Blocks/Mixins.h" +#include "../BlockInfo.h" +#include "../Chunk.h" +#include "ChunkDef.h" + @@ -154,9 +162,26 @@ public: private: + static bool CanBeSupportedBy(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) + { + if (cBlockSlabHandler::IsAnySlabType(a_BlockType)) + { + return (a_BlockMeta & E_META_WOODEN_SLAB_UPSIDE_DOWN); + } + else if (cBlockStairsHandler::IsAnyStairType(a_BlockType)) + { + return (a_BlockMeta & E_BLOCK_STAIRS_UPSIDE_DOWN); + } + return cBlockInfo::FullyOccupiesVoxel(a_BlockType); + } + virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, NIBBLETYPE a_Meta) const override { - if ((a_Position.y <= 0) || !cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(a_Position.addedY(-1)))) + BLOCKTYPE BelowBlock; + NIBBLETYPE BelowBlockMeta; + a_Chunk.GetBlockTypeMeta(a_Position.addedY(-1), BelowBlock, BelowBlockMeta); + + if ((a_Position.y <= 0) || !CanBeSupportedBy(BelowBlock, BelowBlockMeta)) { return false; } @@ -187,6 +212,7 @@ private: return cBlockInfo::FullyOccupiesVoxel(BlockType); } } + return true; } -- cgit v1.2.3