Posted September 10, 201312 yr ok so i want to know how to get the attacking entity, Proof i have tried i have seen related things such as damagesource & livingattackevent, i cant figure out how to use these, all the examples i see of living attack event are doing things to the player, not the entity attacking the player. also all instances of dmg source i have found only work with entity not entitylivingbase which is what the entityzombie, entitySkele, etc come under. I have also found some stuff to do with event.entityliving but you cant use the getEntity(); function with this, so i am stuck. I know how to use the entity once i have a name for it, but i also need to check the item the player is holding, i think i know how to do this too but for this the dmg source has to be a player, not a mob, so HALP INSHORT i want to make the entity attacking the player(if the player is holding sword x) take damage. Use examples, i have aspergers. Examples make sense to me.
September 10, 201312 yr Fast answer: Switch player and entity in your code. Done. EntityLivingBase is a subclass of Entity by the way. Long answer: Check if attacked entity is a player instance, cast it, check for item held, if the desired one, do damage to entity attacking.
September 11, 201312 yr Author i get the idea, but i cant seem to make it work in practice. Use examples, i have aspergers. Examples make sense to me.
September 13, 201312 yr you want something like this final EntityDamageSource eds = (EntityDamageSource) e.source; final Entity play = eds.getSourceOfDamage();
September 15, 201312 yr DamageSource has a method getSourceOfDamage() that returns the Entity causing the damage. Use it like this in your LivingAttackEvent: if (event.entity instanceof EntityPlayer) { // Now you've got the player that is being attacked by something EntityPlayer player = (EntityPlayer) event.entity; if (event.source.getSourceOfDamage() != null && event.source.getSourceOfDamage() instanceof EntityZombie) { EntityZombie zombie = (EntityZombie) event.source.getSourceOfDamage(); // now you've got the zombie that's attacking the player, do what you'd like to it } } http://i.imgur.com/NdrFdld.png[/img]
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.