ByteTag .java

net.minecraft.nbt.ByteTag (record): members: value, ONE, Cache, doubleValue, floatValue, shortValue, byteValue, longValue, intValue, valueOf, box, ZERO.

net.minecraft.nbtrecord140 linescommon2.7 KB

Implements

API Surface (22)

ByteTag load(final DataInput input, final NbtAccounter accounter)
StreamTagVisitor.ValueResult parse(final DataInput input, final StreamTagVisitor output, final NbtAccounter accounter)
int size()
String getName()
String getPrettyName()
ByteTag valueOf(final byte data)
ByteTag valueOf(final boolean data)
void write(final DataOutput output)
int sizeInBytes()
byte getId()
TagType<ByteTag> getType()
ByteTag copy()
void accept(final TagVisitor visitor)
long longValue()
int intValue()
short shortValue()
byte byteValue()
double doubleValue()
float floatValue()
Number box()
StreamTagVisitor.ValueResult accept(final StreamTagVisitor visitor)
String toString()

Fields & Constants (4)

SELF_SIZE_IN_BYTES
TYPE
ZERO
ONE

String literals (2)

"BYTE"
"TAG_Byte"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ByteTag.java140 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.nbt;
2
3
import java.io.DataInput;
4
import java.io.DataOutput;
5
import java.io.IOException;
6
7
public record ByteTag(byte value) implements NumericTag {
8
	private static final int SELF_SIZE_IN_BYTES = 9;
9
	public static final TagType<ByteTag> TYPE = new TagType.StaticSize<ByteTag>() {
10
		public ByteTag load(final DataInput input, final NbtAccounter accounter) throws IOException {
11
			return ByteTag.valueOf(readAccounted(input, accounter));
12
		}
13
14
		@Override
15
		public StreamTagVisitor.ValueResult parse(final DataInput input, final StreamTagVisitor output, final NbtAccounter accounter) throws IOException {
16
			return output.visit(readAccounted(input, accounter));
17
		}
18
19
		private static byte readAccounted(final DataInput input, final NbtAccounter accounter) throws IOException {
20
			accounter.accountBytes(9L);
21
			return input.readByte();
22
		}
23
24
		@Override
25
		public int size() {
26
			return 1;
27
		}
28
29
		@Override
30
		public String getName() {
31
			return "BYTE";
32
		}
33
34
		@Override
35
		public String getPrettyName() {
36
			return "TAG_Byte";
37
		}
38
	};
39
	public static final ByteTag ZERO = valueOf((byte)0);
40
	public static final ByteTag ONE = valueOf((byte)1);
41
42
	@Deprecated(forRemoval = true)
43
	public ByteTag {
44
	}
45
46
	public static ByteTag valueOf(final byte data) {
47
		return ByteTag.Cache.cache[128 + data];
48
	}
49
50
	public static ByteTag valueOf(final boolean data) {
51
		return data ? ONE : ZERO;
52
	}
53
54
	@Override
55
	public void write(final DataOutput output) throws IOException {
56
		output.writeByte(this.value);
57
	}
58
59
	@Override
60
	public int sizeInBytes() {
61
		return 9;
62
	}
63
64
	@Override
65
	public byte getId() {
66
		return 1;
67
	}
68
69
	@Override
70
	public TagType<ByteTag> getType() {
71
		return TYPE;
72
	}
73
74
	public ByteTag copy() {
75
		return this;
76
	}
77
78
	@Override
79
	public void accept(final TagVisitor visitor) {
80
		visitor.visitByte(this);
81
	}
82
83
	@Override
84
	public long longValue() {
85
		return this.value;
86
	}
87
88
	@Override
89
	public int intValue() {
90
		return this.value;
91
	}
92
93
	@Override
94
	public short shortValue() {
95
		return this.value;
96
	}
97
98
	@Override
99
	public byte byteValue() {
100
		return this.value;
101
	}
102
103
	@Override
104
	public double doubleValue() {
105
		return this.value;
106
	}
107
108
	@Override
109
	public float floatValue() {
110
		return this.value;
111
	}
112
113
	@Override
114
	public Number box() {
115
		return this.value;
116
	}
117
118
	@Override
119
	public StreamTagVisitor.ValueResult accept(final StreamTagVisitor visitor) {
120
		return visitor.visit(this.value);
121
	}
122
123
	@Override
124
	public String toString() {
125
		StringTagVisitor visitor = new StringTagVisitor();
126
		visitor.visitByte(this);
127
		return visitor.build();
128
	}
129
130
	private static class Cache {
131
		private static final ByteTag[] cache = new ByteTag[256];
132
133
		static {
134
			for (int i = 0; i < cache.length; i++) {
135
				cache[i] = new ByteTag((byte)(i - 128));
136
			}
137
		}
138
	}
139
}
140

Decompiled Minecraft 26.3 source of ByteTag (net/minecraft/nbt/ByteTag.java) with Mojang official mappings, stored verbatim on the site.