Jump to content

[1.18.2] How do I track things like XP and broken blocks client side on Multiplayer


Ayregon

Recommended Posts

Hi!

I am new to Forge modding (not java), and I am trying to build a statistics mod to keep track of things like how many blocks of X type has a player mined, how many times the player have received damage and how much damage has been received, xp obtained...

But I am constantly finding the problem of things working on a single player mode but not on multiplayer. Events like PlayerXpEvent.PickupXp are firing only when the server is hosted by the client.

I understand this is because this events are handled server side, and I have found workarounds like using the players inventory to keep track of the blocks, but this is very limiting.

I was wondering if there was a way to listen to those events also in the client side. I have searched and searched this forum and Google but I only find outdated or dead posts.

My code (Really simple):

@Mod.EventBusSubscriber(modid = Minestats.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class Events {
    @SubscribeEvent
    public static void onItemPickup(final PlayerXpEvent.PickupXp event) {
        Minestats.saveNewXpValue(event.getOrb().getValue(), new Timestamp(System.currentTimeMillis())); // This just saves it in a JSON file
    }
}

 

Link to comment
Share on other sites

16 hours ago, Ayregon said:
value = Dist.CLIENT

this subscribes the full class and all Events in it to the client, this explains your problem

Dist#CLIENT include the singleplayer server (IntegratedServer), but not the DedicatedServer
remove the value from the annotation and it should work

any reason why you not use the vanilla Stats system

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.