Jump to content

[1.9] Crash when getting EntityPlayer from PlayerTickEvent


Ringosham

Recommended Posts

This only happened on 1.9. Here's what I am trying to do.

private boolean msgShown = false;
@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent event) {
if (!msgShown) {
  event.player.addChatMessage(new TextComponentString("Text 1"));
  Minecraft.getMinecraft().thePlayer.addChatMessage(new TextComponentString("Text 2"));
  msgShown = true;
}
}

Both of these lines work in 1.7.10 - 1.8.9. But in 1.9 I got NullPointerException with Ticking player when opening a world. I don't really know why it doesn't work. I'm using the latest version of Forge for 1.9 ???

I'll post the log if you need to.

Link to comment
Share on other sites

The tick event is client and server side so this line should cause a problem on the server side in every minecraft version

Minecraft.getMinecraft().thePlayer.addChatMessage(new TextComponentString("Text 2"));

 

Logs would be helpful.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

The tick event is client and server side so this line should cause a problem on the server side in every minecraft version

Minecraft.getMinecraft().thePlayer.addChatMessage(new TextComponentString("Text 2"));

 

Logs would be helpful.

Interesting, that worked in the previous versions......

Oh well, thanks for the help. (Now I feel kinda dumb.)

Link to comment
Share on other sites

MC#thePlayer is the client player which you control.

 

This event is fired for server and client sides - for EVERY player in all server worlds AND for every player in MC#theWorld (client has only one world).

 

Proper way to access player: event.player

 

Additionally: This event has 2 phases (fired twice per tick) - use event.phase to pick ONE.

 

Next: Learn @SideOnly:

http://www.minecraftforge.net/forum/index.php/topic,22764.0.html

 

Also: If you want to only ever use this to display stuff for MC#thePlayer - use ClientTickEvent registered from ClientProxy. That one is fired for client only and can safely use MC#thePlayer.

1.7.10 is no longer supported by forge, you are on your own.

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.