Posted November 3, 201311 yr Hi, I am trying to make a sword that damages the player when they swing the sword. So far, I have been unable to figure out how to do that. If anyone could help point me in the right direction, that would be great. Thanks! EDIT: I figured out how to check if the player is swinging the sword. You use the method @Override public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) { //What you want here return false; } in the new sword class. However, I still need to figure out how to damage the player.
November 3, 201311 yr Hi, Hmm... Well I don't think there is a way to stop the sword from damaging the person you swing it at i.e. if you swing it at a zombie, you will damage the zombie. But there should be 2 such methods- onSwordSwing() - something like that damageEntity(Entity entity) - something like that I'll look up the sword classes and other classes. Will try to help you ASAP. Regards, Ablaze. Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze" Currently: Making a mod!
November 3, 201311 yr You would want to use this event: AttackEntityEvent (net.minecraftforge.event.entity.player.AttackEntityEvent) I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!
November 3, 201311 yr Author Thanks for that, but that only registers when I'm swinging at an entity. I was looking for something that happens whenever I swing the sword, regardless of what I'm pointing at. Thank you for your help though.
November 6, 201311 yr Thanks for that, but that only registers when I'm swinging at an entity. I was looking for something that happens whenever I swing the sword, regardless of what I'm pointing at. Thank you for your help though. If you're using this: public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {...} Then you've got the swinging entity. From there, would something like "EntityLivingBase.attackEntityFrom(DamageSource.generic, (float)dmg)" do what you're trying to do?
November 7, 201311 yr If I am not mistaken, if you want it to be a player: public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) { if (entityLiving instanceof EntityPlayer) { // Insert Damage Code Here (I'm trying to remember on the spot) It's obvious if you look through the ItemSword class. The damage is getDamageVsEntity, I believe } } -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
November 7, 201311 yr If I am not mistaken, if you want it to be a player: ... That's another way to do it. OP didn't specify whether he wanted it to count as a sword hit on the wielder, or just have a "punishment" for swinging it (like a cursed sword). The other reason I went with directly damaging the entity was that it would beat down a zombie who managed to pick up the sword.
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.