Ejemplo n.º 1
0
def check_version_leveldat(
    root_tag: nbt.TAG_Compound, _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
Ejemplo n.º 2
0
    def from_palette(cls, tag: nbt.TAG_Compound):
        """
        Creates a new Block from the tag format on Section.Palette

        Parameters
        ----------
        tag
            Raw tag from a section's palette
        """
        name = tag['Name'].value
        properties = tag.get('Properties')
        if properties:
            properties = dict(properties)
        return cls.from_name(name, properties=properties)