Extending the item class
Extending the Item class:
public class MyItem extends Item {
public MyItem(Identifier id) {
super(id, Material.PAPER);
createTooltip(tooltip);
updateTooltip();
}
@Override
public void createTooltip(Tooltip tooltip) {
tooltip.lines.clear();
tooltip.addLine(Component.text("Sends a message whenever a block is broken!"));
}
@Override
public ActionResult postMine(LivingEntity source, Block target) {
source.sendMessage(Component.text("You broke a Block!"));
return ActionResult.PASS;
}
}
then you have to register it like this:
ITEMS.register("my_item", MyItem::new);
There are other methods that you can override:
ActionResult postHit(LivingEntity source, Entity target
ActionResult onUseOn(UseContext ctx)
void onUse(LivingEntity source, EquipmentSlot hand)
void onCraftedBy(Player player)
03 October 2025