bytzo / sessility

AFK utilities for the server: Keeps track of sessile creatures, more often known as "AFK players".
https://modrinth.com/mod/sessility
MIT License
4 stars 5 forks source link

Feat: Adding Sessile Time Statistic #9

Open daniromome opened 1 month ago

daniromome commented 1 month ago

Hey, I would like to propose a sessile time scoreboard stat, this would allow for better play time statistics by making a remainder of the minecraft:custom:play_time stat with the sessile time

I tried implementing this myself but I really struggled with no FAPI and the official mojang mappings since I'm really new to minecraft mod development

This is an example of what that might look like in the actual code

PlayerMixin.java

@Inject(method = "tick", at = @At("HEAD"))
private void awardSessileStat(CallbackInfo ci) {
    var player = (Player) (Object) this;
    if (((SessilePlayer) player).isSessile()) player.awardStat(SessilityStats.SESSILE_TIME);
}

The only missing thing would be to register the statistic in the registry which may be done with something like

Registry.register(BuiltInRegistries.CUSTOM_STAT, "sessile_time", SessilityStats.SESSILE_TIME);
Stats.CUSTOM.get(SessilityStats.SESSILE_TIME, StatFormatter.TIME);

I ran into an issue while doing that though since I'm lost on where it is a good place to call the registration, an exception was thrown Registry is already frozen and I was unable to continue from there

Hopefully you all think this would be a valuable feature to have and find some extra time to implement! If you offer guidance I can also volunteer :)

daniromome commented 1 month ago

I managed to kind of get started with the implementation of this feature here https://github.com/daniromome/sessility/tree/feature/sessility_stat but whenever player opens statistics screen client side the client gets disconnected and it doesn't seem like theres autocompletion on the scoreboard. I imagine it has to do with network packets between server and client but that makes this feature way harder to do than I initially anticipated

bytzo commented 4 weeks ago

Thanks for looking into this, having sessile time integrated into the game statistics is something I have always wanted but never got around to implementing.

I'm not familiar with how the game statistics work, but perhaps modifying the registry on the server requires the registry to also be modified in the same way on the client? If this is true, it would require Sessility to also be installed on the client, which is something we want to avoid—Sessility is strictly a modification for the server.

If we aren't able to add an additional statistic, perhaps there could be an option for disabling the counting of the play time statistic when the player is considered sessile?

daniromome commented 3 weeks ago

I think it won't be necessary to modify the registry on the client. I think we could just prevent the stat from being sent to it so they don't crash and have the custom stat as a scoreboard objective

That last suggestion is a really good solution but I'm not quite sure how to read the config file from a mixin (new to minecraft mod development)