mirror of
https://github.com/ViaVersion/ViaNBT.git
synced 2024-06-26 10:24:44 +02:00
3.5.0: Add NumberArrayTag
This commit is contained in:
parent
324eb6af2c
commit
0439d7af76
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>nbt</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>3.5.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ViaNBT</name>
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Arrays;
|
|||
/**
|
||||
* A tag containing a byte array.
|
||||
*/
|
||||
public class ByteArrayTag extends Tag {
|
||||
public class ByteArrayTag extends NumberArrayTag {
|
||||
public static final int ID = 7;
|
||||
private static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
private byte[] value;
|
||||
|
@ -73,15 +73,20 @@ public class ByteArrayTag extends Tag {
|
|||
this.value[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of this tag's array.
|
||||
*
|
||||
* @return This tag's array length.
|
||||
*/
|
||||
@Override
|
||||
public int length() {
|
||||
return this.value.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListTag toListTag() {
|
||||
final ListTag list = new ListTag(ByteTag.class);
|
||||
for (final byte b : this.value) {
|
||||
list.add(new ByteTag(b));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
|
||||
tagLimiter.countInt();
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Arrays;
|
|||
/**
|
||||
* A tag containing an integer array.
|
||||
*/
|
||||
public class IntArrayTag extends Tag {
|
||||
public class IntArrayTag extends NumberArrayTag {
|
||||
public static final int ID = 11;
|
||||
private static final int[] EMPTY_ARRAY = new int[0];
|
||||
private int[] value;
|
||||
|
@ -26,7 +26,7 @@ public class IntArrayTag extends Tag {
|
|||
*
|
||||
* @param value The value of the tag.
|
||||
*/
|
||||
public IntArrayTag(int[] value) {
|
||||
public IntArrayTag(final int[] value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value cannot be null");
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class IntArrayTag extends Tag {
|
|||
*
|
||||
* @param value New value of this tag.
|
||||
*/
|
||||
public void setValue(int[] value) {
|
||||
public void setValue(final int[] value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value cannot be null");
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class IntArrayTag extends Tag {
|
|||
* @param index Index of the value.
|
||||
* @return The value at the given index.
|
||||
*/
|
||||
public int getValue(int index) {
|
||||
public int getValue(final int index) {
|
||||
return this.value[index];
|
||||
}
|
||||
|
||||
|
@ -71,21 +71,26 @@ public class IntArrayTag extends Tag {
|
|||
* @param index Index of the value.
|
||||
* @param value Value to set.
|
||||
*/
|
||||
public void setValue(int index, int value) {
|
||||
public void setValue(final int index, final int value) {
|
||||
this.value[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of this tag's array.
|
||||
*
|
||||
* @return This tag's array length.
|
||||
*/
|
||||
@Override
|
||||
public int length() {
|
||||
return this.value.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
|
||||
public ListTag toListTag() {
|
||||
final ListTag list = new ListTag();
|
||||
for (final int i : this.value) {
|
||||
list.add(new IntTag(i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final DataInput in, final TagLimiter tagLimiter, final int nestingLevel) throws IOException {
|
||||
tagLimiter.countInt();
|
||||
this.value = new int[in.readInt()];
|
||||
tagLimiter.countBytes(4 * this.value.length);
|
||||
|
@ -95,9 +100,9 @@ public class IntArrayTag extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput out) throws IOException {
|
||||
public void write(final DataOutput out) throws IOException {
|
||||
out.writeInt(this.value.length);
|
||||
for (int i : this.value) {
|
||||
for (final int i : this.value) {
|
||||
out.writeInt(i);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +111,7 @@ public class IntArrayTag extends Tag {
|
|||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
IntArrayTag that = (IntArrayTag) o;
|
||||
final IntArrayTag that = (IntArrayTag) o;
|
||||
return Arrays.equals(this.value, that.value);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Arrays;
|
|||
/**
|
||||
* A tag containing a long array.
|
||||
*/
|
||||
public class LongArrayTag extends Tag {
|
||||
public class LongArrayTag extends NumberArrayTag {
|
||||
public static final int ID = 12;
|
||||
private static final long[] EMPTY_ARRAY = new long[0];
|
||||
private long[] value;
|
||||
|
@ -75,15 +75,20 @@ public class LongArrayTag extends Tag {
|
|||
this.value[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of this tag's array.
|
||||
*
|
||||
* @return This tag's array length.
|
||||
*/
|
||||
@Override
|
||||
public int length() {
|
||||
return this.value.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListTag toListTag() {
|
||||
final ListTag list = new ListTag(LongTag.class);
|
||||
for (final long l : this.value) {
|
||||
list.add(new LongTag(l));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
|
||||
tagLimiter.countInt();
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.github.steveice10.opennbt.tag.builtin;
|
||||
|
||||
public abstract class NumberArrayTag extends Tag {
|
||||
|
||||
/**
|
||||
* Gets the length of this tag's array.
|
||||
*
|
||||
* @return array length
|
||||
*/
|
||||
public abstract int length();
|
||||
|
||||
/**
|
||||
* Creates a new list tag from this tag.
|
||||
*
|
||||
* @return a new list tag
|
||||
*/
|
||||
public abstract ListTag toListTag();
|
||||
}
|
Loading…
Reference in New Issue
Block a user