def test_loading(self): numerical_java_world = load_level(create_temp_world("Java 1.12.2")) self.assertIsInstance(numerical_java_world, World) numerical_java_world.close() clean_temp_world("Java 1.12.2") blocksate_java_world = load_level(create_temp_world("Java 1.13")) self.assertIsInstance(blocksate_java_world, World) blocksate_java_world.close() clean_temp_world("Java 1.13")
def _on_open_file(self, evt): with wx.FileDialog( self.canvas, "Open a Minecraft data file", wildcard="|". join([ # TODO: Automatically load these from the FormatWrapper classes. "All files (*.construction;*.mcstructure;*.schematic)|*.construction;*.mcstructure;*.schematic", "Construction file (*.construction)|*.construction", "Bedrock mcstructure file (*.mcstructure)|*.mcstructure", "Legacy Schematic file (*.schematic)|*.schematic", "Sponge Schematic file (*.schem)|*.schem", ]), style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, ) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return else: pathname = fileDialog.GetPath() try: level = amulet.load_level(pathname) except LoaderNoneMatched: wx.MessageBox(f"Could not find a matching loader for {pathname}.") log.error(f"Could not find a matching loader for {pathname}.") except Exception as e: log.error( f"Could not open {pathname}. Check the console for more details.\n{traceback.format_exc()}" ) wx.MessageBox( f"Could not open {pathname}. Check the console for more details.\n{e}" ) else: self.canvas.paste(level, level.dimensions[0])
def _on_drop_files(self, evt: wx.DropFilesEvent): """Logic to run when a file is dropped into the canvas.""" paths = evt.GetFiles() if paths: pathname = paths[0] if os.path.isfile(pathname): # TODO: if importing worlds get supported fix this try: level = amulet.load_level(pathname) except LoaderNoneMatched: msg = f"Could not find a matching loader for {pathname}." wx.MessageBox(msg) log.error(msg) except Exception as e: log.error(f"Could not open {pathname}.", exc_info=True) dialog = TracebackDialog( self.canvas, f"Could not open {pathname}.", str(e), traceback.format_exc(), ) dialog.ShowModal() dialog.Destroy() else: self.canvas.paste(level, level.dimensions[0]) evt.Skip()
def load_level_from_world(level_folder, coord_box): # World is a amulet data structure world = load_level(level_folder) coord_start, coord_end = coord_box box = SelectionBox(coord_start, coord_end) # Level is a np array of Blocks coord_offset = np.array(box.min) print("Offset: {}".format(coord_offset)) level = level_from_world(world, box) signs = get_signs(world, box, coord_offset) return level, signs
def __init__(self, parent: wx.Window, path: str, close_self_callback: Callable[[], None]): super().__init__(parent, style=wx.NB_LEFT) self._path = path self._close_self_callback = close_self_callback try: self.world = load_level(path) except LoaderNoneMatched as e: self.Destroy() raise e self.world_name = self.world.level_wrapper.world_name self._extensions: List[BaseProgram] = [] self._last_extension: int = -1 self._load_extensions() self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._page_change)
def _on_drop_files(self, evt: wx.DropFilesEvent): paths = evt.GetFiles() if paths: pathname = paths[0] if os.path.isfile(pathname): # TODO: if importing worlds get supported fix this try: level = amulet.load_level(pathname) except LoaderNoneMatched: wx.MessageBox(f"Could not find a matching loader for {pathname}.") log.error(f"Could not find a matching loader for {pathname}.") except Exception as e: wx.MessageBox( f"Could not open {pathname}. Check the console for more details.\n{e}" ) log.error( f"Could not open {pathname}. Check the console for more details.\n{traceback.format_exc()}" ) else: self.canvas.paste(level, level.dimensions[0]) evt.Skip()
import amulet from amulet.api.block import Block # load the level level = amulet.load_level("level") # pick a game version that we want to work with. # see the next page to see what versions are available. game_version = ("bedrock", (1, 16, 20) ) # the version that we want the block data in. # get a block block, block_entity = level.get_version_block( 0, # x location 70, # y location 0, # z location "minecraft:overworld", # dimension game_version, ) if isinstance(block, Block): # Check that what we have is actually a block. # There are some edge cases such as item frames where the returned value might not be a Block. print(block) # Block(minecraft:air) # set a block # define a block in the format of the version we want to work with. block = Block("minecraft", "stone") level.set_version_block( 0, # x location
def _setUp(self, world_name): self._world_name = world_name self.world = load_level(create_temp_world(world_name))
def test_loading(self): for path in worlds_src.levels: with WorldTemp(path) as world_temp: numerical_java_world = load_level(world_temp.temp_path) self.assertIsInstance(numerical_java_world, World) numerical_java_world.close()