Posted April 15, 201411 yr 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; }
April 15, 201411 yr Author I've also tried using EntityPlayer instead of EntityLiving but it just crashes the game when the mob hits me.
April 15, 201411 yr 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
April 15, 201411 yr 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.
April 15, 201411 yr 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
April 15, 201411 yr Author Use EntityLivingBase if you want to affect players and mobs. Changing it to this worked, thank you!
April 15, 201411 yr 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.
April 16, 201411 yr 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.