My goal is to make a pig have its name and its lvl displayed on the same text

but to do this I need to combine "name" and "its lvl" is there any way that I can take both variables and put them in one string

Additional Info I am right now taking the pigs name from a sign and its lvl from a different one I can put one name on the pig but not both

on a multiplayer server, 1.16 is my version, i am in java

my end goal is I'm also trying to make a hypixel skyblock health system if you are wondering

  • Can you put the lvl as a variable with the name of the mob
    – Hunter
    Mar 23, 2021 at 17:51

2 Answers 2


You can simply do this by using this command:

summon pig [x] [y] [z] {CustomName:"\"<name and level>\""}

This command will spawn a pig with the name and level you choose, although this will not change the pig itself, only its name, the pig will remain the same as it would be if you spawned it with a spawn egg. If you want to change the pigs health and other attributes you can do this with this command:

summon pig [x] [y] [z] {CustomName:"\"<name and level>\"",ActiveEffects:[{Id:21,Amplifier:<health amount>,Duration:999999}]}

This command simply adds an effect to the pig that boosts its health for an infinite amount of time where, {health amount} is the number put you can input to change the health, the number has to be between 1 and 255, you can also change the id to another effect or add one using this template, you just have to know the effect id, which you can easily find on the internet, or more simply use a command generator.

If you want to change the color of the pig's name and level just put this in the name slot:

[{"text":"<name/level>","color":"<color, red, blue, etc>"}]

If you want to change the name for both the name and level use this:



summon pig [x] [y] [z] {CustomName:"\"[{"text":"{Lvl:3}","color":"grey"},{"text":"Pig","color":"Red"}]\"",ActiveEffects [{Id:21,Amplifier:{health amount},Duration:999999}]}

Finally since you are on a server, you can add plugins that can do this for you, the plugins will have much more configurations for the mob, (such as showing the mobs current health).

Notice: I haven't yet tested if the color works, but if it doesn't you can just use the first and/or second command.

Hope this helps! If you have any questions feel free to ask me!

(Also this is my first time doing this)


If you want to have a changeable level, you'll want to use a scoreboard to store the level of the pig.

You can use the following command like this:

scoreboard players add pigLvl dummy

to create the required objective.

Then if you want to change it, you can do this:

scoreboard players set @e[type=pig,limit=1] pigLvl 2

replacing 2 with whatever level.

The trouble is to actually update the level on the pig's custom name whenever it is updated. The problem is that the name has to be manually updated every tick. You can't set it to a score and have it dynamically update.

You would use the JSON text component score for this but unfortunately this cannot resolve the score to an actual text value. Therefore you must copy the new JSON text to a sign to have it resolved before putting it on the pig. The standard location for this sign is (−30000000, 0, 1603).

The following commands, to be run by the pig to update name, will work for one pig at a time. If you want to have each pig update its name at once, you must use a function.

tag @s add updatingName
data modify block -30000000 0 1603 Text1 set value '{"score":{"name":"@e[tag=updatingName,limit=1]","objective":"pigLvl"}}'
data modify entity @s CustomName set from block -30000000 0 1603 Text1
tag @s remove updatingName

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .