92 lines
2.7 KiB
Dart
92 lines
2.7 KiB
Dart
import 'package:libac_flutter/nbt/impl/ByteTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/DoubleTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/IntTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/ListTag.dart';
|
|
import 'package:libac_flutter/utils/Vector3.dart';
|
|
|
|
import '../utils/Vector2.dart';
|
|
|
|
class NbtUtils {
|
|
static void writeBoolean(CompoundTag tag, String name, bool b) {
|
|
tag.put(name, ByteTag.valueOf(b ? 1 : 0));
|
|
}
|
|
|
|
static bool readBoolean(CompoundTag tag, String name) {
|
|
if (tag.contains(name)) {
|
|
return tag.get(name)!.asByte() == 1 ? true : false;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static void writeVector2d(CompoundTag tag, String name, Vector2d pos) {
|
|
ListTag posTag = ListTag();
|
|
posTag.add(DoubleTag.valueOf(pos.X));
|
|
posTag.add(DoubleTag.valueOf(pos.Z));
|
|
tag.put(name, posTag);
|
|
}
|
|
|
|
static Vector2d readVector2d(CompoundTag tag, String name) {
|
|
if (tag.contains(name)) {
|
|
ListTag lst = tag.get(name)! as ListTag;
|
|
return Vector2d(X: lst.get(0).asDouble(), Z: lst.get(1).asDouble());
|
|
} else {
|
|
return Vector2d.ZERO;
|
|
}
|
|
}
|
|
|
|
static void writeVector2i(CompoundTag tag, String name, Vector2i pos) {
|
|
ListTag posTag = ListTag();
|
|
posTag.add(IntTag.valueOf(pos.X));
|
|
posTag.add(IntTag.valueOf(pos.Z));
|
|
tag.put(name, posTag);
|
|
}
|
|
|
|
static Vector2i readVector2i(CompoundTag tag, String name) {
|
|
if (tag.contains(name)) {
|
|
ListTag lst = tag.get(name)! as ListTag;
|
|
return Vector2i(X: lst.get(0).asInt(), Z: lst.get(1).asInt());
|
|
} else {
|
|
return Vector2i.ZERO;
|
|
}
|
|
}
|
|
|
|
static void writeVector3d(CompoundTag tag, String name, Vector3d pos) {
|
|
ListTag posTag = ListTag();
|
|
posTag.add(DoubleTag.valueOf(pos.X));
|
|
posTag.add(DoubleTag.valueOf(pos.Y));
|
|
posTag.add(DoubleTag.valueOf(pos.Z));
|
|
tag.put(name, posTag);
|
|
}
|
|
|
|
static Vector3d readVector3d(CompoundTag tag, String name) {
|
|
if (tag.contains(name)) {
|
|
ListTag lst = tag.get(name)! as ListTag;
|
|
return Vector3d(
|
|
X: lst.get(0).asDouble(),
|
|
Y: lst.get(1).asDouble(),
|
|
Z: lst.get(2).asDouble());
|
|
} else {
|
|
return Vector3d.ZERO;
|
|
}
|
|
}
|
|
|
|
static void writeVector3i(CompoundTag tag, String name, Vector3i pos) {
|
|
ListTag posTag = ListTag();
|
|
posTag.add(IntTag.valueOf(pos.X));
|
|
posTag.add(IntTag.valueOf(pos.Y));
|
|
posTag.add(IntTag.valueOf(pos.Z));
|
|
tag.put(name, posTag);
|
|
}
|
|
|
|
static Vector3i readVector3i(CompoundTag tag, String name) {
|
|
if (tag.contains(name)) {
|
|
ListTag lst = tag.get(name)! as ListTag;
|
|
return Vector3i(
|
|
X: lst.get(0).asInt(), Y: lst.get(1).asInt(), Z: lst.get(2).asInt());
|
|
} else {
|
|
return Vector3i.ZERO;
|
|
}
|
|
}
|
|
}
|