Double slabs work *choke choke*
parent
52d8da6ebe
commit
a671e45cd5
|
@ -2015,6 +2015,9 @@
|
||||||
RelativePath="..\source\Blocks\BlockDeadBush.h"
|
RelativePath="..\source\Blocks\BlockDeadBush.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\source\Blocks\BlockDoubleSlab.h"
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\source\blocks\BlockDirt.h"
|
RelativePath="..\source\blocks\BlockDirt.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "BlockHandler.h"
|
||||||
|
#include "../Items/ItemHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cBlockDoubleSlabHandler :
|
||||||
|
public cBlockHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
cBlockDoubleSlabHandler(BLOCKTYPE a_BlockType)
|
||||||
|
: cBlockHandler(a_BlockType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
a_Pickups.push_back(cItem(m_BlockType, Count, a_BlockMeta));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual const char * GetStepSound(void) override
|
||||||
|
{
|
||||||
|
return ((m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB) || (m_BlockType == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? "step.wood" : "step.stone";
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "BlockDeadBush.h"
|
#include "BlockDeadBush.h"
|
||||||
#include "BlockDirt.h"
|
#include "BlockDirt.h"
|
||||||
#include "BlockDoor.h"
|
#include "BlockDoor.h"
|
||||||
|
#include "BlockDoubleSlab.h"
|
||||||
#include "BlockDropSpenser.h"
|
#include "BlockDropSpenser.h"
|
||||||
#include "BlockEnderchest.h"
|
#include "BlockEnderchest.h"
|
||||||
#include "BlockEntity.h"
|
#include "BlockEntity.h"
|
||||||
|
@ -117,8 +118,8 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
||||||
case E_BLOCK_DIAMOND_ORE: return new cBlockOreHandler (a_BlockType);
|
case E_BLOCK_DIAMOND_ORE: return new cBlockOreHandler (a_BlockType);
|
||||||
case E_BLOCK_DIRT: return new cBlockDirtHandler (a_BlockType);
|
case E_BLOCK_DIRT: return new cBlockDirtHandler (a_BlockType);
|
||||||
case E_BLOCK_DISPENSER: return new cBlockDropSpenserHandler (a_BlockType);
|
case E_BLOCK_DISPENSER: return new cBlockDropSpenserHandler (a_BlockType);
|
||||||
case E_BLOCK_DOUBLE_STONE_SLAB: return new cBlockSlabHandler (a_BlockType);
|
case E_BLOCK_DOUBLE_STONE_SLAB: return new cBlockDoubleSlabHandler (a_BlockType);
|
||||||
case E_BLOCK_DOUBLE_WOODEN_SLAB: return new cBlockSlabHandler (a_BlockType);
|
case E_BLOCK_DOUBLE_WOODEN_SLAB: return new cBlockDoubleSlabHandler (a_BlockType);
|
||||||
case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType);
|
case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType);
|
||||||
case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType);
|
case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType);
|
||||||
case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType);
|
case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType);
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cBlockSlabHandler :
|
class cBlockSlabHandler :
|
||||||
public cBlockHandler
|
public cBlockHandler
|
||||||
{
|
{
|
||||||
|
@ -19,7 +18,7 @@ public:
|
||||||
|
|
||||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
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));
|
a_Pickups.push_back(cItem(m_BlockType, Count, a_BlockMeta));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,22 +31,46 @@ public:
|
||||||
) override
|
) override
|
||||||
{
|
{
|
||||||
a_BlockType = m_BlockType;
|
a_BlockType = m_BlockType;
|
||||||
|
BLOCKTYPE Type = (BLOCKTYPE)(a_Player->GetEquippedItem().m_ItemType);
|
||||||
NIBBLETYPE Meta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x07);
|
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)
|
switch (a_BlockFace)
|
||||||
{
|
{
|
||||||
case BLOCK_FACE_TOP:
|
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_Player->GetClientHandle()->HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
|
||||||
a_BlockType = E_BLOCK_AIR; //Stop the server trying to place another slab on top
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a_BlockMeta = Meta & 0x7; break; //Bottom half if on top of non slab block
|
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_EAST:
|
||||||
case BLOCK_FACE_NORTH:
|
case BLOCK_FACE_NORTH:
|
||||||
case BLOCK_FACE_SOUTH:
|
case BLOCK_FACE_SOUTH:
|
||||||
|
@ -56,14 +79,29 @@ public:
|
||||||
if (a_CursorY > 7)
|
if (a_CursorY > 7)
|
||||||
{
|
{
|
||||||
// Cursor at the top half of the face, place a top half of slab
|
// 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
|
else
|
||||||
{
|
{
|
||||||
// Cursor at the bottom half of the face, place a bottom half of slab:
|
// 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)
|
} // switch (a_BlockFace)
|
||||||
return true;
|
return true;
|
||||||
|
@ -72,7 +110,7 @@ public:
|
||||||
|
|
||||||
virtual const char * GetStepSound(void) override
|
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";
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
|
@ -846,33 +846,62 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c
|
||||||
}
|
}
|
||||||
|
|
||||||
cWorld * World = m_Player->GetWorld();
|
cWorld * World = m_Player->GetWorld();
|
||||||
|
|
||||||
// Check if the block ignores build collision (water, grass etc.):
|
BLOCKTYPE ClickedBlock;
|
||||||
BLOCKTYPE ClickedBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
NIBBLETYPE ClickedBlockMeta;
|
||||||
cBlockHandler * Handler = cBlockHandler::GetBlockHandler(ClickedBlock);
|
BLOCKTYPE EquippedBlock = (BLOCKTYPE)(m_Player->GetEquippedItem().m_ItemType);
|
||||||
if (Handler->DoesIgnoreBuildCollision())
|
NIBBLETYPE EquippedBlockDamage = (NIBBLETYPE)(m_Player->GetEquippedItem().m_ItemDamage);
|
||||||
|
|
||||||
|
World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedBlockMeta);
|
||||||
|
|
||||||
|
//Special slab handler coding
|
||||||
|
if (
|
||||||
|
((a_BlockFace == BLOCK_FACE_TOP) || (a_BlockFace == BLOCK_FACE_BOTTOM)) &&
|
||||||
|
((ClickedBlock == E_BLOCK_STONE_SLAB) || (ClickedBlock == E_BLOCK_WOODEN_SLAB)) && //Is clicked a slab?
|
||||||
|
((EquippedBlock == E_BLOCK_STONE_SLAB) || (EquippedBlock == E_BLOCK_WOODEN_SLAB)) && //Is equipped a slab?
|
||||||
|
((ClickedBlockMeta & 0x07) == (EquippedBlockDamage & 0x07)) //Is clicked same type of slab as item in hand?
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
//Don't move the coordinates
|
||||||
// World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
//Check if the block ignores build collision (water, grass etc.):
|
||||||
// Check for Blocks not allowing placement on top
|
cBlockHandler * Handler = cBlockHandler::GetBlockHandler(ClickedBlock);
|
||||||
if ((a_BlockFace == BLOCK_FACE_TOP) && !Handler->DoesAllowBlockOnTop())
|
if (Handler->DoesIgnoreBuildCollision())
|
||||||
{
|
{
|
||||||
// Resend the old block
|
Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
|
||||||
// Some times the client still places the block O.o
|
//World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
|
||||||
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
|
||||||
BLOCKTYPE PlaceBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
|
||||||
if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision())
|
|
||||||
{
|
{
|
||||||
// Tried to place a block *into* another?
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||||
return; // Happens when you place a block aiming at side of block like torch or stem
|
//On side of block, make sure that placement won't be cancelled if there is a slab there
|
||||||
|
//No need to combinability checks, client will do that
|
||||||
|
if ((World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_STONE_SLAB) || (World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_SLAB))
|
||||||
|
{
|
||||||
|
//Is a slab, don't do checks and proceed to double-slabbing
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check for Blocks not allowing placement on top
|
||||||
|
if ((a_BlockFace == BLOCK_FACE_TOP) && !Handler->DoesAllowBlockOnTop())
|
||||||
|
{
|
||||||
|
// Resend the old block
|
||||||
|
// Some times the client still places the block O.o
|
||||||
|
World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BLOCKTYPE PlaceBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
|
||||||
|
if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision())
|
||||||
|
{
|
||||||
|
// Tried to place a block *into* another?
|
||||||
|
// Happens when you place a block aiming at side of block like torch or stem
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,7 +312,7 @@ private:
|
||||||
void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
|
void HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
|
||||||
|
|
||||||
/// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating)
|
/// Handles the block placing packet when it is a real block placement (not block-using, item-using or eating)
|
||||||
void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
|
public: void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
|
||||||
|
|
||||||
// cSocketThreads::cCallback overrides:
|
// cSocketThreads::cCallback overrides:
|
||||||
virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client
|
virtual void DataReceived (const char * a_Data, int a_Size) override; // Data is received from the client
|
||||||
|
|
Loading…
Reference in New Issue