1
0
Fork 0

Update bed behavior (#4545)

This commit is contained in:
Mat 2020-08-05 22:38:29 +03:00 committed by GitHub
parent 5176c22656
commit cb1f0a5af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 7 deletions

View File

@ -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");
}
}

View File

@ -96,6 +96,12 @@ public:
static void SetBedPos(cPlayer & a_Player, const Vector3i a_BedPosition);
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);