Bossbar e titoli: stato persistente, tempistiche e divisione valore/massimo
Una bossbar sopravvive ai riavvii, mentre un titolo no. Ecco il pattern crea-e-modifica, le tempistiche di dissolvenza spesso invertite e come gestire una barra di avanzamento.
Entrambi mostrano testo sullo schermo e le somiglianze finiscono qui. I titoli sono usa e getta; le bossbar sono oggetti persistenti da gestire.
Le bossbar hanno uno stato
/bossbar add my:timer {"text":"Time left"}
/bossbar set my:timer players @a
/bossbar set my:timer max 600
/bossbar set my:timer value 600
/bossbar set my:timer color red
/bossbar set my:timer style notched_10
Un id, poi i comandi per modificarlo. I punti su cui ci si confonde:
- La barra è invisibile finché non ha giocatori. Crearne una senza mai eseguire
set ... players produces nothing, with no error.
- Persiste nel salvataggio del mondo. Una barra creata per un minigioco sarà ancora lì nella prossima
sessione. /bossbar remove when finished, or they accumulate.
valueandmaxare separate, e la barra mostravalue / max. Setting only
value on a bar whose max is still 100 gives nonsense fill.
Colori: pink white red orange yellow green blue purple. Styles: progress notched_6 notched_10 notched_12 notched_20.
Gestire un conto alla rovescia
/bossbar set my:timer value 599
una volta al secondo da una funzione a ripetizione è l'intero meccanismo. Non esiste un timer integrato. Anche rileggerlo è utile:
/execute store result score @s Left run bossbar get my:timer value
bossbar get supports value, max, players and visible, which makes a bossbar a workable global variable when you want the player to see it.
I titoli sono transitori
/title @a times 10 70 20
/title @a subtitle {"text":"Get ready"}
/title @a title {"text":"Round 2"}
Tre cose in questo ordine, e l'ordine conta:
timesfirst. Impostarlo dopo il titolo non ha effetto sul titolo già mostrato.subtitlebeforetitle. Il sottotitolo da solo non mostra nulla; inviare il titolo
è ciò che fa apparire la coppia. Al contrario, il primo viene mostrato senza sottotitolo.
times is fadeIn stay fadeOut in tick — 20 tick al secondo. 10 70 20 is half a second in, three and a half held, one out. People set 1 1 1 and wonder why nothing appears: three ticks total is a flash.
l'actionbar è separata
/title @a actionbar {"text":"Saved"}
La riga sopra la hotbar. Ignora times entirely — it shows for a fixed couple of seconds and fades. Re-sending it every tick keeps it up permanently, which is the standard way to run a custom HUD.
Cancellazione
/title @a clear removes what is showing; /title @a reset also restores default timings. For bossbars, /bossbar set my:timer visible false hides without destroying state.
Crea comandi bossbar, title e il resto dei comandi di controllo e debug da un modulo in Generatore avanzato di comandi — Controllo e debug.