Finish basic server and client impl

This commit is contained in:
zontreck 2024-05-22 15:53:29 -07:00
parent a082210fa9
commit 178cc201c1
4 changed files with 213 additions and 57 deletions

View file

@ -15,7 +15,7 @@ class NbtUtils {
}
static bool readBoolean(CompoundTag tag, String name) {
if (tag.contains(name)) {
if (tag.containsKey(name)) {
return tag.get(name)!.asByte() == 1 ? true : false;
} else {
return false;
@ -30,7 +30,7 @@ class NbtUtils {
}
static Vector2d readVector2d(CompoundTag tag, String name) {
if (tag.contains(name)) {
if (tag.containsKey(name)) {
ListTag lst = tag.get(name)! as ListTag;
return Vector2d(X: lst.get(0).asDouble(), Z: lst.get(1).asDouble());
} else {
@ -46,7 +46,7 @@ class NbtUtils {
}
static Vector2i readVector2i(CompoundTag tag, String name) {
if (tag.contains(name)) {
if (tag.containsKey(name)) {
ListTag lst = tag.get(name)! as ListTag;
return Vector2i(X: lst.get(0).asInt(), Z: lst.get(1).asInt());
} else {
@ -63,7 +63,7 @@ class NbtUtils {
}
static Vector3d readVector3d(CompoundTag tag, String name) {
if (tag.contains(name)) {
if (tag.containsKey(name)) {
ListTag lst = tag.get(name)! as ListTag;
return Vector3d(
X: lst.get(0).asDouble(),
@ -83,7 +83,7 @@ class NbtUtils {
}
static Vector3i readVector3i(CompoundTag tag, String name) {
if (tag.contains(name)) {
if (tag.containsKey(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());
@ -111,7 +111,7 @@ class NbtUtils {
}
static NbtUUID readUUID(CompoundTag tag, String name) {
if (!tag.contains(name)) {
if (!tag.containsKey(name)) {
return NbtUUID.ZERO;
} else {
return _uuidFromIntArray(tag.get(name)!.asIntArray());

View file

@ -1,7 +1,7 @@
import 'package:libac_flutter/nbt/Stream.dart';
import 'package:libac_flutter/nbt/Tag.dart';
class CompoundTag extends Tag {
class CompoundTag extends Tag implements Map<String, Tag> {
late final Map<String, Tag> value = {};
CompoundTag();
@ -48,12 +48,8 @@ class CompoundTag extends Tag {
tag.setKey(name);
}
bool contains(String name) {
return value.containsKey(name);
}
Tag? get(String name) {
if (contains(name)) {
if (containsKey(name)) {
return value[name] as Tag;
} else {
// Does not exist!
@ -61,10 +57,6 @@ class CompoundTag extends Tag {
}
}
void remove(String name) {
value.remove(name);
}
@override
TagType getTagType() {
return TagType.Compound;
@ -103,4 +95,99 @@ class CompoundTag extends Tag {
}
builder.append("\n${"".padLeft(indent - 1, '\t')}}");
}
@override
Tag? operator [](Object? key) {
return value[key];
}
@override
void operator []=(String key, Tag value) {
this.value[key] = value;
}
@override
void addAll(Map<String, Tag> other) {
value.addAll(other);
}
@override
void addEntries(Iterable<MapEntry<String, Tag>> newEntries) {
value.addEntries(newEntries);
}
@override
Map<RK, RV> cast<RK, RV>() {
return value.cast();
}
@override
void clear() {
value.clear();
}
@override
bool containsKey(Object? key) {
return value.containsKey(key);
}
@override
bool containsValue(Object? value) {
return this.value.containsValue(value);
}
@override
Iterable<MapEntry<String, Tag>> get entries => value.entries;
@override
void forEach(void Function(String key, Tag value) action) {
value.forEach(action);
}
@override
bool get isEmpty => value.isEmpty;
@override
bool get isNotEmpty => value.isNotEmpty;
@override
Iterable<String> get keys => value.keys;
@override
int get length => value.length;
@override
Map<K2, V2> map<K2, V2>(
MapEntry<K2, V2> Function(String key, Tag value) convert) {
return value.map(convert);
}
@override
Tag putIfAbsent(String key, Tag Function() ifAbsent) {
return this.value.putIfAbsent(key, ifAbsent);
}
@override
Tag? remove(Object? key) {
return value.remove(key);
}
@override
void removeWhere(bool Function(String key, Tag value) test) {
value.removeWhere(test);
}
@override
Tag update(String key, Tag Function(Tag value) update,
{Tag Function()? ifAbsent}) {
return value.update(key, update);
}
@override
void updateAll(Tag Function(String key, Tag value) update) {
value.updateAll(update);
}
@override
Iterable<Tag> get values => value.values;
}