Jump to content

Recommended Posts

Posted

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.

Posted

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!

Posted

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.

Posted

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?

 

 

 

Posted

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
Posted

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.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.