Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: morpheus not properly waking players, not awarding buffs for sleeping #412

Merged
merged 6 commits into from
Sep 1, 2024

Conversation

leumasme
Copy link
Contributor

Closes GTNewHorizons/GT-New-Horizons-Modpack#16893

Morpheus doesn't actually wake players when a new day starts, it only sets the day time.
This causes players to instead wake up automatically on the next tick as they're in a bed while its day.
This isn't good, and causes the GT5-Unofficial buff you get after sleeping to not be awarded.

This uses an Accessor mixin to call wakeAllPlayers. Because this has to run early but the actual Morpheus fix has to run late, they're split into two mixins.
Maybe reorganize the Accessor mixin to be in the general/minecraft section instead of Morpheus (+change description)? Not sure; this is my first hodgepodge PR

Transforms the Morpheus Method

private void advanceToMorning(World world) {
    try {
        ((INewDayHandler)MorpheusRegistry.registry.get(world.provider.dimensionId)).startNewDay();
    } catch (Exception var3) {
        Morpheus.mLog.error("Exception caught while starting a new day for dimension " + world.provider.dimensionId);
    }

    if (!(Boolean)this.alertSent.get(world.provider.dimensionId)) {
        this.alertPlayers(new ChatComponentText(DateHandler.getMorningText()), world);
        ((WorldSleepState)Morpheus.playerSleepStatus.get(world.provider.dimensionId)).wakeAllPlayers();
        this.alertSent.put(world.provider.dimensionId, true);
    }

    world.provider.resetRainAndThunder();
}

into the equivalent of

private void advanceToMorning(World world) {
    try {
        ((INewDayHandler)MorpheusRegistry.registry.get(world.provider.dimensionId)).startNewDay();
    } catch (Exception var3) {
        Morpheus.mLog.error("Exception caught while starting a new day for dimension " + world.provider.dimensionId);
    }

    if (!(Boolean)this.alertSent.get(world.provider.dimensionId)) {
        this.alertPlayers(new ChatComponentText(DateHandler.getMorningText()), world);
        ((WorldSleepState)Morpheus.playerSleepStatus.get(world.provider.dimensionId)).wakeAllPlayers();
        this.alertSent.put(world.provider.dimensionId, true);
    }
   /* Inject Start */
    if (world instanceof WorldServer worldServer) {
        worldServer.wakeAllPlayers();
        return;
    }
   /* Inject End */
    world.provider.resetRainAndThunder();
}

The return before the call to resetRainAndThunder is intentional, as wakeAllPlayers also calls resetRainAndThunder

Tested ingame to verify that it works. The behavior is now

  • If Morpheus partial sleeping starts a new day, all players that were in a bed when the new day was started will get the buff
  • Normal sleeping without morpheus kicking in remains as it was before
  • Exiting a bed manually still correctly doesn't award the buff

@leumasme
Copy link
Contributor Author

0031929.mp4

@Dream-Master Dream-Master requested a review from a team August 23, 2024 19:52
@leumasme leumasme requested a review from glowredman September 1, 2024 03:31
@Alexdoru
Copy link
Member

Alexdoru commented Sep 1, 2024

looks good to me

@Dream-Master Dream-Master merged commit bbec8c1 into GTNewHorizons:master Sep 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GT5 Sleeping buff is not applied when Morpheus partial sleeping skips the night
4 participants