def create_options_file(self) -> None: stream: object = nbt_be_binary_stream() tag: object = compound_tag("", [ compound_tag("Data", [ byte_tag("hardcore", 0), byte_tag("MapFeatures", 0), byte_tag("raining", 0), byte_tag("Difficulty", 0), byte_tag("thundering", 0), int_tag("GameType", 0), int_tag("generatorVersion", 1), int_tag("rainTime", 0), int_tag("SpawnX", 256), int_tag("SpawnY", 70), int_tag("SpawnZ", 256), int_tag("thunderTime", 0), int_tag("version", 19133), long_tag("LastPlayed", int(time.time() * 1000)), long_tag("RandomSeed", random.randint(0, sys.maxsize)), long_tag("SizeOnDisk", 0), long_tag("Time", 0), string_tag("generatorName", "default"), string_tag("LevelName", "world"), compound_tag("GameRules", []) ]) ]) stream.write_root_tag(tag) with open(os.path.join(self.world_dir, "level.dat"), "wb") as file: file.write(gzip.compress(stream.data)) file.close()
def nbt_serialize(self) -> bytes: stream: object = nbt_be_binary_stream() self.recalculate_height_map() sections: list = list_tag("Sections", [], tag_ids.compound_tag) for i, sect in self.sections.items(): sections.value.append( compound_tag("", [ byte_array_tag("Blocks", sect.block_ids), byte_array_tag("Data", sect.data_entries), byte_array_tag("BlockLight", sect.block_light_entries), byte_array_tag("SkyLight", sect.sky_light_entries) ])) root_tag: object = compound_tag("", [ compound_tag("Level", [ int_tag("xPos", self.x), int_tag("zPos", self.z), long_tag("LastUpdate", 0), byte_tag("V", 1), long_tag("InhabitedTime", 0), byte_tag("TerrainPopulated", 1 if self.terrain_populated else 0), byte_tag("LightPopulated", 1 if self.light_populated else 0), sections, byte_array_tag("Biomes", self.biomes), list_tag("Entities", self.entities, tag_ids.compound_tag), list_tag("TileEntities", self.tile_entities, tag_ids.compound_tag), int_array_tag("HeightMap", self.height_map) ]), int_tag("DataVersion", 1343) ]) stream.write_root_tag(root_tag) return stream.data
def create_player_file(self, uuid: str) -> None: stream: object = nbt_be_binary_stream() tag: object = compound_tag("", [ byte_tag("OnGround", 1), byte_tag("Sleeping", 0), short_tag("Air", 300), short_tag("AttackTime", 0), short_tag("DeathTime", 0), short_tag("Fire", 0), short_tag("Health", 20), short_tag("HurtTime", 0), short_tag("SleepTimer", 0), int_tag("Dimension", 0), int_tag("foodLevel", 0), int_tag("foodTickTimer", 0), int_tag("playerGameType", self.get_world_gamemode()), int_tag("XpLevel", 0), int_tag("XpTotal", 0), float_tag("FallDistance", 0), float_tag("foodExhastionLevel", 0), float_tag("foodSaturationLevel", 0), float_tag("XpP", 0), compound_tag("Inventory", []), list_tag("Motion", [double_tag("", 0), double_tag("", 0), double_tag("", 0)], tag_ids.double_tag), list_tag("Pos", [ double_tag("", self.get_spawn_position().x), double_tag("", self.get_spawn_position().y), double_tag("", self.get_spawn_position().z) ], tag_ids.double_tag), list_tag("Rotation", [float_tag("", 0), float_tag("", 0), float_tag("", 0)], tag_ids.float_tag) ]) stream.write_root_tag(tag) with open(os.path.join(self.world_dir, f"players/{uuid}.dat"), "wb") as file: file.write(gzip.compress(stream.data)) file.close()
def __init__(self, nbt: object = compound_tag(), can_place_on: list = [], can_destroy: list = [], blocking_tick: int = None) -> None: self.nbt: object = nbt self.can_place_on: list = can_place_on self.can_destroy: list = can_destroy self.blocking_tick: int = blocking_tick
def read_data(self, data: bytes) -> None: stream: object = nbt_be_binary_stream(data) tag: object = compound_tag() tag.read(stream) root_tag: object = tag.get_tag("") self.data_version: object = root_tag.get_tag("DataVersion").value level_tag: object = root_tag.get_tag("Level") self.x: int = level_tag.get_tag("xPos").value self.z: int = level_tag.get_tag("zPos").value self.data: list = level_tag