2

/title display rainbow text?

Garfieldwxg55's Avatar Garfieldwxg5510/5/20 11:40 pm
2 emeralds 2.4k 15
4/9/2022 2:24 pm
CentEMO's Avatar CentEMO
Hi, I have been working on editing a datapack which adds extra music discs to Minecraft. Recently I added the ability for the game to show the name of the song when placed in the Jukebox. Currently I have the text set to Light Purple, as that is what it displays as in Bedrock Edition. But ideally I would like it to show as rainbow coloured, as the normal vanilla music discs do. Currently I am using this command to display the text:
title @p actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"light_purple"}
Is there any way I can change this to allow the multicolour text which the vanilla disc use?
Any feedback is appreciated!
Posted by Garfieldwxg55's Avatar
Garfieldwxg55
Level 2 : Apprentice Miner
1

Create an account or sign in to comment.

15

CentEMO
04/09/2022 2:24 pm
Level 3 : Apprentice Miner
CentEMO's Avatar
Bababoi mano '-'
1
garlicbreathinator
10/06/2020 1:08 am
Level 31 : Artisan Engineer
history
garlicbreathinator's Avatar
The color fading of the jukebox is hardcoded and not something you could easily replicate, let alone smoothly replicate at all until 1,16,

1.16 added the ability to use hexadecimal color codes in the "color" field in the format #RRGGBB like "#0000FF" for pure blue or "#FFFFFF" for pure white. You just put a color code like that in instead of a preset color like "light purple" and you can use any color you want.

Now, to get a smooth color fade, you need to make the sequence of colors that you want and use a scoreboard to determine what to do. For example, this code should do about what you need. You can use more or less colors for a faster or slower cycle or reduce the number of commands by syncing the colors for all users and splitting the code into multiple functions so not all of it needs to be read through each tick.

#note: requires scoreboard objectives jukebox_color and jukebox_timer and only works in 1.16+
#jukebox_color is an internal variable and jukebox_timer gets set to a number to enable the message for that many ticks.
#for example, to see the message for 5 seconds, set your jukebox_timer score to 100. It automatically counts down to 0
scoreboard players add @a jukebox_color 1
scoreboard players set @a[​scores={jukebox_color=12}] jukebox_color 0
scoreboard players remove @a[​scores={jukebox_timer=1..}] jukebox_timer 1
title @a[​scores={jukebox_color=0,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#FF0000"}
title @a[​scores={jukebox_color=1,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#FF8000"}
title @a[​scores={jukebox_color=2,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#FFFF00"}
title @a[​scores={jukebox_color=3,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#80FF00"}
title @a[​scores={jukebox_color=4,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#00FF00"}
title @a[​scores={jukebox_color=5,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#00FF80"}
title @a[​scores={jukebox_color=6,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#00FFFF"}
title @a[​scores={jukebox_color=7,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#0080FF"}
title @a[​scores={jukebox_color=8,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#0000FF"}
title @a[​scores={jukebox_color=9,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#8000FF"}
title @a[​scores={jukebox_color=10,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#FF00FF"}
title @a[​scores={jukebox_color=11,jukebox_timer=1..}] actionbar {"text":"Now Playing: John Williams - Duel of the Fates","color":"#FF0080"}


Go ahead and create a scoreboard objective and copy that into a function that gets called every tick. Make sure you create the scoreboard objectives.


With a little bit of recording and frame-by-frame analysis, you could determine what colors the original uses and match it the best you can. Only limit is you have a 20 FPS limit instead of the full framerate (60+) of the computer.
4
Garfieldwxg55
10/06/2020 9:38 pm
Level 2 : Apprentice Miner
Garfieldwxg55's Avatar
Thank you! I'm very new to datapack programming, most of what I know comes from reverse engineering various data packs. Is there any chance you could show me an example datapack so I can reverse engineer the code, and then refine it to hopefully create something almost identical to vanilla?
(The datapack/resource pack I've used)
https://www.dropbox.com/s/uvgqurle67ypu7h/custommusicdiscdatapack%3Aresourcepack.zip?dl=0
1
garlicbreathinator
10/06/2020 10:50 pm
Level 31 : Artisan Engineer
garlicbreathinator's Avatar
Please DM me your discord tag or something, I can show you how to add the custom colors to your existing pack and how to optimize them. I was also thinking of changing a few things (make the sound come from the jukebox instead of the player, use an advancement to detect placing disc instead of a function every tick, etc) and briefly considering a major overhaul that would be completely unnecessary.
2
TriggeredTaco
10/06/2020 4:41 pm
Level 28 : Expert Taco
TriggeredTaco's Avatar
s o
l o n g
2
garlicbreathinator
10/06/2020 5:44 pm
Level 31 : Artisan Engineer
history
garlicbreathinator's Avatar
Well, you need to have a command for each different color it cycles between, so to get a smooth cycle across the whole color spectrum you need 12 or so commands like this. The top 3 commands change which one of the colors listed gets used each frame.
2
TriggeredTaco
10/06/2020 6:20 pm
Level 28 : Expert Taco
TriggeredTaco's Avatar
o h
2
One_Nose
10/06/2020 1:32 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Also add the objective declaration to #minecraft:load:
scoreboard objectives add jukebox_color dummy
2
garlicbreathinator
10/06/2020 1:39 am
Level 31 : Artisan Engineer
garlicbreathinator's Avatar
No, you can put them in an existing function tagged in #minecraft:load or a new function that you add to #minecraft:load or just run them manually. Putting them directly in the tag will not work since it only accepts functions. Additionally, it will result in the tag itself failing to load.



Also, there is a second objective you must create, jukebox_timer, that controls how long the message stays on screen (also need to set up the actionbar timer to only hold it up a tick or so as well) since the colors will loop by default instead of just doing one cycle and disappearing.
2
One_Nose
10/06/2020 2:21 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Of course not in the tag file. That's how we talk, because it's obvious that commands are put in tagged functions and not in the tag itself. And no, DON'T run it manually if you want your data pack to work on worlds other than your testing world.
2
garlicbreathinator
10/06/2020 4:33 pm
Level 31 : Artisan Engineer
garlicbreathinator's Avatar
The point is that this IS a test and not to be used as the final version. The proper version would be spread over a couple functions to avoid unnecessary command calls, use more colors (this one cycles in about half a second), and will likely use different variables.
2
One_Nose
10/07/2020 10:05 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Of course this is just an example, but even examples should be good examples.
2
One_Nose
10/06/2020 12:45 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Sounds kinda stupid, but this is the best way:
title @p actionbar [{"text":"N","color":"red"}, {"text":"o","color":"blue"}, {"text":"w","color":"green"}]And so on. That's the only way.
2
garlicbreathinator
10/06/2020 1:11 am
Level 31 : Artisan Engineer
garlicbreathinator's Avatar
This is not what Garfieldwxg55 is looking for. The goal is to make the entire message fade between different colors like the vanilla jukebox does, not to make the letters themselves different colors. Besides, in 1.16 you can use any color, not just the predefined 16.
3
One_Nose
10/06/2020 1:29 am
He/Him • Level 58 : Grandmaster Dragonborn Hero
One_Nose's Avatar
Oh yeah I'm stupid. And ik about 1.16 colors, it was just an example.
2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome