#merge two Text. together in tooltips

17 messages · Page 1 of 1 (latest)

serene remnant
#

what happens currently is that they appear in seperate lines, and i want them both in the same line.

left fjordBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

golden monolith
#

idk about merging texts, but you can just use inline color codes

serene remnant
#

oh sorry forgot to close this

#

i found a solution

#

Following along with a tutorial from Sept of '23 and adjusting sections that don't work in the 1.21 version today. I've figured out most things on my own, but there's a section about tooltips that's got me stuck.

I can add multiple colors to one tooltip pretty concisely by blending old methods with the new events and arguments, but no matter what I try this first section always breaks into three separate lines.

ItemEvents.modifyTooltips(event => {
    event.add('kubejs:face', Text.darkGreen(
        "It's still you."
    ))

    event.modify('kubejs:thermblock', {shift:false}, tooltip => {
        tooltip.insert(1, [Text.of(`Hold `).gold(),
        Text.of(`[Shoopt] `).aqua(),
        Text.of(`to see description`).gold(),
        ])
    })
    event.modify('kubejs:thermblock', {shift:true}, tooltip => {
        tooltip.insert(1, [
             Text.of(`What fresh`).red(),
        ]),
        tooltip.insert(2, [
            Text.of(`hell is this?`).red(),
       ])
    })
lunar lichenBOT
#

[➤](#1298529434416054303 message)
Following along with a tutorial from Sept of '23 and adjusting sections that don't work in the 1.21 version today. I've figured out most things on my own, but there's a section about tooltips that's got me stuck.

I can add multiple colors to one tooltip pretty concisely by blending old methods with the new events and arguments, but no matter what I try this first section always breaks into three separate lines.

ItemEvents.modifyTooltips(event => {
    event.add('kubejs:face', Text.darkGreen(
        "It's still you."
    ))

    event.modify('kubejs:thermblock', {shift:false}, tooltip => {
        tooltip.insert(1, [Text.of(`Hold `).gold(),
        Text.of(`[Shoopt] `).aqua(),
        Text.of(`to see description`).gold(),
        ])
    })
    event.modify('kubejs:thermblock', {shift:true}, tooltip => {
        tooltip.insert(1, [
             Text.of(`What fresh`).red(),
        ]),
        tooltip.insert(2, [
            Text.of(`hell is this?`).red(),
       ])
    })
golden monolith
#
§0this text is black, §1this one dark blue```
boreal stratus
#

Please don't, these are legacy format codes

#

Instead, use:

Text.ofString('Red text').color('red').append(Text.ofString('Green text').color('green')),
#

Benefit of that is that you can set any color, not just 16 legacy format colors

#

For example:

ItemEvents.modifyTooltips(event => {
  event.add('minecraft:stone', [
    Text.ofString('Red text').color('red').append(Text.ofString('Green text').color('green')),
  ])
})

results in:

#

You can also append to empty component if you don't want first component's settings to be inherited:

ItemEvents.modifyTooltips(event => {
  event.add('minecraft:stone', [
    Text.empty()
      .append(Text.ofString('Red text').color('red'))
      .append(Text.ofString('Green text').color('green')),
  ])
})
#

Compare to the case where you start with a text component with text that you formatted:

ItemEvents.modifyTooltips(event => {
  event.add('minecraft:stone', [
    Text.ofString('Red text')
      .color('red')
      .bold()
      .append(Text.ofString('Green text').color('green')),
  ])
})