Jump to content

Recommended Posts

Posted

Hi!

I'm new to modding and the mod I'm creating has a weapon which attacks specific entities with more damage. I overrided the hitEntity() function from SwordItem and the damage stuff works fine, but the sword's durability does not go down. I found this damageItem() function, but whatever I pass into this it does not work. Here is the unfinished code:

 

@Override
public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker){

    if(target instanceof ZombieEntity || target instanceof SkeletonEntity || target instanceof HuskEntity || target instanceof StrayEntity){
        target.attackEntityFrom(DamageSource.GENERIC, getAttackDamage() + 5);
    }else{
        target.attackEntityFrom(DamageSource.GENERIC, getAttackDamage() + 1);
    }

    damageItem(stack, 1, )

    return true;
}
Posted
34 minutes ago, MostafaSabry55 said:

Just saying, if you want to see examples of what you can do with that consumer take a look at what minecraft does (highlight the function then right click and chose view call hierarchy)

I don't have the "vies call hierarchy" option in IntelliJ. 

 

I tried to use every single entity i have access to, but none of them worked.  It says the following when I put "target" and "attacker" in the function: 


1979299784_Screenshot(8).png.9c8bfc93b433703ec6af4025b693ee17.png

 

Which is strange because when I hover my mouse over the function this pops up:

 

image.png.55b281bbde7a91a3b1cc99270c3efef6.png

 

It clearly says "LivingEntity" 

I got confused

Posted

The type is Consumer<T>, that is a function that accepts a single parameter of type T (in this case, LivingEntity) that is to be run when the item is broken.

This is what handles the player's hand animation when their tool breaks, among other things. Look for existing calls to this method to see what they pass.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.