Topic category: Help with Minecraft modding (Java Edition)
Hello there! I am currently working on a new variant of the Cow in my Minecraft Mod (the Moobloom, a flower Cow) and I was curious on how I can make this new mob milkable with a specific item, similar to how its vanilla counterparts function in the base game. (For example, normal Cows can be milked only with a bucket (which gives Milk Buckets) and Mooshrooms can be milkable with a Bowl (to give Mushroom Stew or Suspicious Stew items,) and I was wanting my custom Cow mob to give an item to the player (such as Suspicious Stew or Milk) whenever it would be right clicked with a specific item (like a Bowl or Bucket.)) I have been trying to figure out how to resolve this issue for quite a bit, but I cannot figure out how to make a procedure in particular that doesn't make all mobs in the game milkable with the specific item I was using! Thank you kindly for your help, Happy April Fools' Day!
There's a global trigger for 'entity right clicked,' and you can then use the 'get item in main hand' and 'get item in off-hand' functions to determine what item the player is holding when the entity is clicked. So you would need to make a procedure with this trigger, check if the event/target entity is your custom mob, check if the item in the source entity's main hand is a bucket, and then set your custom bucket in the player's main hand. (Or shrink the item in their main hand for one, and add one custom item to their inventory, if it's something stackable.)