Posted October 25, 20205 yr 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; }
October 25, 20205 yr Use ItemStack#damageItem, supply the entity, the amount of damage, and a consumer of the entity instance that executes once the item is destroyed.
October 25, 20205 yr 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)
October 25, 20205 yr 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: Which is strange because when I hover my mouse over the function this pops up: It clearly says "LivingEntity" I got confused
October 25, 20205 yr 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.
October 25, 20205 yr 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.