From 7513c37f521a174643e582f79b80930a4f0bdcd1 Mon Sep 17 00:00:00 2001 From: MatthewBeshay <92357869+MatthewBeshay@users.noreply.github.com> Date: Thu, 9 Apr 2026 22:38:11 +1000 Subject: [PATCH] refactor: extend ITutorial to cover MultiPlayerLocalPlayer event hooks --- targets/app/common/Tutorial/Tutorial.h | 4 +- .../multiplayer/MultiPlayerLocalPlayer.cpp | 55 ++++++++++--------- targets/minecraft/world/tutorial/ITutorial.h | 3 + 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/targets/app/common/Tutorial/Tutorial.h b/targets/app/common/Tutorial/Tutorial.h index 01fc95adb..5f790bfc4 100644 --- a/targets/app/common/Tutorial/Tutorial.h +++ b/targets/app/common/Tutorial/Tutorial.h @@ -171,7 +171,7 @@ public: int y, int z, bool bTestUseOnly = false); void useItemOn(std::shared_ptr item, bool bTestUseOnly = false); - void completeUsingItem(std::shared_ptr item); + void completeUsingItem(std::shared_ptr item) override; void startDestroyBlock(std::shared_ptr item, Tile* tile); void destroyBlock(Tile* tile); void attack(std::shared_ptr player, std::shared_ptr entity); @@ -187,7 +187,7 @@ public: void onLookAt(int id, int iData = 0) override; void onLookAtEntity(std::shared_ptr entity) override; void onRideEntity(std::shared_ptr entity) override; - void onEffectChanged(MobEffect* effect, bool bRemoved = false); + void onEffectChanged(MobEffect* effect, bool bRemoved = false) override; bool canMoveToPosition(double xo, double yo, double zo, double xt, double yt, double zt) override; diff --git a/targets/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp b/targets/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp index 36ee02001..8dd22a999 100644 --- a/targets/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp +++ b/targets/minecraft/client/multiplayer/MultiPlayerLocalPlayer.cpp @@ -5,9 +5,8 @@ #include #include "ClientConnection.h" -#include "app/common/Tutorial/Tutorial.h" -#include "app/common/Tutorial/TutorialMode.h" #include "minecraft/IGameServices.h" +#include "minecraft/world/tutorial/ITutorial.h" #include "minecraft/client/Minecraft.h" #include "minecraft/client/multiplayer/MultiPlayerGameMode.h" #include "minecraft/client/player/Input.h" @@ -234,10 +233,11 @@ void MultiplayerLocalPlayer::actuallyHurt(DamageSource* source, float dmg) { void MultiplayerLocalPlayer::completeUsingItem() { Minecraft* pMinecraft = Minecraft::GetInstance(); if (useItem != nullptr && pMinecraft->localgameModes[m_iPad] != nullptr) { - TutorialMode* gameMode = - (TutorialMode*)pMinecraft->localgameModes[m_iPad]; - Tutorial* tutorial = gameMode->getTutorial(); - tutorial->completeUsingItem(useItem); + ITutorial* tutorial = + pMinecraft->localgameModes[m_iPad]->getTutorial(); + if (tutorial != nullptr) { + tutorial->completeUsingItem(useItem); + } } Player::completeUsingItem(); } @@ -245,10 +245,11 @@ void MultiplayerLocalPlayer::completeUsingItem() { void MultiplayerLocalPlayer::onEffectAdded(MobEffectInstance* effect) { Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft->localgameModes[m_iPad] != nullptr) { - TutorialMode* gameMode = - (TutorialMode*)pMinecraft->localgameModes[m_iPad]; - Tutorial* tutorial = gameMode->getTutorial(); - tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); + ITutorial* tutorial = + pMinecraft->localgameModes[m_iPad]->getTutorial(); + if (tutorial != nullptr) { + tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); + } } Player::onEffectAdded(effect); } @@ -257,10 +258,11 @@ void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect, bool doRefreshAttributes) { Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft->localgameModes[m_iPad] != nullptr) { - TutorialMode* gameMode = - (TutorialMode*)pMinecraft->localgameModes[m_iPad]; - Tutorial* tutorial = gameMode->getTutorial(); - tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); + ITutorial* tutorial = + pMinecraft->localgameModes[m_iPad]->getTutorial(); + if (tutorial != nullptr) { + tutorial->onEffectChanged(MobEffect::effects[effect->getId()]); + } } Player::onEffectUpdated(effect, doRefreshAttributes); } @@ -268,10 +270,12 @@ void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect, void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance* effect) { Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft->localgameModes[m_iPad] != nullptr) { - TutorialMode* gameMode = - (TutorialMode*)pMinecraft->localgameModes[m_iPad]; - Tutorial* tutorial = gameMode->getTutorial(); - tutorial->onEffectChanged(MobEffect::effects[effect->getId()], true); + ITutorial* tutorial = + pMinecraft->localgameModes[m_iPad]->getTutorial(); + if (tutorial != nullptr) { + tutorial->onEffectChanged(MobEffect::effects[effect->getId()], + true); + } } Player::onEffectRemoved(effect); } @@ -351,13 +355,14 @@ void MultiplayerLocalPlayer::ride(std::shared_ptr e) { Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft->localgameModes[m_iPad] != nullptr) { - TutorialMode* gameMode = - (TutorialMode*)pMinecraft->localgameModes[m_iPad]; - if (wasRiding && !isRiding) { - gameMode->getTutorial()->changeTutorialState( - e_Tutorial_State_Gameplay); - } else if (!wasRiding && isRiding) { - gameMode->getTutorial()->onRideEntity(e); + ITutorial* tutorial = + pMinecraft->localgameModes[m_iPad]->getTutorial(); + if (tutorial != nullptr) { + if (wasRiding && !isRiding) { + tutorial->changeTutorialState(e_Tutorial_State_Gameplay); + } else if (!wasRiding && isRiding) { + tutorial->onRideEntity(e); + } } } } diff --git a/targets/minecraft/world/tutorial/ITutorial.h b/targets/minecraft/world/tutorial/ITutorial.h index 20a75b694..ed3982fb2 100644 --- a/targets/minecraft/world/tutorial/ITutorial.h +++ b/targets/minecraft/world/tutorial/ITutorial.h @@ -7,6 +7,7 @@ class Entity; class ItemInstance; +class MobEffect; // Domain interface for the player tutorial. // @@ -44,6 +45,8 @@ public: virtual void onLookAt(int id, int iData = 0) = 0; virtual void onLookAtEntity(std::shared_ptr entity) = 0; virtual void onRideEntity(std::shared_ptr entity) = 0; + virtual void completeUsingItem(std::shared_ptr item) = 0; + virtual void onEffectChanged(MobEffect* effect, bool bRemoved = false) = 0; [[nodiscard]] virtual bool canMoveToPosition(double xo, double yo, double zo, double xt,