How would I go about making a custom minecraft item that triggers events when it's used?

How would I go about making a custom minecraft item that triggers events when it's used? - Content female shopaholic lying on floor at home in messy room and making order in online store while using netbook

In specific, I'm looking to code a sword that, when used to block, advances the time of day by 4800. Hopefully this can be accomplished with command blocks only, as I'd rather stick to vanilla minecraft.

So far, I've only figured out how to correctly employ custom names and enchantments, so this is all I've got for the command:

/give @p iron_sword 1 0 {display:{Name:"Longdark Blade",Lore:"[Long ago, it was thought that metals","could control the stars themselves...]"}}





Pictures about "How would I go about making a custom minecraft item that triggers events when it's used?"

How would I go about making a custom minecraft item that triggers events when it's used? - Woman in Red Long Sleeve Shirt Sitting Beside Woman in Gray Sweater
How would I go about making a custom minecraft item that triggers events when it's used? - Yellow Pikachu Plushmascot
How would I go about making a custom minecraft item that triggers events when it's used? - Young woman watching movie in headphones in messy room





How to Create Custom Items in Minecraft 1.18




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Andrea Piacquadio, Thirdman, mentatdgt, Andrea Piacquadio