summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2017-07-01 15:59:26 +0200
committerLukas Pioch <lukas@zgow.de>2017-07-02 17:10:57 +0200
commit070cb0d21f74dda768770ba0b8d410abe381c67a (patch)
treea736ccb3f30aff6bbdd353398c97138481bdd7f1
parentAdded armor durability reduction when player is attacked. (diff)
downloadcuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar.gz
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar.bz2
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar.lz
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar.xz
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.tar.zst
cuberite-070cb0d21f74dda768770ba0b8d410abe381c67a.zip
-rw-r--r--src/Blocks/BlockBed.cpp40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index b980f80e0..adc01c158 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -4,6 +4,9 @@
#include "BroadcastInterface.h"
#include "Entities/../World.h"
#include "Entities/Player.h"
+#include "../BoundingBox.h"
+#include "../Mobs/Monster.h"
+#include "../Entities/Entity.h"
@@ -37,6 +40,22 @@ void cBlockBedHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInt
+class cFindMobs :
+ public cEntityCallback
+{
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ return (
+ (a_Entity->GetEntityType() == cEntity::etMonster) &&
+ (static_cast<cMonster*>(a_Entity)->GetMobFamily() == cMonster::mfHostile)
+ );
+ }
+};
+
+
+
+
+
class cTimeFastForwardTester :
public cPlayerListCallback
{
@@ -88,14 +107,23 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
Vector3i Coords(a_BlockX, a_BlockY, a_BlockZ);
a_WorldInterface.DoExplosionAt(5, a_BlockX, a_BlockY, a_BlockZ, true, esBed, &Coords);
}
+ else if (!((a_WorldInterface.GetTimeOfDay() > 12541) && (a_WorldInterface.GetTimeOfDay() < 23458))) // Source: http://minecraft.gamepedia.com/Bed#Sleeping
+ {
+ a_Player->SendMessageFailure("You can only sleep at night");
+ }
else
{
- if (a_WorldInterface.GetTimeOfDay() > 13000)
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ if ((Meta & 0x4) == 0x4)
+ {
+ a_Player->SendMessageFailure("This bed is occupied");
+ }
+ else
{
- NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if ((Meta & 0x4) == 0x4)
+ cFindMobs FindMobs;
+ if (!a_Player->GetWorld()->ForEachEntityInBox(cBoundingBox(a_Player->GetPosition() - Vector3i(0, 5, 0), 8, 10), FindMobs))
{
- a_Player->SendMessageFailure("This bed is occupied");
+ a_Player->SendMessageFailure("You may not rest now, there are monsters nearby");
}
else
{
@@ -133,10 +161,6 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
}
}
}
- else
- {
- a_Player->SendMessageFailure("You can only sleep at night");
- }
}
return true;
}