How to add effect when item is in inventory

Started by MrNick on

Topic category: Help with modding (Java Edition)

Last seen on 11:58, 27. Nov 2023
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to add effect when item is in inventory

I am creating a pet mod type thing and was wondering how would the absorption effect to the player with the pet but remove it when the pet is dropped or discarded. 

 

I tryed a few methods however all of them seemed to fail, like they if pet is not in inventory remove effect, but this means that if you don't have the pet and try to use a golden apple you will lose the effect absorption that comes with the pet. 

Last seen on 18:06, 24. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could just apply a short…
Tue, 11/07/2023 - 04:50

You could just apply a short enough duration of absorption that it wears off very quickly if the player no longer has the item in their inventory? If you have a procedure that applies ten ticks of Absorbtion on player update tick when the item is in the inventory, there'll only be a half second delay or so, though it might look a little weird in the GUI.

There are probably better methods to do this using a player-persistent logic variable, but this method will probably suffice, it's what I use for totems and whatnot.