Posted December 22, 201410 yr Sorry if this is a (very) derpy question, but how do I get the EntityPlayer from an event. I have tried casting it as EntityPlayer, though no luck @SubscribeEvent public void onEntityLivingDeath(LivingDeathEvent event) { if (event.entityLiving instanceof EntityWolf && ((EntityWolf)event.entityLiving).isTamed()) { ((EntityPlayer) event.entityLiving).addChatComponentMessage(new ChatComponentText("Your Wolf Has Sadly Died")); } } But it just crashes.
December 22, 201410 yr Author Of course it crashes. You just checked if the entity is a wolf and then say "hey, treat this wolf as if it were a player". Good job. To get the owner, use getOwner on the wolf. Note that that will return null if the player is not online. Found that out a few minutes ago, but thanks anyway. How do I send a chat message to the owner?
December 22, 201410 yr Tried with googling it yourself? When I goolged it some months ago, I found this: player.addChatMessage(new ChatComponentText("SOME MSG")); Since English is not my mother tongue, my sentences may are confusing. I'm coding java for a long time now - just MC and forge stop me sometimes.
December 23, 201410 yr Author Tried with googling it yourself? When I goolged it some months ago, I found this: player.addChatMessage(new ChatComponentText("SOME MSG")); *facepalm* Im not stupid. There is no EntityPlayer in my event...
December 23, 201410 yr Author To get the owner, use getOwner on the wolf. Note that that will return null if the player is not online. Yea, I tried that, though it doesn't seem to have the .addChatMessage in it for some reason
December 23, 201410 yr Author Because it returns an EntityLivingBase. Check if it's a player first. Thanks, works now. One last question though. How do I get a world, because I need to check if world.isRemote
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.