Jump to content

iEviiL

Members
  • Posts

    1
  • Joined

  • Last visited

iEviiL's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I made a method for filling an empty bowl with milk (a modded milk bowl item) when right-clicking a cow by handling the PlayerInteractEvent.EntityInteract event. However, seems like the method is called twice since each time that I right-click a cow two bowls are extracted and two milk bowls are added to the player's inventory. Any idea on why this happens? Here I attach the code of the method for handling the event: @SubscribeEvent public static void onRightClickBowl(PlayerInteractEvent.EntityInteract event) { if(!event.getLevel().isClientSide()) { // if the target entity is a cow if (event.getTarget() instanceof Cow cow) { // check if the target entity is an adult cow and if the player holds an empty bowl if ((cow.getAge() != -1) && event.getEntity().getItemInHand(InteractionHand.MAIN_HAND).getItem().equals(Items.BOWL)) { event.getEntity().setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.BOWL, event.getEntity().getItemInHand(InteractionHand.MAIN_HAND).getCount() - 1)); event.getEntity().addItem(new ItemStack(ModItems.MILK_BOWL.get())); } } } } Thanks in advance!!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.