summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/cBlockToPickup.cpp20
-rw-r--r--source/cBlockToPickup.h1
-rw-r--r--source/cClientHandle.cpp51
-rw-r--r--source/cDoors.h75
4 files changed, 85 insertions, 62 deletions
diff --git a/source/cBlockToPickup.cpp b/source/cBlockToPickup.cpp
index 6e59e6573..c0597d005 100644
--- a/source/cBlockToPickup.cpp
+++ b/source/cBlockToPickup.cpp
@@ -50,7 +50,27 @@ ENUM_ITEM_ID cBlockToPickup::ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_U
return E_ITEM_REDSTONE_TORCH_ON;
case E_BLOCK_MELON:
return E_ITEM_MELON_SLICE;
+ case E_BLOCK_WOODEN_DOOR:
+ return E_ITEM_WOODEN_DOOR;
+ case E_BLOCK_IRON_DOOR:
+ return E_ITEM_IRON_DOOR;
default:
return (ENUM_ITEM_ID)a_BlockID;
}
}
+
+char cBlockToPickup::PickupCount(unsigned char a_BlockID)
+{
+ switch(a_BlockID)
+ {
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ case E_BLOCK_REDSTONE_ORE:
+ return rand() % 2 + 4;
+ case E_BLOCK_MELON:
+ return rand() % 8 + 3;
+ case E_BLOCK_LAPIS_ORE:
+ return rand() % 5 + 4;
+ default:
+ return 1;
+ }
+} \ No newline at end of file
diff --git a/source/cBlockToPickup.h b/source/cBlockToPickup.h
index 8eb74c5ae..a59d64318 100644
--- a/source/cBlockToPickup.h
+++ b/source/cBlockToPickup.h
@@ -10,4 +10,5 @@ class cBlockToPickup
{
public:
static ENUM_ITEM_ID ToPickup( unsigned char a_BlockID, ENUM_ITEM_ID a_UsedItemID );
+ static char PickupCount(unsigned char a_BlockID);
};
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 6725a2156..3d54dc4d9 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -546,22 +546,26 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
bool bBroken = (PacketData->m_Status == 0x02) || g_BlockOneHitDig[(int)OldBlock] || ( (PacketData->m_Status == 0x00) && (m_Player->GetGameMode() == 1) );
if(bBroken == false) bBroken = (m_Player->GetInventory().GetEquippedItem().m_ItemID == E_ITEM_SHEARS && OldBlock == E_BLOCK_LEAVES);
+ if(OldBlock == E_BLOCK_WOODEN_DOOR && !bBroken)
+ {
+ cDoors::ChangeDoor(m_Player->GetWorld(), PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ);
+ }
+
cItem PickupItem;
if( bBroken && !(m_Player->GetGameMode() == 1) ) // broken
{
+
ENUM_ITEM_ID PickupID = cBlockToPickup::ToPickup( (ENUM_BLOCK_ID)OldBlock, m_Player->GetInventory().GetEquippedItem().m_ItemID );
PickupItem.m_ItemID = PickupID;
PickupItem.m_ItemHealth = MetaData;
- PickupItem.m_ItemCount = 1;
- if( OldBlock == E_BLOCK_LAPIS_ORE ) {
+ PickupItem.m_ItemCount = cBlockToPickup::PickupCount(OldBlock);
+ if( OldBlock == E_BLOCK_LAPIS_ORE )
+ {
PickupItem.m_ItemHealth = 4;
- PickupItem.m_ItemCount = rand()%5+4;
}
- if( OldBlock == E_BLOCK_REDSTONE_ORE || OldBlock == E_BLOCK_REDSTONE_ORE_GLOWING ) {
- PickupItem.m_ItemCount = rand()%2+4;
- }
- if( OldBlock == E_BLOCK_MELON ) {
- PickupItem.m_ItemCount = rand()%8+3;
+ if(cDoors::IsDoor(OldBlock))
+ {
+ PickupItem.m_ItemHealth = 1; //For a complete door this works :D
}
}
if(!cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_BLOCK_DIG, 2, PacketData, m_Player, &PickupItem ) )
@@ -592,6 +596,18 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
}
}
+ if(cDoors::IsDoor(OldBlock)) //Special actions for destroyed door (Destroy second part)
+ {
+ if(MetaData & 8) //was Upper part of door
+ {
+ if(cDoors::IsDoor(World->GetBlock(PacketData->m_PosX, PacketData->m_PosY - 1, PacketData->m_PosZ)))
+ World->SetBlock(PacketData->m_PosX, PacketData->m_PosY - 1, PacketData->m_PosZ, E_BLOCK_AIR, 0);
+ }else{ //Was lower part
+ if(cDoors::IsDoor(World->GetBlock(PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ)))
+ World->SetBlock(PacketData->m_PosX, PacketData->m_PosY + 1, PacketData->m_PosZ, E_BLOCK_AIR, 0);
+ }
+ }
+
int helditem = m_Player->GetInventory().GetEquippedItem().m_ItemID;
bool itemhasdur = false;
switch(helditem)
@@ -752,24 +768,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
case E_BLOCK_WOODEN_DOOR:
{
bPlaceBlock = false;
- char OldMetaData = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ);
- char NewMetaData = cDoors::ChangeStateMetaData ( OldMetaData );
- cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewMetaData );
- if ( (int)OldMetaData > 7 ) { //top of door
- char BottomBlock = cRoot::Get()->GetWorld()->GetBlock(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ);
- char BottomMeta = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ);
- if ( ( (int)BottomBlock == E_BLOCK_WOODEN_DOOR ) && ( (int)BottomMeta < 8 ) ) {
- char NewBottomMeta = cDoors::ChangeStateMetaData ( BottomMeta );
- cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewBottomMeta );
- }
- } else if ( (int)OldMetaData < 8 ) { //bottom of door
- char TopBlock = cRoot::Get()->GetWorld()->GetBlock(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ);
- char TopMeta = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ);
- if ( ( (int)TopBlock == E_BLOCK_WOODEN_DOOR ) && ( (int)TopMeta > 7 ) ) {
- char NewTopMeta = cDoors::ChangeStateMetaData ( TopMeta );
- cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewTopMeta );
- }
- }
+ cDoors::ChangeDoor(m_Player->GetWorld(), PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ);
}
break;
default:
diff --git a/source/cDoors.h b/source/cDoors.h
index eb1710df2..dc326104b 100644
--- a/source/cDoors.h
+++ b/source/cDoors.h
@@ -1,4 +1,6 @@
#pragma once
+#include "cBlockToPickup.h"
+
class cDoors //tolua_export
{ //tolua_export
@@ -17,43 +19,44 @@ public:
return 0x3;
} //tolua_export
- static char ChangeStateMetaData( char MetaData ) //tolua_export
+ static char ChangeStateMetaData( char a_MetaData ) //tolua_export
{ //tolua_export
- if ( (int)MetaData == 0 ) { //todo, condense this code. lol
- return 0x4;
- } else if ( (int)MetaData == 1 ) {
- return 0x5;
- } else if ( (int)MetaData == 2 ) {
- return 0x6;
- } else if ( (int)MetaData == 3 ) {
- return 0x7;
- } else if ( (int)MetaData == 4 ) {
- return 0x0;
- } else if ( (int)MetaData == 5 ) {
- return 0x1;
- } else if ( (int)MetaData == 6 ) {
- return 0x2;
- } else if ( (int)MetaData == 7 ) {
- return 0x3;
- } else if ( (int)MetaData == 8 ) {
- return 0xC;
- } else if ( (int)MetaData == 9 ) {
- return 0xD;
- } else if ( (int)MetaData == 10 ) {
- return 0xE;
- } else if ( (int)MetaData == 11 ) {
- return 0xF;
- } else if ( (int)MetaData == 12 ) {
- return 0x8;
- } else if ( (int)MetaData == 13 ) {
- return 0x9;
- } else if ( (int)MetaData == 14 ) {
- return 0xA;
- } else if ( (int)MetaData == 15 ) {
- return 0xB;
- } else {
- return 0x0;
+
+ a_MetaData ^= 4; //XOR bit 2 aka 3. bit (Door open state)
+
+ return a_MetaData;
+ } //tolua_export
+
+ static void ChangeDoor(cWorld *a_World, int a_X, int a_Y, int a_Z) //tolua_export
+ { //tolua_export
+ char OldMetaData = a_World->GetBlockMeta(a_X, a_Y, a_Z);
+
+ a_World->SetBlockMeta(a_X, a_Y, a_Z, ChangeStateMetaData ( OldMetaData ) );
+
+
+ if (OldMetaData & 8)
+ { //current block is top of the door
+ char BottomBlock = a_World->GetBlock(a_X, a_Y - 1, a_Z);
+ char BottomMeta = a_World->GetBlockMeta(a_X, a_Y - 1, a_Z);
+
+ if (IsDoor(BottomBlock) && !(BottomMeta & 8))
+ {
+ a_World->SetBlockMeta(a_X, a_Y - 1, a_Z, ChangeStateMetaData ( BottomMeta ) );
+ }
+ } else { //current block is bottom of the door
+ char TopBlock = a_World->GetBlock(a_X, a_Y + 1, a_Z);
+ char TopMeta = a_World->GetBlockMeta(a_X, a_Y + 1, a_Z);
+
+ if (IsDoor(TopBlock) && (TopMeta & 8))
+ {
+ a_World->SetBlockMeta(a_X, a_Y + 1, a_Z, ChangeStateMetaData ( TopMeta ) );
+ }
}
- } //tolua_export
+ } //tolua_export
+
+ inline static bool IsDoor(char a_Block)
+ {
+ return (a_Block == E_BLOCK_WOODEN_DOOR || a_Block == E_BLOCK_IRON_DOOR);
+ }
}; //tolua_export \ No newline at end of file