ItemEvents.modifyTooltips


#Info

This event can be used from either client or server side.
To simply add tooltip to item you can use event.add(filter, Text[]) method.
You can register dynamic tooltip handler from server side but the handler itself has to be on client side.
Available methods in ItemEvents.modifyTooltips event:
  • event.add(filter, Text[]) - shortcut method to just add text lines to item
  • event.add(filter, TooltipRequirements, Text[]) - same method but 2nd argument adds requirements. See below
  • event.modify(filter, (tooltip: TooltipActionBuilder) => void) - modify tooltip with no requirements
  • event.modify(filter, TooltipRequirements, (tooltip: TooltipActionBuilder) => void) - modify tooltip with requirements
  • event.modifyAll((tooltip: TooltipActionBuilder) => void) - modify all tooltips with no requirements
  • event.modifyAll(TooltipRequirements, (tooltip: TooltipActionBuilder) => void) - modify all tooltips with requirements

#Basic Example

ItemEvents.modifyTooltips(event => {
	// Show this tooltip for all red blocks
	event.add(/minecraft:red_/, Text.red('Red!'))
	// Only show this text when shift is not pressed
	event.add('minecraft:campfire', {shift: false}, Text.gray('Campfire :D'))
	// Only show this text when shift is pressed
	event.add('minecraft:campfire', {shift: true}, Text.gray('Campfire :('))
})
ItemEvents.modifyTooltips(event => {
	event.modify('minecraft:pink_concrete_powder', tooltip => {
		// Remove block title
		tooltip.removeLine(0)
		// Insert text at top of list
		tooltip.insert(0, Text.of('funi block').color(0xFFA5F7))
	})
})

#Text actions

All available methods in tooltip of event.modify:
  • tooltip.dynamic(id)
  • tooltip.add(Text[]) - adds text lines at end of tooltip
  • tooltip.insert(index, Text[]) - inserts text lines in middle of tooltip at specific line
  • tooltip.removeLine(index) - removes specific line
  • tooltip.removeText(Text) - removes line if any part of component's content matches input
  • tooltip.removeExactText(Text) - removes line if it matches component exactly
  • tooltip.clear() - clears entire tooltip
Tooltip actions are executed in order, so if you call tooltip.removeLine(0) twice, it will remove first two lines

#Tooltip Requirements

Available requirement properties:
  • shift: true/false - if shift key is pressed
  • ctrl: true/false - if ctrl key is pressed
  • alt: true/false - if alt key is pressed
  • advanced: true/false - if advanced tooltips are enabled (F3+H)
  • creative: true/false - if player is in creative mode
  • stages: {stageName: true/false} - if player has specific stage
You can combine multiple properties, e.g. {shift: true, ctrl: false, advanced: true}