def _operation(
     self, world: "World", dimension: Dimension, selection: SelectionGroup
 ) -> OperationReturnType:
     path = self._file_picker.GetPath()
     platform = self._version_define.platform
     version = self._version_define.version_number
     if isinstance(path, str) and platform and version:
         wrapper = ConstructionFormatWrapper(path)
         if wrapper.exists:
             response = wx.MessageDialog(
                 self,
                 f"A file is already present at {path}. Do you want to continue?",
                 style=wx.YES | wx.NO,
             ).ShowModal()
             if response == wx.ID_CANCEL:
                 return
         wrapper.create_and_open(platform, version, selection)
         wrapper.translation_manager = world.translation_manager
         wrapper_dimension = wrapper.dimensions[0]
         chunk_count = len(list(selection.chunk_locations()))
         yield 0, f"Exporting {os.path.basename(path)}"
         for chunk_index, (cx, cz) in enumerate(selection.chunk_locations()):
             try:
                 chunk = world.get_chunk(cx, cz, dimension)
                 wrapper.commit_chunk(chunk, wrapper_dimension)
             except ChunkLoadError:
                 continue
             yield (chunk_index + 1) / chunk_count
         wrapper.save()
         wrapper.close()
     else:
         raise OperationError(
             "Please specify a save location and version in the options before running."
         )
    def _operation(self, world: "World", dimension: Dimension,
                   selection: SelectionGroup) -> OperationReturnType:
        if len(selection.selection_boxes) == 0:
            raise OperationError("No selection was given to export.")
        elif len(selection.selection_boxes) != 1:
            raise OperationError(
                "The mcstructure format only supports a single selection box.")

        path = self._file_picker.GetPath()
        version = self._version_define.version_number

        if isinstance(path, str) and path.endswith(".mcstructure") and version:
            wrapper = MCStructureFormatWrapper(path, "w")
            wrapper.selection = selection
            wrapper.version = version
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            chunk_count = len(list(selection.chunk_locations()))
            yield 0, f"Exporting {os.path.basename(path)}"
            for chunk_index, (cx,
                              cz) in enumerate(selection.chunk_locations()):
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, world.palette)
                except ChunkLoadError:
                    continue
                yield (chunk_index + 1) / chunk_count

            wrapper.close()
        else:
            raise OperationError(
                "Please specify a save location and version in the options before running."
            )
def prune_chunks(world: "BaseLevel", dimension: Dimension,
                 selection: SelectionGroup):
    chunks = world.all_chunk_coords(dimension).difference(
        selection.chunk_locations())
    for i, (cx, cz) in enumerate(chunks):
        world.delete_chunk(cx, cz, dimension)
        yield (i + 1) / len(chunks)
def export_construction(world: "World", dimension: Dimension,
                        selection: SelectionGroup, options: dict):
    path, platform, version = options.get('path', None), options.get(
        'platform', None), options.get('version', None)
    if isinstance(
            path,
            str) and path.endswith('.construction') and platform and version:
        wrapper = ConstructionFormatWrapper(path, 'w')
        wrapper.platform = platform
        wrapper.version = version
        wrapper.selection = selection
        wrapper.translation_manager = world.translation_manager
        wrapper.open()
        for cx, cz in selection.chunk_locations():
            try:
                chunk = world.get_chunk(cx, cz, dimension)
                wrapper.commit_chunk(chunk, world.palette)
            except ChunkLoadError:
                continue

        wrapper.close()
    else:
        raise Exception(
            'Please specify a save location and version in the options before running.'
        )
Beispiel #5
0
 def create_chunks(
     world: BaseLevel,
     dimension: Dimension,
     selection: SelectionGroup,
 ):
     for cx, cz in selection.chunk_locations():
         if not world.has_chunk(cx, cz, dimension):
             world.put_chunk(Chunk(cx, cz), dimension)
Beispiel #6
0
    def _operation(
        self, world: "BaseLevel", dimension: Dimension, selection: SelectionGroup
    ) -> OperationReturnType:
        if len(selection.selection_boxes) == 0:
            raise OperationError("No selection was given to export.")
        elif len(selection.selection_boxes) != 1:
            raise OperationError(
                "The Sponge Schematic format only supports a single selection box."
            )

        path = self._file_picker.GetPath()
        version = self._version_define.version_number
        if isinstance(path, str):
            wrapper = SpongeSchemFormatWrapper(path)
            if wrapper.exists:
                response = wx.MessageDialog(
                    self,
                    f"A file is already present at {path}. Do you want to continue?",
                    style=wx.YES | wx.NO,
                ).ShowModal()
                if response == wx.ID_CANCEL:
                    return
            wrapper.create_and_open("java", version, selection, True)
            wrapper.translation_manager = world.translation_manager
            wrapper_dimension = wrapper.dimensions[0]
            chunk_count = len(list(selection.chunk_locations()))
            yield 0, f"Exporting {os.path.basename(path)}"
            for chunk_index, (cx, cz) in enumerate(selection.chunk_locations()):
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, wrapper_dimension)
                except ChunkLoadError:
                    continue
                yield (chunk_index + 1) / chunk_count
            wrapper.save()
            wrapper.close()
        else:
            raise OperationError(
                "Please specify a save location and version in the options before running."
            )
def delete_chunk(
    world: "BaseLevel",
    dimension: Dimension,
    source_box: SelectionGroup,
    load_original: bool = True,
):
    chunks = [(cx, cz) for (cx, cz) in source_box.chunk_locations()
              if world.has_chunk(cx, cz, dimension)]
    iter_count = len(chunks)
    for count, (cx, cz) in enumerate(chunks):
        world.delete_chunk(cx, cz, dimension)

        if not load_original:
            # this part is kind of hacky.
            # Work out a propery API to do this.
            key = dimension, cx, cz
            if key not in world.chunks._history_database:
                world.chunks._register_original_entry(key, Chunk(cx, cz))

        yield (count + 1) / iter_count
    def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup) -> OperationReturnType:
        path = self._file_picker.GetPath()
        platform = self._version_define.platform
        version = self._version_define.version
        if isinstance(path, str) and path.endswith('.construction') and platform and version:
            wrapper = ConstructionFormatWrapper(path, 'w')
            wrapper.platform = platform
            wrapper.version = version
            wrapper.selection = selection
            wrapper.translation_manager = world.translation_manager
            wrapper.open()
            for cx, cz in selection.chunk_locations():
                try:
                    chunk = world.get_chunk(cx, cz, dimension)
                    wrapper.commit_chunk(chunk, world.palette)
                except ChunkLoadError:
                    continue

            wrapper.close()
        else:
            raise OperationError('Please specify a save location and version in the options before running.')