mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-09 04:19:26 +08:00
Lua API for spectating entities (#4518)
This commit is contained in:
parent
c04ba834d1
commit
5eb1ba3bcc
@ -11132,6 +11132,17 @@ a_Player:OpenWindow(Window);
|
||||
},
|
||||
Notes = "Sets the player visibility to other players",
|
||||
},
|
||||
SpectateEntity =
|
||||
{
|
||||
Params =
|
||||
{
|
||||
{
|
||||
Name = "Target",
|
||||
Type = "cEntity",
|
||||
},
|
||||
},
|
||||
Notes = "Spectates the target entity. Does not change the player's gamemode to spectator mode. When called with self or nil as the target, resets the spectation.",
|
||||
},
|
||||
TossEquippedItem =
|
||||
{
|
||||
Params =
|
||||
|
@ -1703,6 +1703,23 @@ void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees)
|
||||
|
||||
|
||||
|
||||
void cPlayer::SpectateEntity(cEntity * a_Target)
|
||||
{
|
||||
if ((a_Target == nullptr) || (static_cast<cEntity *>(this) == a_Target))
|
||||
{
|
||||
GetClientHandle()->SendCameraSetTo(*this);
|
||||
m_AttachedTo = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
m_AttachedTo = a_Target;
|
||||
GetClientHandle()->SendCameraSetTo(*m_AttachedTo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vector3d cPlayer::GetThrowStartPos(void) const
|
||||
{
|
||||
Vector3d res = GetEyePosition();
|
||||
@ -2838,8 +2855,7 @@ void cPlayer::AttachTo(cEntity * a_AttachTo)
|
||||
// Different attach, if this is a spectator
|
||||
if (IsGameModeSpectator())
|
||||
{
|
||||
m_AttachedTo = a_AttachTo;
|
||||
GetClientHandle()->SendCameraSetTo(*m_AttachedTo);
|
||||
SpectateEntity(a_AttachTo);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,9 @@ public:
|
||||
*/
|
||||
void SendRotation(double a_YawDegrees, double a_PitchDegrees);
|
||||
|
||||
/** Spectates the target entity. If a_Target is nullptr or a pointer to self, end spectation. */
|
||||
void SpectateEntity(cEntity * a_Target);
|
||||
|
||||
/** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */
|
||||
Vector3d GetThrowStartPos(void) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user