def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup): path = self._file_picker.GetPath() if isinstance(path, str) and path.endswith( '.construction') and os.path.isfile(path): wrapper = ConstructionFormatWrapper(path, 'r') wrapper.translation_manager = world.translation_manager wrapper.open() selection = wrapper.selection global_palette = BlockManager() chunks = {} chunk_count = len(list(wrapper.all_chunk_coords())) for chunk_index, (cx, cz) in enumerate(wrapper.all_chunk_coords()): try: chunks[(cx, cz)] = wrapper.load_chunk(cx, cz, global_palette) yield 100 * (chunk_index + 1) / chunk_count except ChunkLoadError: pass wrapper.close() self.canvas.paste(Structure(chunks, global_palette, selection)) else: raise OperationError( 'Please specify a construction file in the options before running.' )
def import_construction( world: "World", dimension: Dimension, options: dict ) -> Structure: path = options.get('path', None) if isinstance(path, str) and path.endswith('.construction') and os.path.isfile(path): wrapper = ConstructionFormatWrapper(path, 'r') wrapper.translation_manager = world.translation_manager wrapper.open() selection = wrapper.selection global_palette = BlockManager() chunks = {} for (cx, cz) in wrapper.all_chunk_coords(): try: chunks[(cx, cz)] = wrapper.load_chunk(cx, cz, global_palette) except ChunkLoadError: pass wrapper.close() return Structure( chunks, global_palette, selection ) else: raise Exception('Please specify a construction file in the options before running.')
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)
def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup): path = self._file_picker.GetPath() if (isinstance(path, str) and path.endswith(".mcstructure") and os.path.isfile(path)): wrapper = MCStructureFormatWrapper(path, "r") wrapper.translation_manager = world.translation_manager wrapper.open() selection = wrapper.selection global_palette = BlockManager() chunks = {} chunk_count = len(list(wrapper.all_chunk_coords())) yield 0, f"Importing {os.path.basename(path)}" for chunk_index, (cx, cz) in enumerate(wrapper.all_chunk_coords()): try: chunk = chunks[(cx, cz)] = wrapper.load_chunk(cx, cz) chunk.block_palette = global_palette except ChunkLoadError: pass yield (chunk_index + 1) / chunk_count wrapper.close() self.canvas.paste(Structure(chunks, global_palette, selection)) else: raise OperationError( "Please specify a mcstructure file in the options before running." )
def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup): path = self._file_picker.GetPath() if isinstance( path, str) and path.endswith('.schematic') and os.path.isfile(path): wrapper = SchematicFormatWrapper(path, 'r') wrapper.translation_manager = world.translation_manager wrapper.open() selection = wrapper.selection global_palette = BlockManager() chunks = {} for (cx, cz) in wrapper.all_chunk_coords(): try: chunks[(cx, cz)] = wrapper.load_chunk(cx, cz, global_palette) except ChunkLoadError: pass wrapper.close() self.canvas.paste(Structure(chunks, global_palette, selection)) else: raise OperationError( 'Please specify a schematic file in the options before running.' )
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.")
def paste(world: "World", dimension: int, source: Selection, structure: Structure, dst: dict): dst_location = (dst.get('x', 0), dst.get('y', 0), dst.get('z', 0)) 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
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, )
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.")
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
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] } )
def copy_selection(world: "World", dimension: Dimension, selection: SelectionGroup): structure = Structure.from_world(world, selection, dimension) structure_buffer.append(structure) return True
def copy(world: "World", dimension: Dimension, selection: SelectionGroup): structure = Structure.from_world(world, selection, dimension) structure_cache.add_structure(structure) raise OperationSilentAbort
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()
def _operation(self, world: "World", dimension: Dimension, selection: SelectionGroup) -> OperationReturnType: structure = Structure.from_world(world, selection, dimension) self.canvas.paste(structure) raise OperationSilentAbort
def paste_iter( world: "World", dimension: Dimension, structure: Structure, location: BlockCoordinates, scale: FloatTriplet, rotation: FloatTriplet, copy_air=True, copy_water=True, copy_lava=True, ): gab = numpy.vectorize(world.palette.get_add_block, otypes=[numpy.uint32]) lut = gab(structure.palette.blocks()) filtered_mode = not all([copy_air, copy_lava, copy_water]) filtered_blocks = [] if not copy_air: filtered_blocks.append("universal_minecraft:air") if not copy_water: filtered_blocks.append("universal_minecraft:water") if not copy_lava: filtered_blocks.append("universal_minecraft:lava") if filtered_mode: paste_blocks = numpy.array([ any(sub_block.namespaced_name not in filtered_blocks for sub_block in block.block_tuple) for block in structure.palette.blocks() ]) else: paste_blocks = None rotation_point = numpy.floor( (structure.selection.max + structure.selection.min) / 2).astype(int) if any(rotation) or any(s != 1 for s in scale): yield 0, "Rotating!" transformed_structure = yield from structure.transform_iter( scale, rotation) rotation_point = (numpy.matmul( transform_matrix((0, 0, 0), scale, -numpy.radians(numpy.flip(rotation)), "zyx"), numpy.array([*rotation_point, 1]), ).T[:3].round().astype(int)) else: transformed_structure = structure offset = location - rotation_point moved_min_location = transformed_structure.selection.min + offset iter_count = len( list(transformed_structure.get_moved_chunk_slices(moved_min_location))) count = 0 yield 0, "Pasting!" for ( src_chunk, src_slices, src_box, (dst_cx, dst_cz), dst_slices, dst_box, ) in transformed_structure.get_moved_chunk_slices(moved_min_location): try: dst_chunk = world.get_chunk(dst_cx, dst_cz, dimension) except ChunkDoesNotExist: dst_chunk = Chunk(dst_cx, dst_cz) world.put_chunk(dst_chunk, dimension) except ChunkLoadError: continue remove_block_entities = [] for block_entity_location in dst_chunk.block_entities.keys(): if block_entity_location in dst_box: if copy_air: remove_block_entities.append(block_entity_location) else: chunk_block_entity_location = ( numpy.array(block_entity_location) - offset) chunk_block_entity_location[[0, 2]] %= 16 if paste_blocks[src_chunk.blocks[tuple( chunk_block_entity_location)]]: remove_block_entities.append(block_entity_location) for block_entity_location in remove_block_entities: del dst_chunk.block_entities[block_entity_location] for block_entity_location, block_entity in src_chunk.block_entities.items( ): if block_entity_location in src_box: dst_chunk.block_entities.insert( block_entity.new_at_location(*offset + block_entity_location)) if not copy_air: # dst_blocks_copy = dst_chunk.blocks[dst_slices] # mask = paste_blocks[src_chunk.blocks[src_slices]] # dst_blocks_copy[mask] = lut[src_chunk.blocks[src_slices]][mask] dst_blocks_copy = numpy.asarray(dst_chunk.blocks[dst_slices]) mask = paste_blocks[src_chunk.blocks[src_slices]] dst_blocks_copy[mask] = lut[src_chunk.blocks[src_slices]][mask] dst_chunk.blocks[dst_slices] = dst_blocks_copy else: dst_chunk.blocks[dst_slices] = lut[src_chunk.blocks[src_slices]] dst_chunk.changed = True count += 1 yield count / iter_count
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