From 8e153f6689880da1380af1bf9d858d1d3a8461bb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 20 Aug 2013 23:17:49 +0100 Subject: Fixed longstanding issue with slabs Fixes FS#298 --- source/Blocks/BlockSlab.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source/Blocks/BlockSlab.h') diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h index f34f42bae..dd80da27e 100644 --- a/source/Blocks/BlockSlab.h +++ b/source/Blocks/BlockSlab.h @@ -35,7 +35,18 @@ public: NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x07); switch (a_BlockFace) { - case BLOCK_FACE_TOP: a_BlockMeta = Meta & 0x7; break; // Always bottom half of the slab when placing on top of something + case BLOCK_FACE_TOP: + { + if (a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == E_BLOCK_STONE_SLAB) + { + a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_DOUBLE_STONE_SLAB, Meta); + a_BlockType = E_BLOCK_AIR; + } + else + { + a_BlockMeta = Meta & 0x7; break; // Always bottom half of the slab when placing on top of something + } + } case BLOCK_FACE_BOTTOM: a_BlockMeta = Meta | 0x8; break; // Always top half of the slab when placing on bottom of something case BLOCK_FACE_EAST: case BLOCK_FACE_NORTH: -- cgit v1.2.3 From 0c44904766ee835dc07a96d563d3d109fcda293a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 20 Aug 2013 23:24:29 +0100 Subject: Changed comments to be more accurate --- source/Blocks/BlockSlab.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/Blocks/BlockSlab.h') diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h index dd80da27e..44e1962b9 100644 --- a/source/Blocks/BlockSlab.h +++ b/source/Blocks/BlockSlab.h @@ -39,15 +39,15 @@ public: { if (a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == E_BLOCK_STONE_SLAB) { - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_DOUBLE_STONE_SLAB, Meta); - a_BlockType = E_BLOCK_AIR; + a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_DOUBLE_STONE_SLAB, Meta); //Set it to a slabby block + a_BlockType = E_BLOCK_AIR; //Stop the server trying to place another slab on top } else { - a_BlockMeta = Meta & 0x7; break; // Always bottom half of the slab when placing on top of something + a_BlockMeta = Meta & 0x7; break; //Bottom half if on top of non slab block } } - case BLOCK_FACE_BOTTOM: a_BlockMeta = Meta | 0x8; break; // Always top half of the slab when placing on bottom of something + case BLOCK_FACE_BOTTOM: a_BlockMeta = Meta | 0x8; break; //Always top when placing on bottom of something case BLOCK_FACE_EAST: case BLOCK_FACE_NORTH: case BLOCK_FACE_SOUTH: -- cgit v1.2.3 From a671e45cd55adc4ae477225e59afb2969454b1d4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 23 Aug 2013 19:38:39 +0100 Subject: Double slabs work *choke choke* --- source/Blocks/BlockSlab.h | 58 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 deletions(-) (limited to 'source/Blocks/BlockSlab.h') diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h index 44e1962b9..881a85615 100644 --- a/source/Blocks/BlockSlab.h +++ b/source/Blocks/BlockSlab.h @@ -6,7 +6,6 @@ - class cBlockSlabHandler : public cBlockHandler { @@ -19,7 +18,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - char Count = ((m_BlockType == E_BLOCK_DOUBLE_STONE_SLAB) || (m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? 2 : 1; + char Count = ((m_BlockType == E_BLOCK_STONE_SLAB) || (m_BlockType == E_BLOCK_WOODEN_SLAB)) ? 1 : 1; a_Pickups.push_back(cItem(m_BlockType, Count, a_BlockMeta)); } @@ -32,22 +31,46 @@ public: ) override { a_BlockType = m_BlockType; + BLOCKTYPE Type = (BLOCKTYPE)(a_Player->GetEquippedItem().m_ItemType); NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x07); + + int DoubleType; + if (Type == E_BLOCK_STONE_SLAB) + { + DoubleType = 43; //Make it a double slab (with old type wood) + } + else + { + DoubleType = 125; //Make it a wooden double slab (new type) + } + cItemHandler * ItemHandler = cItemHandler::GetItemHandler(DoubleType); + switch (a_BlockFace) { case BLOCK_FACE_TOP: { - if (a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ) == E_BLOCK_STONE_SLAB) + if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) { - a_World->FastSetBlock(a_BlockX, a_BlockY - 1, a_BlockZ, E_BLOCK_DOUBLE_STONE_SLAB, Meta); //Set it to a slabby block - a_BlockType = E_BLOCK_AIR; //Stop the server trying to place another slab on top + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); + return false; } else { a_BlockMeta = Meta & 0x7; break; //Bottom half if on top of non slab block } } - case BLOCK_FACE_BOTTOM: a_BlockMeta = Meta | 0x8; break; //Always top when placing on bottom of something + case BLOCK_FACE_BOTTOM: + { + if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) + { + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); + return false; + } + else + { + a_BlockMeta = Meta | 0x8; break; //Bottom half if on top of non slab block + } + } case BLOCK_FACE_EAST: case BLOCK_FACE_NORTH: case BLOCK_FACE_SOUTH: @@ -56,14 +79,29 @@ public: if (a_CursorY > 7) { // Cursor at the top half of the face, place a top half of slab - a_BlockMeta = Meta | 0x8; + if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) + { + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); + return false; + } + else + { + a_BlockMeta = Meta | 0x8; break; + } } else { // Cursor at the bottom half of the face, place a bottom half of slab: - a_BlockMeta = Meta & 0x7; + if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) + { + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); + return false; + } + else + { + a_BlockMeta = Meta & 0x7; break; + } } - break; } } // switch (a_BlockFace) return true; @@ -72,7 +110,7 @@ public: virtual const char * GetStepSound(void) override { - return ((m_BlockType == E_BLOCK_WOODEN_SLAB) || (m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? "step.wood" : "step.stone"; + return ((m_BlockType == E_BLOCK_WOODEN_SLAB) || (m_BlockType == E_BLOCK_STONE_SLAB)) ? "step.wood" : "step.stone"; } } ; -- cgit v1.2.3 From d1cc6d9a9cd76eca7ab98ef5253b29573f8d6959 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 24 Aug 2013 18:46:19 +0100 Subject: Added comments and fixed a bug Bug was placing slabs between slabs not making a double slab. --- source/Blocks/BlockSlab.h | 76 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 39 deletions(-) (limited to 'source/Blocks/BlockSlab.h') diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h index 881a85615..6caa3a27a 100644 --- a/source/Blocks/BlockSlab.h +++ b/source/Blocks/BlockSlab.h @@ -18,8 +18,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { - char Count = ((m_BlockType == E_BLOCK_STONE_SLAB) || (m_BlockType == E_BLOCK_WOODEN_SLAB)) ? 1 : 1; - a_Pickups.push_back(cItem(m_BlockType, Count, a_BlockMeta)); + a_Pickups.push_back(cItem(m_BlockType, 1, a_BlockMeta)); } @@ -37,39 +36,54 @@ public: int DoubleType; if (Type == E_BLOCK_STONE_SLAB) { - DoubleType = 43; //Make it a double slab (with old type wood) + DoubleType = 43; // Make it a double slab (with old type wood) } else { - DoubleType = 125; //Make it a wooden double slab (new type) + DoubleType = 125; // Make it a wooden double slab (new type) } + // HandlePlaceBlock wants a cItemHandler pointer thing, so let's give it one cItemHandler * ItemHandler = cItemHandler::GetItemHandler(DoubleType); - switch (a_BlockFace) + // Check if the block at the coordinates is a slab. Eligibility for combining etc. were processed in ClientHandle + BLOCKTYPE IsSlab; + IsSlab = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if ((IsSlab == E_BLOCK_STONE_SLAB) || (IsSlab == E_BLOCK_WOODEN_SLAB)) { - case BLOCK_FACE_TOP: + // Special handling for non top/bottom clicks + if ((a_BlockFace == BLOCK_FACE_TOP) || (a_BlockFace == BLOCK_FACE_BOTTOM)) { - if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) + // As with previous, call the function in ClientHandle that places a block when the client sends the packet + // This effectively simulates a client placing a double slab, so it goes through plugins etc. so the slabbing can be cancelled + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); + } + else + { + // If player cursor is at top half of block + if (a_CursorY > 7) { - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - return false; + // Edit the call to use BLOCK_FACE_BOTTOM, otherwise it places incorrectly + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_TOP, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } else { - a_BlockMeta = Meta & 0x7; break; //Bottom half if on top of non slab block + // Edit the call to use BLOCK_FACE_TOP, otherwise it places incorrectly + a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_BOTTOM, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); } } + return false; // Cancel the event because dblslabs were already placed, nothing else needed + } + + switch (a_BlockFace) + { + // Previous IF condition didn't cancel the event (not a slab at coords), so place slab with correct metas + case BLOCK_FACE_TOP: + { + a_BlockMeta = Meta & 0x7; break; // Bottom half slab block + } case BLOCK_FACE_BOTTOM: { - if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) - { - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - return false; - } - else - { - a_BlockMeta = Meta | 0x8; break; //Bottom half if on top of non slab block - } + a_BlockMeta = Meta | 0x8; break; // Top half slab block } case BLOCK_FACE_EAST: case BLOCK_FACE_NORTH: @@ -78,29 +92,13 @@ public: { if (a_CursorY > 7) { - // Cursor at the top half of the face, place a top half of slab - if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) - { - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - return false; - } - else - { - a_BlockMeta = Meta | 0x8; break; - } + // Cursor at top half of block, place top slab + a_BlockMeta = Meta | 0x8; break; } else { - // Cursor at the bottom half of the face, place a bottom half of slab: - if ((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB)) - { - a_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler); - return false; - } - else - { - a_BlockMeta = Meta & 0x7; break; - } + // Cursor at bottom half of block, place bottom slab + a_BlockMeta = Meta & 0x7; break; } } } // switch (a_BlockFace) -- cgit v1.2.3