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/BlockTorch.h | 54 +++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'src/Blocks/BlockTorch.h') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 0b96ad246..ad69cf5eb 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -1,8 +1,12 @@ #pragma once #include "BlockHandler.h" +#include "BlockSlab.h" +#include "BlockStairs.h" #include "../Chunk.h" +#include "BlockType.h" #include "ChunkInterface.h" +#include "Defines.h" #include "Mixins.h" @@ -22,6 +26,34 @@ public: /** Returns true if the torch can be placed on the specified block's face. */ static bool CanBePlacedOn(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_BlockFace) { + // upside down slabs + if (cBlockSlabHandler::IsAnySlabType(a_BlockType)) + { + return (a_BlockFace == BLOCK_FACE_YP) && (a_BlockMeta & E_META_WOODEN_SLAB_UPSIDE_DOWN); + } + + // stairs (top and sides) + if (cBlockStairsHandler::IsAnyStairType(a_BlockType)) + { + switch (a_BlockFace) + { + case eBlockFace::BLOCK_FACE_YP: + return (a_BlockMeta & E_BLOCK_STAIRS_UPSIDE_DOWN); + case eBlockFace::BLOCK_FACE_XP: + return ((a_BlockMeta & 0b11) == E_BLOCK_STAIRS_XP); + case eBlockFace::BLOCK_FACE_XM: + return ((a_BlockMeta & 0b11) == E_BLOCK_STAIRS_XM); + case eBlockFace::BLOCK_FACE_ZP: + return ((a_BlockMeta & 0b11) == E_BLOCK_STAIRS_ZP); + case eBlockFace::BLOCK_FACE_ZM: + return ((a_BlockMeta & 0b11) == E_BLOCK_STAIRS_ZM); + default: + { + return false; + } + } + } + switch (a_BlockType) { case E_BLOCK_END_PORTAL_FRAME: @@ -44,28 +76,6 @@ public: // Torches can only be placed on top of these blocks return (a_BlockFace == BLOCK_FACE_YP); } - case E_BLOCK_STONE_SLAB: - case E_BLOCK_WOODEN_SLAB: - { - // Toches can be placed only on the top of top-half-slabs - return ((a_BlockFace == BLOCK_FACE_YP) && ((a_BlockMeta & 0x08) == 0x08)); - } - case E_BLOCK_OAK_WOOD_STAIRS: - case E_BLOCK_COBBLESTONE_STAIRS: - case E_BLOCK_BRICK_STAIRS: - case E_BLOCK_STONE_BRICK_STAIRS: - case E_BLOCK_NETHER_BRICK_STAIRS: - case E_BLOCK_SANDSTONE_STAIRS: - case E_BLOCK_SPRUCE_WOOD_STAIRS: - case E_BLOCK_BIRCH_WOOD_STAIRS: - case E_BLOCK_JUNGLE_WOOD_STAIRS: - case E_BLOCK_QUARTZ_STAIRS: - case E_BLOCK_ACACIA_WOOD_STAIRS: - case E_BLOCK_DARK_OAK_WOOD_STAIRS: - case E_BLOCK_RED_SANDSTONE_STAIRS: - { - return (a_BlockFace == BLOCK_FACE_TOP) && (a_BlockMeta & E_BLOCK_STAIRS_UPSIDE_DOWN); - } default: { if (cBlockInfo::FullyOccupiesVoxel(a_BlockType)) -- cgit v1.2.3