StyledFormat .java

net.minecraft.network.chat.numbers.StyledFormat (record, 42 lines): members: style, PLAYER_LIST_DEFAULT, SIDEBAR_DEFAULT, NO_STYLE, format, TYPE, type.

net.minecraft.network.chat.numbersrecord42 linescommon1.5 KB

Implements

API Surface (4)

MapCodec<StyledFormat> mapCodec()
StreamCodec<RegistryFriendlyByteBuf, StyledFormat> streamCodec()
MutableComponent format(final int value)
NumberFormatType<StyledFormat> type()

Fields & Constants (4)

TYPE
NO_STYLE
SIDEBAR_DEFAULT
PLAYER_LIST_DEFAULT

Full Source

StyledFormat.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.network.chat.numbers;
2
3
import com.mojang.serialization.MapCodec;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.network.RegistryFriendlyByteBuf;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.network.chat.MutableComponent;
8
import net.minecraft.network.chat.Style;
9
import net.minecraft.network.codec.StreamCodec;
10
11
public record StyledFormat(Style style) implements NumberFormat {
12
	public static final NumberFormatType<StyledFormat> TYPE = new NumberFormatType<StyledFormat>() {
13
		private static final MapCodec<StyledFormat> CODEC = Style.Serializer.MAP_CODEC.xmap(StyledFormat::new, StyledFormat::style);
14
		private static final StreamCodec<RegistryFriendlyByteBuf, StyledFormat> STREAM_CODEC = StreamCodec.composite(
15
			Style.Serializer.TRUSTED_STREAM_CODEC, StyledFormat::style, StyledFormat::new
16
		);
17
18
		@Override
19
		public MapCodec<StyledFormat> mapCodec() {
20
			return CODEC;
21
		}
22
23
		@Override
24
		public StreamCodec<RegistryFriendlyByteBuf, StyledFormat> streamCodec() {
25
			return STREAM_CODEC;
26
		}
27
	};
28
	public static final StyledFormat NO_STYLE = new StyledFormat(Style.EMPTY);
29
	public static final StyledFormat SIDEBAR_DEFAULT = new StyledFormat(Style.EMPTY.withColor(ChatFormatting.RED));
30
	public static final StyledFormat PLAYER_LIST_DEFAULT = new StyledFormat(Style.EMPTY.withColor(ChatFormatting.YELLOW));
31
32
	@Override
33
	public MutableComponent format(final int value) {
34
		return Component.literal(Integer.toString(value)).withStyle(this.style);
35
	}
36
37
	@Override
38
	public NumberFormatType<StyledFormat> type() {
39
		return TYPE;
40
	}
41
}
42

Decompiled Minecraft 26.3 source of StyledFormat (net/minecraft/network/chat/numbers/StyledFormat.java) with Mojang official mappings, stored verbatim on the site.