In my mod I wanted my custom mob to spawn some particles around it when it was killed, but I can't get it to work. And this is the code I'm trying to use.
Did you correctly register the event? Also, you should try with different particles, given that reddust might be something that appears really quickly, and might be really small.
If it were me I would override the method attackEntityFrom(DamageSource damageSource, float amnt) inside the mob's class.
In the method, call super.attackEntityFrom(damageSource, amnt) first and then check if the entity's health is at or below zero. If it is AND the code is running client-side (world.isRemote is true), spawn particles.
Also, like Ferdz said, most Minecraft code uses a for loop when calling world#spawnParticle. Otherwise one and only one particle will appear, which is not very visible. Try spawning at least a dozen.
Happy modding!
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
#attackEntityFrom is only called on the server if the attacking entity is not a player, so you may want to do what vanilla does and instead of trying to spawn them directly from there, instead set the entity state and use #handleHealthUpdate, e.g.:
private static final byte CUSTOM_FLAG = 10; // don't want to conflict with vanilla flags - check the super classes
#attackEntityFrom:
worldObj.setEntityState(this, CUSTOM_FLAG); // sends this bit flag to this entity's #handleHealthUpdate method
@Override
@SideOnly(Side.CLIENT)
public void handleHealthUpdate(byte flag) {
if (flag == CUSTOM_FLAG) {
// spawn your particles here
} else {
super.handleHealthUpdate(flag);
}
}
In my mod I wanted my custom mob to spawn some particles around it when it was killed, but I can't get it to work. And this is the code I'm trying to use.
Help my dragons! Just give 'em a click!
Did you correctly register the event? Also, you should try with different particles, given that reddust might be something that appears really quickly, and might be really small.
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
If it were me I would override the method attackEntityFrom(DamageSource damageSource, float amnt) inside the mob's class.
In the method, call super.attackEntityFrom(damageSource, amnt) first and then check if the entity's health is at or below zero. If it is AND the code is running client-side (world.isRemote is true), spawn particles.
Also, like Ferdz said, most Minecraft code uses a for loop when calling world#spawnParticle. Otherwise one and only one particle will appear, which is not very visible. Try spawning at least a dozen.
Happy modding!