ByteArrayTag.java
net.minecraft.nbt.ByteArrayTag
信息
- 全限定名:net.minecraft.nbt.ByteArrayTag
- 类型:public final class
- 包:net.minecraft.nbt
- 源码路径:src/main/java/net/minecraft/nbt/ByteArrayTag.java
- 起始行号:L10
- 实现:CollectionTag
- 职责:
TODO
字段/常量
-
SELF_SIZE_IN_BYTES- 类型:
int - 修饰符:
private static final - 源码定位:
L11 - 说明:
TODO
- 类型:
-
TYPE- 类型:
TagType<ByteArrayTag> - 修饰符:
public static final public public private static public public public - 源码定位:
L12 - 说明:
TODO
- 类型:
-
data- 类型:
byte[] - 修饰符:
private - 源码定位:
L46 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ByteArrayTag(byte[] data) @ L48
- 构造器名:ByteArrayTag
- 源码定位:L48
- 修饰符:public
参数:
- data: byte[]
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void write(DataOutput output) @ L52
- 方法名:write
- 源码定位:L52
- 返回类型:void
- 修饰符:public
参数:
- output: DataOutput
说明:
TODO
public int sizeInBytes() @ L58
- 方法名:sizeInBytes
- 源码定位:L58
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public byte getId() @ L63
- 方法名:getId
- 源码定位:L63
- 返回类型:byte
- 修饰符:public
参数:
- 无
说明:
TODO
public TagType<ByteArrayTag> getType() @ L68
- 方法名:getType
- 源码定位:L68
- 返回类型:TagType
- 修饰符:public
参数:
- 无
说明:
TODO
public String toString() @ L73
- 方法名:toString
- 源码定位:L73
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public Tag copy() @ L80
- 方法名:copy
- 源码定位:L80
- 返回类型:Tag
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean equals(Object obj) @ L87
- 方法名:equals
- 源码定位:L87
- 返回类型:boolean
- 修饰符:public
参数:
- obj: Object
说明:
TODO
public int hashCode() @ L92
- 方法名:hashCode
- 源码定位:L92
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void accept(TagVisitor visitor) @ L97
- 方法名:accept
- 源码定位:L97
- 返回类型:void
- 修饰符:public
参数:
- visitor: TagVisitor
说明:
TODO
public byte[] getAsByteArray() @ L102
- 方法名:getAsByteArray
- 源码定位:L102
- 返回类型:byte[]
- 修饰符:public
参数:
- 无
说明:
TODO
public int size() @ L106
- 方法名:size
- 源码定位:L106
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public ByteTag get(int index) @ L111
- 方法名:get
- 源码定位:L111
- 返回类型:ByteTag
- 修饰符:public
参数:
- index: int
说明:
TODO
public boolean setTag(int index, Tag tag) @ L115
- 方法名:setTag
- 源码定位:L115
- 返回类型:boolean
- 修饰符:public
参数:
- index: int
- tag: Tag
说明:
TODO
public boolean addTag(int index, Tag tag) @ L125
- 方法名:addTag
- 源码定位:L125
- 返回类型:boolean
- 修饰符:public
参数:
- index: int
- tag: Tag
说明:
TODO
public ByteTag remove(int index) @ L135
- 方法名:remove
- 源码定位:L135
- 返回类型:ByteTag
- 修饰符:public
参数:
- index: int
说明:
TODO
public void clear() @ L141
- 方法名:clear
- 源码定位:L141
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public Optional<byte[]> asByteArray() @ L146
- 方法名:asByteArray
- 源码定位:L146
- 返回类型:Optional<byte[]>
- 修饰符:public
参数:
- 无
说明:
TODO
public StreamTagVisitor.ValueResult accept(StreamTagVisitor visitor) @ L151
- 方法名:accept
- 源码定位:L151
- 返回类型:StreamTagVisitor.ValueResult
- 修饰符:public
参数:
- visitor: StreamTagVisitor
说明:
TODO
代码
public final class ByteArrayTag implements CollectionTag {
private static final int SELF_SIZE_IN_BYTES = 24;
public static final TagType<ByteArrayTag> TYPE = new TagType.VariableSize<ByteArrayTag>() {
public ByteArrayTag load(DataInput input, NbtAccounter accounter) throws IOException {
return new ByteArrayTag(readAccounted(input, accounter));
}
@Override
public StreamTagVisitor.ValueResult parse(DataInput input, StreamTagVisitor output, NbtAccounter accounter) throws IOException {
return output.visit(readAccounted(input, accounter));
}
private static byte[] readAccounted(DataInput input, NbtAccounter accounter) throws IOException {
accounter.accountBytes(24L);
int length = input.readInt();
accounter.accountBytes(1L, length);
byte[] data = new byte[length];
input.readFully(data);
return data;
}
@Override
public void skip(DataInput input, NbtAccounter accounter) throws IOException {
input.skipBytes(input.readInt() * 1);
}
@Override
public String getName() {
return "BYTE[]";
}
@Override
public String getPrettyName() {
return "TAG_Byte_Array";
}
};
private byte[] data;
public ByteArrayTag(byte[] data) {
this.data = data;
}
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(this.data.length);
output.write(this.data);
}
@Override
public int sizeInBytes() {
return 24 + 1 * this.data.length;
}
@Override
public byte getId() {
return 7;
}
@Override
public TagType<ByteArrayTag> getType() {
return TYPE;
}
@Override
public String toString() {
StringTagVisitor visitor = new StringTagVisitor();
visitor.visitByteArray(this);
return visitor.build();
}
@Override
public Tag copy() {
byte[] cp = new byte[this.data.length];
System.arraycopy(this.data, 0, cp, 0, this.data.length);
return new ByteArrayTag(cp);
}
@Override
public boolean equals(Object obj) {
return this == obj ? true : obj instanceof ByteArrayTag && Arrays.equals(this.data, ((ByteArrayTag)obj).data);
}
@Override
public int hashCode() {
return Arrays.hashCode(this.data);
}
@Override
public void accept(TagVisitor visitor) {
visitor.visitByteArray(this);
}
public byte[] getAsByteArray() {
return this.data;
}
@Override
public int size() {
return this.data.length;
}
public ByteTag get(int index) {
return ByteTag.valueOf(this.data[index]);
}
@Override
public boolean setTag(int index, Tag tag) {
if (tag instanceof NumericTag numeric) {
this.data[index] = numeric.byteValue();
return true;
} else {
return false;
}
}
@Override
public boolean addTag(int index, Tag tag) {
if (tag instanceof NumericTag numeric) {
this.data = ArrayUtils.add(this.data, index, numeric.byteValue());
return true;
} else {
return false;
}
}
public ByteTag remove(int index) {
byte prev = this.data[index];
this.data = ArrayUtils.remove(this.data, index);
return ByteTag.valueOf(prev);
}
@Override
public void clear() {
this.data = new byte[0];
}
@Override
public Optional<byte[]> asByteArray() {
return Optional.of(this.data);
}
@Override
public StreamTagVisitor.ValueResult accept(StreamTagVisitor visitor) {
return visitor.visit(this.data);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
System.arraycopy()
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
ByteTag.valueOf()
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringTagVisitor()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置: