Jump to content

[1.10]PlayerTickEvent only works on one client.


oldcheese

Recommended Posts

    @SubscribeEvent
    public void regenStats(TickEvent.PlayerTickEvent e) {
        if (!e.player.getEntityWorld().isRemote && e.phase == TickEvent.Phase.END) {
            if (ticks < 200) {
                ticks++;
            }
            if (ticks == 200) {
                final IBarHandler handler = getHandler(e.player);
                handler.addFatigue(25);
                ticks = 0;
                tinyRefresh(e.player); //updates client with server data.
            }
        }
    }

 

The loop is done kinda shittily at the moment, I originally had it doing different things at different ticks.

 

 

Anyway. The added fatigue only seems to process for the latest player to have logged in.

 

Is this a specific effect of this Event. It'd really be easier to use this event. My goal is to periodically 'regenerate' fatigue on every client. It doesn't have to be at once, but I do want there to be updates.

 

I guess I could use a ServerTickEvent or a WorldTickEvent, loop through all available players in the world and adjut their fatigue and refresh, which would work spotlessly. I'm just wondering what exactly is the deal with PlayerEvent. 

 

 

Edit: I've changed it succesfully to the code below: 

    @SubscribeEvent
    public void regenStats(TickEvent.WorldTickEvent e) {
        if(!e.world.isRemote && e.phase == TickEvent.Phase.END){
            if(ticks < 200){
                ticks++;
            }else{
                ticks = 0;
                List players = e.world.playerEntities;
                for(int i = 0; i < players.size(); i++){
                    EntityPlayer player = (EntityPlayer)players.get(i);
                    final IBarHandler handler = CustomDataHandlerBar.getHandler(player);
                    handler.addFatigue(25);
                    tinyRefresh(player);
                }
            }
        }
    }

 

but I'm still wondering why PlayerTicks don't work apart from the last player to join.

Edited by oldcheese
Added fixed code.
Link to comment
Share on other sites

Well, you're clearly counting ticks as a global value, not a per-player value. This is bad.

Imagine you have 200 players logged in...

 

World ticks (time 1), all entities are ticked...

Player1 ticks, ticks is now 1.

Player2 ticks, ticks is now 2.

Player3 ticks, ticks is now 3.

Player4 ticks, ticks is now 4.

Player5 ticks, ticks is now 5.

Player6 ticks, ticks is now 6.

...

Player198 ticks, ticks is now 198.

Player199 ticks, ticks is now 199.

Player200 ticks, ticks is now 200, Player200 is fatigued.

World ticks (time 2), all entities are ticked...

Player1 ticks, ticks is now 1.

Player2 ticks, ticks is now 2...

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, oldcheese said:

but at the same time it's a lot easier to just have one global value and use WorldTicks. It seems a little bit more efficient right now.

If by "more efficient" you mean "as there are more players, everyone fatigues faster."

If you want to use world ticks, do world.getTotalWorldTime() % 200 == 0. The slight discrepancy of a player joining / leaving off-cycle will be pretty much unnoticeable.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.