def test_height(self):
     with WorldTemp(self.WorldPath) as world_temp:
         test_data_path = os.path.join(world_temp.temp_path, "world_test_data.json")
         self.assertTrue(
             os.path.isfile(test_data_path),
             msg=f"Could not find world_test_data.json for world {self.WorldPath}",
         )
         with open(test_data_path) as f:
             test_data = json.load(f)
         self.assertIn("dim_height", test_data, msg=self.WorldPath)
         self.assertIsInstance(test_data["dim_height"], dict, msg=self.WorldPath)
         height_data = test_data["dim_height"]
         world_wrapper = load_format(world_temp.temp_path)
         world_wrapper.open()
         self.assertEqual(
             sorted(test_data["dim_height"]),
             sorted(world_wrapper.dimensions),
             msg=self.WorldPath,
         )
         for dim in world_wrapper.dimensions:
             box = world_wrapper.bounds(dim).to_box()
             self.assertEqual(
                 height_data[dim], [list(box.min), list(box.max)], msg=self.WorldPath
             )
         world_wrapper.close()
    def __init__(self, parent: wx.Window, world_dirs, open_world_callback, sort=True):
        super().__init__(parent)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        self.worlds = []

        world_formats = []
        for world_path in world_dirs:
            if os.path.isdir(world_path):
                try:
                    world_formats.append(load_format(world_path))
                except FormatError as e:
                    log.info(f"Could not find loader for {world_path} {e}")
                except Exception:
                    log.error(
                        f"Error loading format wrapper for {world_path} {traceback.format_exc()}"
                    )
        if sort:
            world_formats = reversed(sorted(world_formats, key=lambda f: f.last_played))

        for world_format in world_formats:
            try:
                world_button = WorldUIButton(self, world_format, open_world_callback)
                sizer.Add(
                    world_button, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 5
                )
                self.worlds.append(world_button)
            except Exception as e:
                log.info(f"Failed to display world button for {world_format.path} {e}")

        self.Layout()
Exemple #3
0
    def __init__(self, parent, world_dirs, open_world_callback, sort=True):
        super(WorldList, self).__init__(parent)

        self.worlds = []

        world_formats = []
        for world_path in world_dirs:
            if os.path.isdir(world_path):
                try:
                    world_formats.append(load_format(world_path))
                except FormatError as e:
                    log.info(f"Could not find loader for {world_path} {e}")
                except Exception:
                    log.error(
                        f"Error loading format wrapper for {world_path} {traceback.format_exc()}"
                    )
        if sort:
            world_formats = reversed(sorted(world_formats, key=lambda f: f.last_played))

        for world_format in world_formats:
            try:
                world_button = WorldUIButton(self, world_format, open_world_callback)
                self.add_object(world_button, 0, wx.ALL | wx.EXPAND)
                self.worlds.append(world_button)
            except Exception as e:
                log.info(f"Failed to display world button for {world_format.path} {e}")

        self.Layout()
Exemple #4
0
    def test_decode_encode(self):
        """Test decoding chunk data and then encoding it again to make sure it matches."""
        with WorldTemp(self.WorldPath) as world_temp:
            level = load_format(world_temp.temp_path)
            level.open()
            chunk_count = 0
            for dimension in level.dimensions:
                for cx, cz in level.all_chunk_coords(dimension):
                    raw_chunk_data_in = level._get_raw_chunk_data(cx, cz, dimension)
                    raw_chunk_data = copy.deepcopy(raw_chunk_data_in)
                    interface = level._get_interface(raw_chunk_data)

                    if (
                        world_temp.metadata["world_data"]["platform"] == "java"
                        and world_temp.metadata["world_data"]["origin"] == "vanilla"
                    ):
                        # store references to the data
                        level_tag = raw_chunk_data.get("Level", TAG_Compound())

                    # decode the raw chunk data
                    chunk, chunk_palette = level._decode(
                        interface, dimension, cx, cz, raw_chunk_data
                    )

                    # TODO: uncomment this when the last few things in the Java format are sorted
                    # if (
                    #     world_temp.metadata["world_data"]["platform"] == "java"
                    #     and world_temp.metadata["world_data"]["origin"] == "vanilla"
                    # ):
                    #     self.assertFalse(raw_chunk_data, msg=self.WorldPath)
                    #     self.assertFalse(level_tag, msg=self.WorldPath)

                    raw_chunk_data_out = level._encode(
                        interface, chunk, dimension, chunk_palette
                    )
                    if chunk_count > 100:
                        break
                    chunk_count += 1
                    # if raw_chunk_data_in != raw_chunk_data_out:
                    #     print("Difference")
                    #     print(raw_chunk_data_in.value.find_diff(raw_chunk_data_out.value))
                    # print(raw_chunk_data_in.to_snbt())
                    # print(raw_chunk_data_out.to_snbt())

                    # self.assertEqual(raw_chunk_data_in, raw_chunk_data_out)

                    raw_chunk_data2 = copy.deepcopy(raw_chunk_data_out)
                    if world_temp.metadata["world_data"]["platform"] == "bedrock":
                        raw_chunk_data2 = {
                            key: val
                            for key, val in raw_chunk_data2.items()
                            if val is not None
                        }
                    level._decode(interface, dimension, cx, cz, raw_chunk_data2)
            level.close()
