Push more utilities and UUID stuff
This commit is contained in:
parent
dd6ee1bf60
commit
9b7b84153f
7 changed files with 325 additions and 0 deletions
|
@ -1,11 +1,13 @@
|
|||
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/IntArrayTag.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';
|
||||
import '../utils/uuid/UUID.dart';
|
||||
|
||||
class NbtUtils {
|
||||
static void writeBoolean(CompoundTag tag, String name, bool b) {
|
||||
|
@ -89,4 +91,29 @@ class NbtUtils {
|
|||
return Vector3i.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
static List<int> _msbLsbToIntArray(int msb, int lsb) {
|
||||
return [msb >> 32, msb, lsb >> 32, lsb];
|
||||
}
|
||||
|
||||
static List<int> _uuidToIntArray(UUID ID) {
|
||||
return _msbLsbToIntArray(
|
||||
ID.getMostSignificantBits(), ID.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
static UUID _uuidFromIntArray(List<int> values) {
|
||||
return UUID((values[0] << 32 | values[1] & 4294967295),
|
||||
(values[2] << 32 | values[3] & 4294967295));
|
||||
}
|
||||
|
||||
static void writeUUID(CompoundTag tag, String name, UUID ID) {
|
||||
tag.put(name, IntArrayTag.valueOf(_uuidToIntArray(ID)));
|
||||
}
|
||||
|
||||
static UUID readUUID(CompoundTag tag, String name) {
|
||||
if (!tag.contains(name))
|
||||
return UUID.ZERO;
|
||||
else
|
||||
return _uuidFromIntArray(tag.get(name)!.asIntArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,4 +283,74 @@ class ByteLayer {
|
|||
int value = readLong();
|
||||
return (value >> 1) ^ (-(value & 1));
|
||||
}
|
||||
|
||||
void writeBytes(Iterable<int> bytes) {
|
||||
for (int byte in bytes) {
|
||||
writeByte(byte);
|
||||
}
|
||||
}
|
||||
|
||||
List<int> readBytes(int num) {
|
||||
List<int> lst = [];
|
||||
for (int i = 0; i < num; i++) {
|
||||
lst.add(readByte());
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
void setBit(int position, int maskToSet) {
|
||||
if (position < _byteBuffer.length) {
|
||||
// Set the value now
|
||||
seek(position);
|
||||
int current = readByte();
|
||||
seek(position);
|
||||
current |= maskToSet;
|
||||
writeByte(current);
|
||||
}
|
||||
}
|
||||
|
||||
void clearBit(int position, int maskToClear) {
|
||||
if (position < _byteBuffer.length) {
|
||||
// Lets clear the bit
|
||||
seek(position);
|
||||
int current = readByte();
|
||||
current &= maskToClear;
|
||||
seek(position);
|
||||
writeByte(current);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkBit(int position, int mask) {
|
||||
if (position < _byteBuffer.length) {
|
||||
seek(position);
|
||||
int current = readByte();
|
||||
return (current & mask) == mask;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
int getBit(int position) {
|
||||
if (position < _byteBuffer.length) {
|
||||
seek(position);
|
||||
return readByte();
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void seek(int position) {
|
||||
_position = 0;
|
||||
_ensureCapacity(position);
|
||||
_position = position;
|
||||
}
|
||||
|
||||
void waitSetBit(int position, int maskToClear, int maskToSet) {
|
||||
clearBit(position, maskToClear);
|
||||
setBit(position, maskToSet);
|
||||
|
||||
while (!checkBit(position, maskToSet)) {
|
||||
clearBit(position, maskToClear);
|
||||
setBit(position, maskToSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ class IntArrayTag extends Tag {
|
|||
this.value.addAll(value);
|
||||
}
|
||||
|
||||
static IntArrayTag valueOf(List<int> value) {
|
||||
return IntArrayTag._(value);
|
||||
}
|
||||
|
||||
@override
|
||||
void readValue(ByteLayer data) {
|
||||
int count = data.readInt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue