Jump to content

how to make food lose durability


BlakeBrad

Recommended Posts

so, i created a food which heals you and the entity hitted by it, but i want the food to lose durability everytime you hit someone. heres my event

@SubscribeEvent
public static void onDamage(AttackEntityEvent event){
    if(event.getEntityLiving().getHeldItemMainhand().getItem() == RegistryHandler.HEAL_SOUP.get()){
        if(event.getTarget().isAlive()){
            LivingEntity target = (LivingEntity) event.getTarget();

                PlayerEntity player = event.getPlayer();
                target.addPotionEffect(new EffectInstance(Effects.REGENERATION, 15*20, 2));

                if (event.getPlayer().getEntityWorld().isRemote){

                    String msg = TextFormatting.BLUE + "The mob is healing!";
                    player.sendMessage(new StringTextComponent(msg), player.getUniqueID());
                }
        }
    }
Link to comment
Share on other sites

add defaultMaxDamage(*theMaxUsesYouWant*) to your item properties when constructing the item, so you give it a finite number of uses before it breaks (keep in mind your food won't be stackable). Then you need to use ItemStack#damageItem to decrease its life when you hit an entity.

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

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.