summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMat <mail@mathias.is>2020-08-05 21:38:29 +0200
committerGitHub <noreply@github.com>2020-08-05 21:38:29 +0200
commitcb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6 (patch)
tree3e2440c34df4d64a195a59741da58a57ac877009
parentimprementing plugin message to send server brand (#4786) (diff)
downloadcuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar.gz
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar.bz2
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar.lz
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar.xz
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.tar.zst
cuberite-cb1f0a5af260ee7fab7ccda51366a3e2c1f89ce6.zip
-rw-r--r--src/Blocks/BlockBed.cpp31
-rw-r--r--src/Blocks/BlockBed.h6
2 files changed, 30 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");
+ }
+}
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index 418d44ca5..0a5a0e300 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -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);