Posted August 24, 20205 yr 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()); } } }
August 29, 20205 yr 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
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.