Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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!

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!

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

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?

 

 

 

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.