Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • 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. :o

 

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?

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.

  • 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...

  • 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

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.