Exemple #5
0
    def _output_world_callback(self, path):
        if path == self.world.world_path:
            wx.MessageBox(
                lang.get("program_convert.input_output_must_different"))
            return
        try:
            out_world_format = load_format(path)
            self.out_world_path = path

        except Exception:
            return

        for child in list(self._output.GetChildren())[1:]:
            child.Destroy()
        self._output.add_object(WorldUI(self._output, out_world_format), 0)
        self._output.Layout()
        self._output.Fit()
        self.Layout()
        def test_save(self):
            version_string = self.world.level_wrapper.game_version_string

            if "1.12.2" in version_string:
                world_name = worlds_src.java_vanilla_1_13
                world_name_temp = f"{worlds_src.java_vanilla_1_12_2} to {worlds_src.java_vanilla_1_13}"
            else:
                world_name = worlds_src.java_vanilla_1_12_2
                world_name_temp = f"{worlds_src.java_vanilla_1_13} to {worlds_src.java_vanilla_1_12_2}"

            output_wrapper = load_format(
                create_temp_world(world_name, world_name_temp))
            output_wrapper.open()

            self.world.save(output_wrapper)
            self.world.close()
            output_wrapper.close()

            clean_temp_world(world_name_temp)
Exemple #7
0
        def test_save(self):
            version_string = self.world.level_wrapper.game_version_string

            if "1.12.2" in version_string:
                world_name = "Java 1.13"
                world_name_temp = "Java 1.12.2 to Java 1.13"
            else:
                world_name = "Java 1.12.2"
                world_name_temp = "Java 1.13 to Java 1.12.2"

            output_wrapper = load_format(
                create_temp_world(world_name, world_name_temp))
            output_wrapper.open()

            self.world.save(output_wrapper)
            self.world.close()
            output_wrapper.close()

            clean_temp_world(world_name_temp)
Exemple #8
0
 def _convert_method(self):
     global work_count
     try:
         out_world = load_format(self.out_world_path)
         log.info(
             f"Converting world {self.world.level_path} to {out_world.path}"
         )
         out_world: WorldFormatWrapper
         out_world.open()
         self.world.save(out_world, self._update_loading_bar)
         out_world.close()
         message = lang.get("program_convert.conversion_completed")
         log.info(
             f"Finished converting world {self.world.level_path} to {out_world.path}"
         )
     except Exception as e:
         message = f"Error during conversion\n{e}"
         log.error(message, exc_info=True)
     self._update_loading_bar(0, 100)
     self.convert_button.Enable()
     wx.MessageBox(message)
     work_count -= 1
