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'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;
}

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)

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

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.

  • Author

The problem solved with this code:

 

stack.damageItem(1, attacker, (p_220045_0_) -> {
   p_220045_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
});

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.