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

I currently have the following code, but my mob doesn't apply potion effects when it hits you.

 

@Override
public boolean attackEntityAsMob(Entity par1)
{
	if (super.attackEntityAsMob(par1))
	{
		if (par1 instanceof EntityLiving)
		{
			((EntityLiving)par1).addPotionEffect(new PotionEffect(Potion.blindness.id, 12 * 20, 0));
		}
		return true;
	} else
		return false;
}

  • Author

I've also tried using EntityPlayer instead of EntityLiving but it just crashes the game when the mob hits me.

Try this.  I might have some of the syntax wrong as I'm doing this from memory.

 

 

 

 

@Override

public boolean attackEntityAsMob(Entity par1) {

 

if (super.attackEntityAsMob(par1)) {

 

if (par1 instanceof EntityLiving) {

 

EntityPlayer player = (EntityPlayer) par1;

 

if (player != null) {

 

player.addPotionEffect(new PotionEffect(Potion.blindness.id, 12 * 20, 0));

 

return true;

 

}

 

}

 

} else {

 

return false;

 

}

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

If that entity attacks a non-player we will have issues.

@Override
   public boolean attackEntityAsMob(Entity par1) {
   
      if (super.attackEntityAsMob(par1)) {
      
         if (par1 instanceof EntityPlayer ) {
         
            EntityPlayer player = (EntityPlayer) par1;
            
            if (player != null) {
         
               player.addPotionEffect(new PotionEffect(Potion.blindness.id, 12 * 20, 0));
               
               return true;
            
            }
            
         }
         
      } else {
      
         return false;
         
   }

 

ALSO EntityPlayer does NOT extend EntityLiving.

It will not have an issue if it attacks a non Player other than it won't apply the potion, but that seemed to be the goal from original post.

 

I have used this setup many times with zero issues.

Long time Bukkit & Forge Programmer

Happy to try and help

It will not have an issue if it attacks a non Player other than it won't apply the potion, but that seemed to be the goal from original post.

 

I have used this setup many times with zero issues.

This is your code:

      if (super.attackEntityAsMob(par1)) {
      
         if (par1 instanceof EntityLiving) {
         
            EntityPlayer player = (EntityPlayer) par1;
            
            if (player != null) {
         
               player.addPotionEffect(new PotionEffect(Potion.blindness.id, 12 * 20, 0));
               
               return true;
            
            }
            
         }
         
      } else {
      
         return false;
         
   }

 

If par1 instanceof EntityLiving, par1; par1 CANNOT be cast to EntityPlayer as EntityPlayer does NOT extend EntityLiving.

Good point darty11.  I did have a typo in what I put up, forgot to change one of his variables.

 

After reading his posts, it looks like he wants it to be any living thing, so probably needs this.

 

 

 

 

@Override

  public boolean attackEntityAsMob(Entity par1) {

 

      if (super.attackEntityAsMob(par1)) {

     

        if (par1 instanceof EntityLivingBase) {

       

            EntityLivingBase e = (EntityLivingBase) par1;

           

            if (e != null) {

       

              e.addPotionEffect(new PotionEffect(Potion.blindness.id, 12 * 20, 0));

             

              return true;

           

            }

           

        }

       

      } else {

     

        return false;

       

  }

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

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.