Add a boolean data type
This commit is contained in:
parent
d655d87275
commit
c07ab8c032
3 changed files with 55 additions and 2 deletions
45
src/main/java/dev/zontreck/registry/v3/BooleanTag.java
Normal file
45
src/main/java/dev/zontreck/registry/v3/BooleanTag.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package dev.zontreck.registry.v3;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanTag extends Tag {
|
||||
public boolean value;
|
||||
|
||||
public BooleanTag() {
|
||||
value = false;
|
||||
}
|
||||
|
||||
public BooleanTag(boolean val) {
|
||||
value = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.Boolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCanonicalName() {
|
||||
return "TAG_Boolean";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void WriteValue(DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ReadValue(DataInputStream dis) throws IOException {
|
||||
value = dis.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String PrettyPrint(int indent, String name) {
|
||||
String builder = super.PrettyPrint(indent, name);
|
||||
builder += ": " + (value ? "true" : "false");
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ public abstract class Tag {
|
|||
public String PrettyPrint(int indent, String name) {
|
||||
String builder = "";
|
||||
builder += MakeIndent(indent) + getCanonicalName();
|
||||
if(name != "")
|
||||
if (name != "")
|
||||
builder += " [" + name + "]";
|
||||
|
||||
return builder;
|
||||
|
@ -129,4 +129,11 @@ public abstract class Tag {
|
|||
return new IntArrayTag();
|
||||
}
|
||||
|
||||
public BooleanTag asBoolean() {
|
||||
if (this instanceof BooleanTag bt)
|
||||
return bt;
|
||||
else
|
||||
return new BooleanTag();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ public enum Type {
|
|||
List(9),
|
||||
Key(10),
|
||||
IntArray(11),
|
||||
LongArray(12);
|
||||
LongArray(12),
|
||||
Boolean(13);
|
||||
|
||||
byte value;
|
||||
|
||||
|
|
Loading…
Reference in a new issue