Add a boolean data type

This commit is contained in:
Zontreck 2023-10-13 20:57:39 -07:00
parent d655d87275
commit c07ab8c032
3 changed files with 55 additions and 2 deletions

View 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;
}
}

View file

@ -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();
}
}

View file

@ -13,7 +13,8 @@ public enum Type {
List(9),
Key(10),
IntArray(11),
LongArray(12);
LongArray(12),
Boolean(13);
byte value;