From 1e7bedaa725e9fe3c8c79bf281ebe3e7d91259c0 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 13 Aug 2023 23:01:40 +0300 Subject: [PATCH] * Work on survival mode. --- source/world/entity/LocalPlayer.cpp | 15 +++++++++++++++ source/world/entity/LocalPlayer.hpp | 1 + source/world/entity/Mob.cpp | 6 ++++-- source/world/entity/Player.cpp | 4 ++++ source/world/item/Inventory.cpp | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/source/world/entity/LocalPlayer.cpp b/source/world/entity/LocalPlayer.cpp index ebe580c..9cd4420 100644 --- a/source/world/entity/LocalPlayer.cpp +++ b/source/world/entity/LocalPlayer.cpp @@ -123,6 +123,9 @@ int LocalPlayer::move(float x, float y, float z) int result = 0; LocalPlayer* pLP = m_pMinecraft->m_pLocalPlayer; + if (!pLP) + return 1300; // TODO + if (Minecraft::DEADMAU5_CAMERA_CHEATS && pLP == this && m_pMinecraft->m_options.m_bFlyCheat) { //@HUH: Using m_pMinecraft->m_pLocalPlayer instead of this, even though they're the same @@ -235,3 +238,15 @@ void LocalPlayer::updateAi() field_B0C = m_pKeyboardInput->m_bJumpButton || m_nAutoJumpFrames > 0; } + +void LocalPlayer::beforeRemove() +{ +#ifdef TEST_SURVIVAL_MODE + LogMsg("The localplayer was removed"); + + if (m_pMinecraft->m_pLocalPlayer == this) + m_pMinecraft->m_pLocalPlayer = nullptr; + if (m_pMinecraft->m_pMobPersp == this) + m_pMinecraft->m_pMobPersp = nullptr; +#endif +} diff --git a/source/world/entity/LocalPlayer.hpp b/source/world/entity/LocalPlayer.hpp index 17613e8..4034199 100644 --- a/source/world/entity/LocalPlayer.hpp +++ b/source/world/entity/LocalPlayer.hpp @@ -27,6 +27,7 @@ public: virtual int move(float x, float y, float z) override; virtual void tick() override; virtual void updateAi() override; + virtual void beforeRemove() override; void calculateFlight(float, float, float); void closeContainer(); //@HUH: oddly enough not a virtual/override diff --git a/source/world/entity/Mob.cpp b/source/world/entity/Mob.cpp index 139055e..249a0b8 100644 --- a/source/world/entity/Mob.cpp +++ b/source/world/entity/Mob.cpp @@ -364,7 +364,7 @@ void Mob::causeFallDamage(float level) int x = int(ceilf(level - 3)); if (x > 0) { - hurt(nullptr, 3); + hurt(nullptr, 3*42); //@HUH: useless call to getTile? or could this be a return value of some sort //Entity::causeFallDamage returns nothing though, so.... @@ -710,7 +710,9 @@ int Mob::getMaxSpawnClusterSize() void Mob::actuallyHurt(int damage) { - +#ifdef TEST_SURVIVAL_MODE + m_health -= damage; +#endif } bool Mob::removeWhenFarAway() diff --git a/source/world/entity/Player.cpp b/source/world/entity/Player.cpp index 4c9c6cc..13095ab 100644 --- a/source/world/entity/Player.cpp +++ b/source/world/entity/Player.cpp @@ -84,7 +84,11 @@ bool Player::isCreativeModeAllowed() bool Player::hurt(Entity* pEnt, int damage) { //@HUH +#ifndef TEST_SURVIVAL_MODE return false; +#endif + + return Mob::hurt(pEnt, damage); } void Player::awardKillScore(Entity* pKilled, int score) diff --git a/source/world/item/Inventory.cpp b/source/world/item/Inventory.cpp index baed02e..3391474 100644 --- a/source/world/item/Inventory.cpp +++ b/source/world/item/Inventory.cpp @@ -92,6 +92,7 @@ void Inventory::prepareSurvivalInventory() addTestItem(Item::wheat->m_itemID, 64); addTestItem(Item::sugar->m_itemID, 64); addTestItem(Item::camera->m_itemID, 64); + addTestItem(Tile::ladder->m_ID, 64); for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++) m_hotbar[i] = i;