1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Method add_pos for object/player (#14126)

This commit is contained in:
sfence 2024-01-01 22:48:56 +01:00 committed by GitHub
parent c9ab61aa8c
commit d0753dddb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 105 additions and 7 deletions

View file

@ -352,7 +352,7 @@ void PlayerSAO::setBasePosition(v3f position)
void PlayerSAO::setPos(const v3f &pos)
{
if(isAttached())
if (isAttached())
return;
// Send mapblock of target location
@ -367,6 +367,30 @@ void PlayerSAO::setPos(const v3f &pos)
m_env->getGameDef()->SendMovePlayer(m_peer_id);
}
void PlayerSAO::addPos(const v3f &added_pos)
{
if (isAttached())
return;
// Backward compatibility for older clients
if (m_player->protocol_version < 44) {
setPos(getBasePosition() + added_pos);
return;
}
// Send mapblock of target location
v3f pos = getBasePosition() + added_pos;
v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE);
m_env->getGameDef()->SendBlock(m_peer_id, blockpos);
setBasePosition(pos);
// Movement caused by this command is always valid
m_last_good_position = getBasePosition();
m_move_pool.empty();
m_time_from_last_teleport = 0.0;
m_env->getGameDef()->SendMovePlayerRel(m_peer_id, added_pos);
}
void PlayerSAO::moveTo(v3f pos, bool continuous)
{
if(isAttached())

View file

@ -90,6 +90,7 @@ public:
void step(float dtime, bool send_recommended) override;
void setBasePosition(v3f position);
void setPos(const v3f &pos) override;
void addPos(const v3f &added_pos) override;
void moveTo(v3f pos, bool continuous) override;
void setPlayerYaw(const float yaw);
// Data should not be sent at player initialization

View file

@ -91,6 +91,8 @@ public:
virtual void setPos(const v3f &pos)
{ setBasePosition(pos); }
virtual void addPos(const v3f &added_pos)
{ setBasePosition(m_base_position + added_pos); }
// continuous: if true, object does not stop immediately at pos
virtual void moveTo(v3f pos, bool continuous)
{ setBasePosition(pos); }