diff --git a/Minecraft.Client/SDK.cpp b/Minecraft.Client/SDK.cpp index 77fd64ec..c6240156 100644 --- a/Minecraft.Client/SDK.cpp +++ b/Minecraft.Client/SDK.cpp @@ -112,6 +112,72 @@ PlayerPos SDK::GetPlayerPos(int index) { return { p->x, p->y, p->z }; } +// ============================================================================ +// Player Stats +// ============================================================================ + +float SDK::GetPlayerHealth(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->getHealth() : 0.0f; +} + +void SDK::SetPlayerHealth(float health, int index) { + auto* p = GetLocalPlayer(index); + if (!p) return; + // Clamp to valid range so modders can't accidentally set 999 hp + if (health < 0.0f) health = 0.0f; + if (health > p->getMaxHealth()) health = p->getMaxHealth(); + p->setHealth(health); +} + +float SDK::GetPlayerMaxHealth(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->getMaxHealth() : 20.0f; +} + +bool SDK::IsPlayerAlive(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->getHealth() > 0.0f : false; +} + +// ============================================================================ +// Player State +// ============================================================================ + +void SDK::SetPlayerFlying(bool flying, int index) { + auto* p = GetLocalPlayer(index); + if (p) p->abilities.flying = flying; +} + +bool SDK::IsPlayerFlying(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->abilities.flying : false; +} + +bool SDK::IsPlayerSprinting(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->isSprinting() : false; +} + +bool SDK::IsPlayerSneaking(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->isSneaking() : false; +} + +bool SDK::IsPlayerOnGround(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->onGround : false; +} + +// ============================================================================ +// Player Info +// ============================================================================ + +std::wstring SDK::GetPlayerName(int index) { + auto* p = GetLocalPlayer(index); + return p ? p->name : L""; +} + // ============================================================================ // Messaging // ============================================================================ diff --git a/Minecraft.Client/SDK.h b/Minecraft.Client/SDK.h index dd3585e7..52d6ec4f 100644 --- a/Minecraft.Client/SDK.h +++ b/Minecraft.Client/SDK.h @@ -42,6 +42,22 @@ namespace SDK { MODAPI double GetPlayerZ(int index = 0); MODAPI PlayerPos GetPlayerPos(int index = 0); + // Player Stats + MODAPI float GetPlayerHealth(int index = 0); + MODAPI void SetPlayerHealth(float health, int index = 0); + MODAPI float GetPlayerMaxHealth(int index = 0); + MODAPI bool IsPlayerAlive(int index = 0); + + // Player State + MODAPI void SetPlayerFlying(bool flying, int index = 0); + MODAPI bool IsPlayerFlying(int index = 0); + MODAPI bool IsPlayerSprinting(int index = 0); + MODAPI bool IsPlayerSneaking(int index = 0); + MODAPI bool IsPlayerOnGround(int index = 0); + + // Player Info + MODAPI std::wstring GetPlayerName(int index = 0); + // Messaging MODAPI void BroadcastMessage(const std::wstring& message); MODAPI void SendMessageToPlayer(const std::wstring& playerName, const std::wstring& message);