-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ezfe-improv-world-loading'
- Loading branch information
Showing
15 changed files
with
345 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from __future__ import annotations | ||
|
||
from os.path import exists, join | ||
|
||
from nbt import nbt | ||
|
||
|
||
def check_all_exist(in_dir: str, *args: str) -> bool: | ||
""" | ||
Check that all files exist in a parent directory | ||
:param in_dir: The parent directory | ||
:param *args: file or folder names to look for | ||
:return: Boolean value indicating whether all were found | ||
""" | ||
|
||
for child in args: | ||
if not exists(join(in_dir, child)): | ||
print(f"Didn't find {child}") | ||
return False | ||
else: | ||
print(f"Found {child}") | ||
|
||
return True | ||
|
||
|
||
def check_one_exists(in_dir: str, *args: str) -> bool: | ||
""" | ||
Check that at least one file exists in a parent directory | ||
:param in_dir: The parent directory | ||
:param *args: file or folder names to look for | ||
:return: Boolean value indicating whether at least one was found | ||
""" | ||
|
||
for child in args: | ||
if exists(join(in_dir, child)): | ||
print(f"Found {child}") | ||
return True | ||
|
||
return False | ||
|
||
|
||
def load_leveldat(in_dir: str): | ||
""" | ||
Load the root tag of the level.dat file in the directory | ||
:param in_dir: The world directory containing the level.dat file | ||
:return: The NBT root tag | ||
""" | ||
|
||
fp = open(join(in_dir, "level.dat"), "rb") | ||
root_tag = nbt.NBTFile(fileobj=fp) | ||
fp.close() | ||
|
||
return root_tag | ||
|
||
|
||
def check_version_leveldat(root_tag, min: int = None, max: int = None) -> bool: | ||
""" | ||
Check the Version tag from the provided level.dat NBT structure | ||
:param root_tag: the root level.dat tag | ||
:param min: The lowest acceptable value (optional) | ||
:param max: The highest acceptable value (optional) | ||
:return: Whether the version tag falls in the correct range | ||
""" | ||
|
||
version_found: int = root_tag.get("Data", nbt.TAG_Compound()).get( | ||
"Version", nbt.TAG_Compound() | ||
).get("Id", nbt.TAG_Int(-1)).value | ||
|
||
min_qualifies: bool = True | ||
if min is not None: | ||
min_qualifies = version_found >= min | ||
|
||
max_qualifies: bool = True | ||
if max is not None: | ||
max_qualifies = version_found <= max | ||
|
||
if __debug__: | ||
min_text: str = f"{min} <= " if min is not None else "" | ||
max_text: str = f" >= {max}" if max is not None else "" | ||
print(f"Checking {min_text}{version_found}{max_text}") | ||
|
||
return min_qualifies and max_qualifies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.