Merge pull request #782 from mc-server/beds
Beds now work properly, fixes #707
This commit is contained in:
commit
4ec402e6f9
@ -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) != 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
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ class cBroadcastInterface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
|
||||
virtual void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
|
||||
virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ ) = 0;
|
||||
virtual void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
|
||||
virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0;
|
||||
};
|
||||
|
@ -27,7 +27,13 @@ public:
|
||||
|
||||
/** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
|
||||
virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) = 0;
|
||||
|
||||
|
||||
/** Sends the block on those coords to the player */
|
||||
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer * a_Player) = 0;
|
||||
|
||||
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
|
||||
virtual bool ForEachPlayer(cItemCallback<cPlayer> & a_Callback) = 0;
|
||||
|
||||
virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0;
|
||||
|
||||
};
|
||||
|
@ -270,6 +270,9 @@ public:
|
||||
/// Returns true if the player is currently flying.
|
||||
bool IsFlying(void) const { return m_IsFlying; }
|
||||
|
||||
/** Returns if a player is sleeping in a bed */
|
||||
bool IsInBed(void) const { return m_bIsInBed; }
|
||||
|
||||
/// returns true if the player has thrown out a floater.
|
||||
bool IsFishing(void) const { return m_IsFishing; }
|
||||
|
||||
@ -278,6 +281,9 @@ public:
|
||||
int GetFloaterID(void) const { return m_FloaterID; }
|
||||
|
||||
// tolua_end
|
||||
|
||||
/** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */
|
||||
void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; }
|
||||
|
||||
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
|
||||
void StartEating(void);
|
||||
@ -371,8 +377,8 @@ protected:
|
||||
GroupList m_ResolvedGroups;
|
||||
GroupList m_Groups;
|
||||
|
||||
std::string m_PlayerName;
|
||||
std::string m_LoadedWorldName;
|
||||
AString m_PlayerName;
|
||||
AString m_LoadedWorldName;
|
||||
|
||||
/// Xp Level stuff
|
||||
enum
|
||||
@ -456,7 +462,7 @@ protected:
|
||||
|
||||
int m_FloaterID;
|
||||
|
||||
cTeam* m_Team;
|
||||
cTeam * m_Team;
|
||||
|
||||
|
||||
|
||||
@ -479,6 +485,11 @@ protected:
|
||||
|
||||
/// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block)
|
||||
void ApplyFoodExhaustionFromMovement();
|
||||
|
||||
/** Flag representing whether the player is currently in a bed
|
||||
Set by a right click on unoccupied bed, unset by a time fast forward or teleport */
|
||||
bool m_bIsInBed;
|
||||
|
||||
} ; // tolua_export
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ public:
|
||||
m_WeatherInterval = a_WeatherInterval;
|
||||
}
|
||||
|
||||
void SetTimeOfDay(Int64 a_TimeOfDay)
|
||||
virtual void SetTimeOfDay(Int64 a_TimeOfDay)
|
||||
{
|
||||
m_TimeOfDay = a_TimeOfDay;
|
||||
m_TimeOfDaySecs = (double)a_TimeOfDay / 20.0;
|
||||
@ -203,7 +203,7 @@ public:
|
||||
void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
|
||||
virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmmount, cClientHandle * a_Exclude = NULL); // tolua_export
|
||||
void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
|
||||
@ -216,7 +216,7 @@ public:
|
||||
void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL);
|
||||
virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
|
||||
virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ );
|
||||
void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = NULL);
|
||||
|
||||
virtual cBroadcastInterface & GetBroadcastManager()
|
||||
@ -273,7 +273,7 @@ public:
|
||||
void RemovePlayer( cPlayer* a_Player );
|
||||
|
||||
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
|
||||
bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
virtual bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
/** Calls the callback for the player of the given name; returns true if the player was found and the callback called, false if player not found. Callback return ignored */
|
||||
bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
Loading…
Reference in New Issue
Block a user