Esempio n. 1
0
 def _copy(self):
     selection = self._get_box()
     if selection is None:
         return
     structure = Structure.from_world(self._world, selection,
                                      self._canvas.dimension)
     structure_buffer.append(structure)
Esempio n. 2
0
def copy(world: "World", dimension: Dimension, selection: SelectionGroup):
    if selection:
        structure = Structure.from_world(world, selection, dimension)
        structure_cache.add_structure(structure)
        raise OperationSilentAbort
    else:
        raise OperationError(
            "At least one selection is required for the copy operation.")
Esempio n. 3
0
def cut(world: "World", dimension: Dimension,
        selection: SelectionGroup) -> OperationReturnType:
    structure = Structure.from_world(world, selection, dimension)
    structure_cache.add_structure(structure)
    yield from delete(
        world,
        dimension,
        selection,
    )
Esempio n. 4
0
def cut(world: "World", dimension: Dimension,
        selection: SelectionGroup) -> OperationReturnType:
    if selection:
        structure = Structure.from_world(world, selection, dimension)
        structure_cache.add_structure(structure)
        yield from delete(
            world,
            dimension,
            selection,
        )
    else:
        raise OperationError(
            "At least one selection is required for the copy operation.")
Esempio n. 5
0
def clone(world: "World", dimension: Dimension, source: SelectionGroup,
          target: dict):
    dst_location = (target.get("x", 0), target.get("y", 0), target.get("z", 0))
    structure = Structure.from_world(world, source, dimension)
    for (
            src_chunk,
            src_slices,
            _,
        (dst_cx, dst_cz),
            dst_slices,
            _,
    ) in structure.get_moved_chunk_slices(dst_location):
        dst_chunk = world.get_chunk(dst_cx, dst_cz, dimension)
        dst_chunk.blocks[dst_slices] = src_chunk.blocks[src_slices]
        dst_chunk.changed = True
Esempio n. 6
0
def copy_selection(
    world: "World",
    dimension: Dimension,
    selection: SelectionGroup
):
    structure = Structure.from_world(
        world, selection, dimension
    )
    structure_buffer.append(structure)
    yield from fill(
        world,
        dimension,
        selection,
        {
            "fill_block": world.translation_manager.get_version(
                'java', (1, 15, 2)
            ).block.to_universal(
                Block("minecraft", "air")
            )[0]
        }
    )
Esempio n. 7
0
def copy(world: "World", dimension: Dimension, selection: SelectionGroup):
    structure = Structure.from_world(world, selection, dimension)
    structure_cache.add_structure(structure)
    raise OperationSilentAbort
Esempio n. 8
0
 def _operation(self, world: "World", dimension: Dimension,
                selection: SelectionGroup) -> OperationReturnType:
     structure = Structure.from_world(world, selection, dimension)
     self.canvas.paste(structure)
     raise OperationSilentAbort
Esempio n. 9
0
    def _run_operation(self, operation_path=None) -> Any:
        if operation_path is None:
            operation_path = self._operation_options.operation
        operation = plugins.all_operations[operation_path]
        features = operation.get("features", [])
        operation_input_definitions = operation.get("inputs", [])
        if any(feature in features for feature in ("dst_location_absolute", )):
            if "structure_callable" in operation:
                operation_inputs = []
                for inp in operation.get("structure_callable_inputs", []):
                    if inp == "src_selection":
                        selection = self._get_box()
                        if selection is None:
                            return
                        operation_inputs.append(selection)

                    elif inp == "options":
                        operation_inputs.append(
                            plugins.options.get(operation_path, {}))

                self._operation_options.Disable()

                self._canvas.disable_threads()
                try:
                    structure = show_loading_dialog(
                        lambda: operation["structure_callable"]
                        (self._world, self._canvas.dimension, *operation_inputs
                         ),
                        f'Running structure operation for {operation["name"]}.',
                        "Please wait for the operation to finish.",
                        self,
                    )
                except Exception as e:
                    log.error(
                        f"Error running structure operation: {e}\n{traceback.format_exc()}"
                    )
                    wx.MessageBox(f"Error running structure operation: {e}")
                    self._world.restore_last_undo_point()
                    self._canvas.enable_threads()
                    return
                self._canvas.enable_threads()

                self._operation_options.Enable()
                if not isinstance(structure, Structure):
                    log.error(
                        "Object returned from structure_callable was not a Structure. Aborting."
                    )
                    wx.MessageBox(
                        "Object returned from structure_callable was not a Structure. Aborting."
                    )
                    return
            else:
                selection = self._get_box()
                if selection is None:
                    return
                self._operation_options.Disable()
                structure = show_loading_dialog(
                    lambda: Structure.from_world(self._world, selection, self.
                                                 _canvas.dimension),
                    f'Running structure operation for {operation["name"]}.',
                    "Copying structure from world.",
                    self,
                )
                self._operation_options.Enable()

            if "dst_location_absolute" in features:
                # trigger UI to show select box UI
                self._operation_options.enable_select_destination_ui(
                    operation_path,
                    operation["operation"],
                    operation_input_definitions,
                    structure,
                    plugins.options.get(operation_path, {}),
                )
            else:
                # trigger UI to show select box multiple UI
                raise NotImplementedError

        else:
            self._operation_options.Disable()
            out = self._run_main_operation(operation_path,
                                           operation["operation"],
                                           operation_input_definitions)
            self._operation_options.Enable()
            return out
Esempio n. 10
0
    def _run_operation(self, evt):
        operation_path = self._operation_ui.operation
        operation = operations.operations[operation_path]
        features = operation.get("features", [])
        operation_input_definitions = operation.get("inputs", [])
        if any(feature in features for feature in ("dst_location_absolute", )):
            if "structure_callable" in operation:
                operation_inputs = []
                for inp in operation.get("structure_callable_inputs", []):
                    if inp == "src_selection":
                        selection = self._get_box()
                        if selection is None:
                            return
                        operation_inputs.append(selection)

                    elif inp == "options":
                        operation_inputs.append(
                            operations.options.get(operation_path, {}))

                self._operation_ui.Disable()

                self._canvas.disable_threads()
                try:
                    structure = self._world.run_operation(
                        operation["structure_callable"],
                        self._canvas.dimension,
                        *operation_inputs,
                        create_undo=False)
                except Exception as e:
                    wx.MessageBox(f"Error running structure operation: {e}")
                    self._world.restore_last_undo_point()
                    self._canvas.enable_threads()
                    return
                self._canvas.enable_threads()

                self._operation_ui.Enable()
                if not isinstance(structure, Structure):
                    wx.MessageBox(
                        "Object returned from structure_callable was not a Structure. Aborting."
                    )
                    return
            else:
                selection = self._get_box()
                if selection is None:
                    return
                self._operation_ui.Disable()
                structure = Structure.from_world(self._world, selection,
                                                 self._canvas.dimension)
                self._operation_ui.Enable()

            if "dst_location_absolute" in features:
                # trigger UI to show select box UI
                self._select_destination_ui.setup(
                    operation_path, operation["operation"],
                    operation_input_definitions, structure,
                    operations.options.get(operation_path, {}))
                self._enable_select_destination_ui(structure)
            else:
                # trigger UI to show select box multiple UI
                raise NotImplementedError

        else:
            self._operation_ui.Disable()
            self._run_main_operation(operation_path, operation["operation"],
                                     operation_input_definitions)
            self._operation_ui.Enable()
        evt.Skip()
Esempio n. 11
0
def copy_selection(world: "World", dimension: Dimension,
                   selection: SelectionGroup):
    structure = Structure.from_world(world, selection, dimension)
    structure_buffer.append(structure)
    return True