From 15b92af166e03e3deb8baf5eb2ec6b0be5981646 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 25 Jan 2014 11:14:14 -0800 Subject: First attempt at Implementing Interfaces --- src/Blocks/BlockBed.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 66eb9130c..9c6f15698 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cWorld * a_World, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_World->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -23,26 +23,26 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ ); Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); if (OldMeta & 0x8) { // Was pillow - if (a_World->GetBlock(ThisPos - Direction) == E_BLOCK_BED) + if (a_ChunkInterface->GetBlock(ThisPos - Direction) == E_BLOCK_BED) { - a_World->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); } } else { // Was foot end - if (a_World->GetBlock(ThisPos + Direction) == E_BLOCK_BED) + if (a_ChunkInterface->GetBlock(ThisPos + Direction) == E_BLOCK_BED) { - a_World->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); + a_ChunkInterface->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); } } } @@ -51,30 +51,30 @@ void cBlockBedHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, -void cBlockBedHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_World->GetDimension() != dimOverworld) + if (a_WorldInterface->GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_World->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_ChunkInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { - if (a_World->GetTimeOfDay() > 13000) + if (a_WorldInterface->GetTimeOfDay() > 13000) { - NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (Meta & 0x8) { // Is pillow - a_World->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { // Is foot end Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_World->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_World->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { -- cgit v1.2.3 From 14e48ccb4bbad6f43121dc27f042083cda160f45 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 26 Jan 2014 06:20:39 -0800 Subject: Refactored cBlockHandler::OnUse and dependents --- src/Blocks/BlockBed.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 9c6f15698..02cdd58c7 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cPlayer * a_Player, + cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_ChunkInterface->SetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface->SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -56,7 +56,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface if (a_WorldInterface->GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_ChunkInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_WorldInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { @@ -66,7 +66,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface if (Meta & 0x8) { // Is pillow - a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { @@ -74,7 +74,7 @@ void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { -- cgit v1.2.3 From 25ec7750aac9800bec83a844020a6eeda5cd4d74 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 31 Jan 2014 15:17:41 -0800 Subject: Changed signitures of Several BLockHandler Methods Changed the signitures of the following to use interfaces: GetPlacementBlockTypeMeta OnPlaced OnPlacedByPlayer OnDestroyed OnNeighbourChanged NeighbourChanged OnUse CanBeAt Check --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 02cdd58c7..425e286ec 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -23,7 +23,7 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); -- cgit v1.2.3 From c6304b2b4faf31c2e4a91a07bcac298467898dba Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 1 Feb 2014 05:06:32 -0800 Subject: Changed pointers to references --- src/Blocks/BlockBed.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 425e286ec..65d397b36 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -6,7 +6,7 @@ void cBlockBedHandler::OnPlacedByPlayer( - cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta @@ -15,7 +15,7 @@ void cBlockBedHandler::OnPlacedByPlayer( if (a_BlockMeta < 8) { Vector3i Direction = MetaDataToDirection(a_BlockMeta); - a_ChunkInterface->SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); + a_ChunkInterface.SetBlock(a_WorldInterface,a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, a_BlockMeta | 0x8); } } @@ -23,26 +23,26 @@ void cBlockBedHandler::OnPlacedByPlayer( -void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) { - NIBBLETYPE OldMeta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Vector3i ThisPos( a_BlockX, a_BlockY, a_BlockZ ); Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 ); if (OldMeta & 0x8) { // Was pillow - if (a_ChunkInterface->GetBlock(ThisPos - Direction) == E_BLOCK_BED) + if (a_ChunkInterface.GetBlock(ThisPos - Direction) == E_BLOCK_BED) { - a_ChunkInterface->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0); } } else { // Was foot end - if (a_ChunkInterface->GetBlock(ThisPos + Direction) == E_BLOCK_BED) + if (a_ChunkInterface.GetBlock(ThisPos + Direction) == E_BLOCK_BED) { - a_ChunkInterface->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); + a_ChunkInterface.FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0); } } } @@ -51,30 +51,30 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface * a_ChunkInterface, cWorldInt -void cBlockBedHandler::OnUse(cChunkInterface * a_ChunkInterface, cWorldInterface * a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { - if (a_WorldInterface->GetDimension() != dimOverworld) + if (a_WorldInterface.GetDimension() != dimOverworld) { Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ); - a_WorldInterface->DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); + a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords); } else { - if (a_WorldInterface->GetTimeOfDay() > 13000) + if (a_WorldInterface.GetTimeOfDay() > 13000) { - NIBBLETYPE Meta = a_ChunkInterface->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); if (Meta & 0x8) { // Is pillow - a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } else { // Is foot end Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface->GetBroadcastManager()->BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); } } } else { -- cgit v1.2.3 From 8464f689ea214d3c30105ae58539885cf1268317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 4 Feb 2014 10:59:05 -0800 Subject: Improved Type safety of eBlockFace May Fix #640 --- src/Blocks/BlockBed.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 65d397b36..2fd993817 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -7,7 +7,7 @@ void cBlockBedHandler::OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, - int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) @@ -51,7 +51,7 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt -void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) +void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_WorldInterface.GetDimension() != dimOverworld) { -- cgit v1.2.3 From aa8b46e94714f261bfe451897b7ef23934e764eb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Feb 2014 23:24:16 +0000 Subject: Server internally uses new functions --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 65d397b36..8f291ad1f 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -78,7 +78,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } } } else { - a_Player->SendMessage("You can only sleep at night"); + a_Player->SendMessageFailure("You can only sleep at night"); } } } -- cgit v1.2.3 From c2277c6feeae4551c511588e6da8b05e1bc0c22e Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 16:26:50 +0100 Subject: BlockBed.cpp: Fixed Multiple people in one bed. OnUse in BlockBed.cpp now checks whether bit flag 0x4 in the Data values of the bed is set before somebody can try to sleep in the bed. --- src/Blocks/BlockBed.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index a6f3c36b6..2fa3a7264 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,20 +63,29 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x8) + if(Meta & 0x4) { - // Is pillow - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_Player->SendMessageFailure("This bed is occupied."); } else { - // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (Meta & 0x8) { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + // Is pillow + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } + else + { + // Is foot end + Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + { + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + } + } + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); } + } else { a_Player->SendMessageFailure("You can only sleep at night"); } @@ -86,3 +95,5 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface + + -- cgit v1.2.3 From 1b081a0fbbc217ed48830368c6e40b24a7af5358 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 17:31:38 +0100 Subject: BlockBed.cpp: Fixed space at if statement Added a space after an if statement and before the first bracket to keep up code conventions. --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 2fa3a7264..3dad4feba 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,7 +63,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if(Meta & 0x4) + if (Meta & 0x4) { a_Player->SendMessageFailure("This bed is occupied."); } -- cgit v1.2.3 From b64e9fb7f52e4a2b75b49413fdc2194132885370 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 00:17:23 +0000 Subject: Beds now work properly fixes #707 Also fixes FS392 Conflicts: src/Blocks/WorldInterface.h src/ClientHandle.cpp --- src/Blocks/BlockBed.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 7 deletions(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 3dad4feba..ca3927827 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -51,6 +51,49 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt +class cTimeFastForwardTester : + public cPlayerListCallback +{ + virtual bool Item(cPlayer * a_Player) override + { + if (!a_Player->IsInBed()) + { + return true; + } + + return false; + } +}; + + + + + +class cPlayerBedStateUnsetter : + public cPlayerListCallback +{ +public: + cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) : + m_Position(a_Position), m_WorldInterface(a_WorldInterface) + { + } + + virtual bool Item(cPlayer * a_Player) override + { + a_Player->SetIsInBed(false); + m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2); + return false; + } + +private: + Vector3i m_Position; + cWorldInterface & m_WorldInterface; +}; + + + + + void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { if (a_WorldInterface.GetDimension() != dimOverworld) @@ -69,6 +112,8 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } else { + Vector3i PillowDirection(0, 0, 0); + if (Meta & 0x8) { // Is pillow @@ -77,16 +122,30 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface else { // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken + + PillowDirection = MetaDataToDirection(Meta & 0x7); + if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z); } } - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); - } - - } else { + + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit + a_Player->SetIsInBed(true); + + cTimeFastForwardTester Tester; + if (a_WorldInterface.ForEachPlayer(Tester)) + { + cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface); + a_WorldInterface.ForEachPlayer(Unsetter); + a_WorldInterface.SetTimeOfDay(0); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0xB); // Where 0xB = 1011, and zero is to make sure 'occupied' bit is always unset + } + } + } + else + { a_Player->SendMessageFailure("You can only sleep at night"); } } -- cgit v1.2.3 From 888c3f1af7b817ab770703ce0638e0eef07d2d31 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 9 Mar 2014 15:53:03 +0000 Subject: Fixed VERIFY --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks/BlockBed.cpp') diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index ca3927827..6a3c6a55b 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -122,7 +122,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface else { // Is foot end - VERIFY((Meta & 0x4) != 1); // Occupied flag should never be set, else our compilator (intended) is broken + VERIFY((Meta & 0x4) != 0x4); // Occupied flag should never be set, else our compilator (intended) is broken PillowDirection = MetaDataToDirection(Meta & 0x7); if (a_ChunkInterface.GetBlock(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z) == E_BLOCK_BED) // Must always use pillow location for sleeping -- cgit v1.2.3