#Adding tooltips in a server script

107 messages · Page 1 of 1 (latest)

pliant trout
#

It'd be one thing if all i wanted was to just add lore to an item. what i'm trying to achieve is a tooltip with a functioning shift option to show more info. the issue is that client scripts cant run on a server (unless you f3+t every time you join a server session)
I was referencing to stuff like this #off-topic message but this is from wayy back and im not sure if its even what i'm looking for

viral hearthBOT
#

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

smoky girderBOT
#

[Quote ➤](#off-topic message) ```kt
package ky.someone.mods.vacuous.util

import net.minecraft.ChatFormatting
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.*
import net.minecraft.util.Mth
import java.util.function.UnaryOperator

@JvmField
val TOOLTIP_MAIN = UnaryOperator<Style> {
it.withColor(0xfcb95b)
}

@JvmField
val TOOLTIP_SIDENOTE = UnaryOperator<Style> {
it.withColor(0x0fd1ec).withItalic(true)
}

@JvmField
val COLOUR_TRUE = UnaryOperator<Style> {
it.withColor(0x4ecc8d)
}

@JvmField
val COLOUR_FALSE = UnaryOperator<Style> {
it.withColor(0xfd6d5d)
}

@JvmField
val COLOUR_INFO = UnaryOperator<Style> {
it.withColor(0x5555ff)
}

fun appendInfoTooltip(tooltip: MutableList<Component>, info: List<Component>) {
val isShift = Screen.hasShiftDown()
tooltip.add(
"ℹ".asText()
.append(" (Shift)".asText().withStyle(if (isShift) ChatFormatting.DARK_GRAY else ChatFormatting.GRAY))
.withStyle(COLOUR_INFO)
)
if (isShift) {
tooltip.addAll(info)
}
}

val tickGreen: MutableComponent
get() = "✔".asText().withStyle(COLOUR_TRUE)

val tickRed: MutableComponent
get() = "✘".asText().withStyle(COLOUR_FALSE)

fun styledBool(b: Boolean): MutableComponent = if (b) tickGreen else tickRed

// returns a new style using "parent" with a colour representing
// the given ratio of the range [0, 1] (0 = red, 1 = green)
fun styledRatio(parent: Style, ratio: Double): Style = parent.withColor(Mth.hsvToRgb((ratio / 3).toFloat(), 1f, 1f))

fun asStyledValue(value: Number, max: Number, formattedValue: String = value.toString()): MutableComponent =
formattedValue.asText().withStyle(styledRatio(Style.EMPTY, value.toDouble() / max.toDouble()))

fun String.asText(): MutableComponent = TextComponent(this)
fun String.asTranslate(vararg replacements: Any): MutableComponent = TranslatableComponent(this, *replacements)

operator fun MutableComponent.plus(other: String): MutableComponent = append(other)
operator fun MutableComponent.plus(other: Component): MutableComponent = append(other)

pliant trout
sacred drum
#

why do you need to do this in server scripts?

pliant trout
#

cause client scripts dont work on servers, i mean they do but you have to do f3+t to see the tooltips

sacred drum
#

well yeah obviously they dont :P

#

buti still dont know why you need tooltips on server

#

server doesnt do tooltips

pliant trout
#

well im creating a modpack for my friends and i to play on and once i get a server going its going to be really annoying that they wont be able to see some tooltips i add onto certain items

sacred drum
#

well if they add them correctly, they will see it hmmm

pliant trout
#

well yeah i mean they'll all have the client script except even though both server and client have the script it still doesnt show til you reload textures

#

even doing /kubejs reload client_scripts doesnt work without f3+t

sacred drum
#

the client script folder is completely ignored on a dedicated server

pliant trout
#

right

#

is a shift button detection possible on server?

#

or is that client as well

sacred drum
#

client

pliant trout
#

dang

sacred drum
#

why not just do it in client scripts?

#

im still confused lol

pliant trout
#

i did on client scripts, though when i go to a dedicated server they dont work

#

hence me tryna get a server script going somehow

sacred drum
pliant trout
#

is it possible to remove certain nbt from an item? i could maybe use lore

#

oh you think?

#

one sec lemme post it

sacred drum
#

NBT is not attached to items

#

nbt is put on items when the player gets the items

pliant trout
#

yeah i mean i was thinking of maybe setting a tick script to put nbt on each item that a player recieves

#

cursed af tho to do that

sacred drum
#

youre doing that XY thing worry

smoky girderBOT
#

The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.

This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.

Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.

pliant trout
smoky girderBOT
#

Paste version of originskeytooltips.js from @pliant trout

pliant trout
#

i just dont know how to do it lmao

sacred drum
#

what is OriginsClient.usePrimaryActivePowerKeybind.key.displayName confused_dog_lex

#

oh i get it

pliant trout
#

ye keybind in the text

#

wasnt me who figured that out either

#

aint no way rofl

desert idol
#

You can just… put client script on git for ur friends?

pliant trout
#

no i mean itll be on curseforge and they'll download everything

sacred drum
#

btw quick sidenote, instead of Text.of('-25% ').red() you can just do Text.red('-25% ')

desert idol
#

Vscode can even commit for you

sacred drum
pliant trout
#

im saying that even though its the same on both sides it doesnt load the tooltips til you refresh textures with f3+t

sacred drum
#

can you show me your client log when youre log in the first time to a server?

pliant trout
#

thanks anyways spoke

#

kk lemme restart the craft

desert idol
sacred drum
#

ye but assets have nothing to do with tooltips

pliant trout
#

wait what

#

it just worked

#

am i crazy?

sacred drum
#

um

pliant trout
#

no client script errors either

sacred drum
#

youre welcome?

pliant trout
#

omg

#

ty lmao

sacred drum
#

happens to me all the time

pliant trout
#

it wasnt working with the other script i had and now that i tested it out with this one it works

sacred drum
#

online and irl

pliant trout
#

lmaoo

#

thats such a relief

#

thank you so much lmao

#

for tryna help me lmao

sacred drum
#

had something similar happen at work a while ago

pliant trout
#

oh fr

sacred drum
#

spent a few hours trying to get something to work

#

then i called a coworker

#

and instantly worked

pliant trout
#

lmaooooo

sacred drum
#

i was like

pliant trout
#

fair enough lmao

sacred drum
pliant trout
#

hahahhaha

#

yo this actually saves me so much work tbh

#

aight well ty again i guess

viral hearthBOT
#

Ticket closed!

sacred drum
#

you reopened the ticket with the reaction

pliant trout
#

oof

#

actually while i have it open

pliant trout
# sacred drum ~~you reopened the ticket with the reaction~~
event.addAdvanced(['#artifacts:artifacts'], (item, advanced, text) => {
        if (item.nbt.Springy){
            text.add([
                Text.of('Quality: ').gray(),
                Text.of('Springy').blue()   
            ])
            text.add([
                Text.of('When in any curios slot:').gray() 
            ])
            text.add([
                Text.of('+0.5 Jump Height').blue()  
            ])
        }
    })
    })``` This was the client script i was talking about that wouldnt work til you did f3+t
#

guess it mightve been because of the item tag

#

also even just reacting to posts reopens it? jeez fair enough

sacred drum
viral hearthBOT
#

Ticket closed!

pliant trout
#

wow the timing

sacred drum
#

lol

pliant trout
#

lmao

sacred drum
#

i was typing about your snippet

pliant trout
#

got it

sacred drum
#

xD

pliant trout
#

hahahha

sacred drum
#

but it works now?

pliant trout
#

yeah

sacred drum
#

ah cool

pliant trout
#

guess it doesnt work right if you go by tags

sacred drum
#

tags are fucky sometimes

pliant trout
#

lmao

#

aight ill close now haha ty again