Exemple #9
0
    def _test_create(
        self,
        cls: Type[FormatWrapper],
        level_name: str,
        platform: str,
        version: VersionNumberAny,
    ):
        path = clean_temp_world(level_name)

        # create, initialise and save the level
        level = cls(path)
        if level.requires_selection:
            level.create_and_open(
                platform,
                version,
                SelectionGroup([SelectionBox((0, 0, 0), (1, 1, 1))]),
                overwrite=True,
            )
        else:
            level.create_and_open(platform, version, overwrite=True)

        self.assertTrue(level.is_open,
                        "The level was not opened by create_and_open()")
        self.assertTrue(level.has_lock,
                        "The lock was not acquired by create_and_open()")

        platform_ = level.platform
        version_ = level.version
        dimension_selections = {
            dim: level.bounds(dim)
            for dim in level.dimensions
        }

        level.save()
        level.close()

        self.assertFalse(level.is_open, "The level was not closed by close()")
        self.assertFalse(level.has_lock, "The lock was not lost by close()")

        self.assertTrue(os.path.exists(level.path))

        # reopen the level
        level2 = load_format(path)
        # check that the class is the same
        self.assertIs(level.__class__, level2.__class__)
        level2.open()

        self.assertTrue(level2.is_open, "The level was not opened by open()")
        self.assertTrue(level2.has_lock, "The lock was not acquired by open()")

        # check that the platform and version are the same
        self.assertEqual(level2.platform, platform_)
        self.assertEqual(level2.version, version_)
        self.assertEqual(set(level2.dimensions), set(dimension_selections))
        for dim, selection in dimension_selections.items():
            self.assertEqual(level2.bounds(dim), selection)
        level2.close()

        self.assertFalse(level2.is_open, "The level was not closed by close()")
        self.assertFalse(level2.has_lock, "The lock was not lost by close()")

        self.assertTrue(os.path.exists(level.path))

        level = cls(path)
        with self.assertRaises(ObjectWriteError):
            if level.requires_selection:
                level.create_and_open(
                    platform,
                    version,
                    SelectionGroup([SelectionBox((0, 0, 0), (1, 1, 1))]),
                )
            else:
                level.create_and_open(platform, version)

        clean_path(path)
 def test_identify(self):
     for path in worlds_src.JavaVanillaLevels:
         with WorldTemp(path) as world_temp:
             java_format = load_format(world_temp.temp_path)
             self.assertIsInstance(java_format, AnvilFormat)
    def test_identify(self):
        numerical_java_format = load_format(get_world_path("Java 1.12.2"))
        self.assertIsInstance(numerical_java_format, AnvilFormat)

        blockstate_java_format = load_format(get_world_path("Java 1.13"))
        self.assertIsInstance(blockstate_java_format, AnvilFormat)
Exemple #12
0
    def convert_buttonOnButtonClick(self, event):
        if self.input_world_path is None:
            dialog = wx.MessageDialog(self,
                                      "You must select an input world",
                                      "Converter Error",
                                      style=wx.ICON_WARNING | wx.OK
                                      | wx.CENTER)
            dialog.ShowModal()
            dialog.Destroy()
            return

        if self.output_world_path is None:
            dialog = wx.MessageDialog(self,
                                      "You must select an output world",
                                      "Converter Error",
                                      style=wx.ICON_WARNING | wx.OK
                                      | wx.CENTER)
            dialog.ShowModal()
            dialog.Destroy()
            return

        input_world = amulet.load_world(self.input_world_path)
        self.converter_progress.SetValue(20)
        output_world_wrapper = amulet.load_format(self.output_world_path)
        self.converter_progress.SetValue(40)

        if self.run_operation_cb.GetValue():
            operation_name = self.operation_chooser.GetStringSelection().lower(
            )

            operation_args = None
            if operation_name == 'fill':
                operation_args = [
                    amulet.selection.SelectionBox([
                        amulet.selection.SubBox(
                            (self.start_x.GetValue(), self.start_y.GetValue(),
                             self.start_z.GetValue()),
                            (self.end_x.GetValue(), self.end_y.GetValue(),
                             self.end_z.GetValue()))
                    ]),
                    amulet.Block(self.fill_blockstate_field.GetValue())
                ]
            elif operation_name == 'replace':
                operation_args = [
                    amulet.selection.SelectionBox([
                        amulet.selection.SubBox(
                            (self.start_x.GetValue(), self.start_y.GetValue(),
                             self.start_z.GetValue()),
                            (self.end_x.GetValue(), self.end_y.GetValue(),
                             self.end_z.GetValue()))
                    ]), [
                        amulet.Block(self.fill_blockstate_field.GetValue()),
                    ],
                    [
                        amulet.Block(self.replace_blockstate_field.GetValue()),
                    ]
                ]

            self.converter_progress.SetValue(50)
            input_world.run_operation_from_operation_name(
                operation_name, *operation_args)
            self.converter_progress.SetValue(60)

        self.converter_progress.SetValue(70)

        def progress_update(index, count):
            self.converter_progress.SetValue(int(100 * index / count))
            self.Update()

        input_world.save(output_world_wrapper, progress_update)
        input_world.close()
        output_world_wrapper.close()
        self.converter_progress.SetValue(100)

        finished_dialog = wx.MessageDialog(self,
                                           "World conversion has completed",
                                           "Conversion Finished",
                                           style=wx.ICON_INFORMATION
                                           | wx.CENTER | wx.OK)
        finished_dialog.ShowModal()
        finished_dialog.Destroy()