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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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