diff options
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockBed.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index dccbcde39..e333c0700 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -71,11 +71,16 @@ bool cBlockBedHandler::OnUse( return true; } - // Sleeping is allowed only during night: - // TODO: Also during thunderstorms - if (!((a_WorldInterface.GetTimeOfDay() > 12541) && (a_WorldInterface.GetTimeOfDay() < 23458))) // Source: https://minecraft.gamepedia.com/Bed#Sleeping + // Sleeping is allowed only during night and thunderstorms: + if ( + !(((a_WorldInterface.GetTimeOfDay() > 12541) && (a_WorldInterface.GetTimeOfDay() < 23458)) || + (a_Player.GetWorld()->GetWeather() == wThunderstorm)) + ) // Source: https://minecraft.gamepedia.com/Bed#Sleeping { - a_Player.SendMessageFailure("You can only sleep at night"); + a_Player.SendAboveActionBarMessage("You can only sleep at night and during thunderstorms"); + + // Try to set home position anyway: + SetBedPos(a_Player, a_BlockPos); return true; } @@ -97,7 +102,7 @@ bool cBlockBedHandler::OnUse( }; if (!a_Player.GetWorld()->ForEachEntityInBox(cBoundingBox(a_Player.GetPosition() - Vector3i(0, 5, 0), 8, 10), FindMobs)) { - a_Player.SendMessageFailure("You may not rest now, there are monsters nearby"); + a_Player.SendAboveActionBarMessage("You may not rest now, there are monsters nearby"); return true; } @@ -120,10 +125,9 @@ bool cBlockBedHandler::OnUse( } // Occupy the bed: - a_Player.SetBedPos(a_BlockPos); + SetBedPos(a_Player, a_BlockPos); SetBedOccupationState(a_ChunkInterface, a_Player.GetLastBedPos(), true); a_Player.SetIsInBed(true); - a_Player.SendMessageSuccess("Home position set successfully"); // Fast-forward the time if all players in the world are in their beds: auto TimeFastForwardTester = [](cPlayer & a_OtherPlayer) @@ -172,3 +176,16 @@ cItems cBlockBedHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * } return cItem(E_ITEM_BED, 1, color); } + + + + + +void cBlockBedHandler::SetBedPos(cPlayer & a_Player, const Vector3i a_BedPosition) +{ + if (a_Player.GetLastBedPos() != a_BedPosition) + { + a_Player.SetBedPos(a_BedPosition); + a_Player.SendMessageSuccess("Home position set successfully"); + } +} |