mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Fix player HP desync between client and server
This commit is contained in:
		@@ -826,7 +826,8 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
 | 
			
		||||
				<< std::endl;
 | 
			
		||||
 | 
			
		||||
		PlayerHPChangeReason reason(PlayerHPChangeReason::FALL);
 | 
			
		||||
		playersao->setHP((s32)playersao->getHP() - (s32)damage, reason);
 | 
			
		||||
		playersao->setHP((s32)playersao->getHP() - (s32)damage, reason, false);
 | 
			
		||||
		SendPlayerHPOrDie(playersao, reason); // correct client side prediction
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -462,7 +462,7 @@ void PlayerSAO::rightClick(ServerActiveObject *clicker)
 | 
			
		||||
	m_env->getScriptIface()->on_rightclickplayer(this, clicker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
 | 
			
		||||
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason, bool send)
 | 
			
		||||
{
 | 
			
		||||
	if (hp == (s32)m_hp)
 | 
			
		||||
		return; // Nothing to do
 | 
			
		||||
@@ -490,7 +490,8 @@ void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
 | 
			
		||||
	if ((hp == 0) != (oldhp == 0))
 | 
			
		||||
		m_properties_sent = false;
 | 
			
		||||
 | 
			
		||||
	m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
 | 
			
		||||
	if (send)
 | 
			
		||||
		m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PlayerSAO::setBreath(const u16 breath, bool send)
 | 
			
		||||
 
 | 
			
		||||
@@ -112,7 +112,11 @@ public:
 | 
			
		||||
	u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
 | 
			
		||||
			float time_from_last_punch);
 | 
			
		||||
	void rightClick(ServerActiveObject *clicker);
 | 
			
		||||
	void setHP(s32 hp, const PlayerHPChangeReason &reason);
 | 
			
		||||
	void setHP(s32 hp, const PlayerHPChangeReason &reason) override
 | 
			
		||||
	{
 | 
			
		||||
		return setHP(hp, reason, true);
 | 
			
		||||
	}
 | 
			
		||||
	void setHP(s32 hp, const PlayerHPChangeReason &reason, bool send);
 | 
			
		||||
	void setHPRaw(u16 hp) { m_hp = hp; }
 | 
			
		||||
	u16 getBreath() const { return m_breath; }
 | 
			
		||||
	void setBreath(const u16 breath, bool send = true);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user