From c876253f76104c56947f82aecd342951a8848a76 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Feb 2025 15:30:39 +0000 Subject: [PATCH 1/2] tools/blockstate-upgrade-schema-utils: added dump-table command this command dumps a human-readable version of pmmp/mapping palette mapping files to a .txt file. may be useful for debugging issues with the schema generator or the upgrade process. --- tools/blockstate-upgrade-schema-utils.php | 42 ++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tools/blockstate-upgrade-schema-utils.php b/tools/blockstate-upgrade-schema-utils.php index 4f5c8740c..6bfe44a03 100644 --- a/tools/blockstate-upgrade-schema-utils.php +++ b/tools/blockstate-upgrade-schema-utils.php @@ -51,8 +51,10 @@ use function array_unique; use function array_values; use function count; use function dirname; +use function fclose; use function file_exists; use function file_put_contents; +use function fopen; use function fwrite; use function get_class; use function get_debug_type; @@ -885,6 +887,43 @@ function cmdUpdateAll(array $argv) : int{ return 0; } +/** + * @param string[] $argv + */ +function cmdDumpTable(array $argv) : int{ + $tableFile = $argv[2]; + $outputFile = $argv[3]; + + $output = fopen($outputFile, 'wb'); + if($output === false){ + fwrite(STDERR, "Failed to open output file: $outputFile\n"); + return 1; + } + + $table = loadUpgradeTableFromFile($tableFile, reverse: false); + + foreach(Utils::stringifyKeys($table) as $oldName => $mappings){ + fwrite($output, "---------- MAPPING LIST: $oldName ----------\n"); + foreach($mappings as $mapping){ + $oldNbt = $mapping->old->toVanillaNbt(); + $oldNbt->setInt("version", $mapping->new->getVersion()); + + //intentionally not reused result of toVanillaNbt otherwise output wouldn't include version + fwrite($output, "OLD: " . $mapping->old->toVanillaNbt() . "\n"); + if(!$oldNbt->equals($mapping->new->toVanillaNbt())){ + fwrite($output, "NEW: " . $mapping->new->toVanillaNbt() . "\n"); + }else{ + fwrite($output, "NEW: version bump only (" . $mapping->new->getVersion() . ")\n"); + } + fwrite($output, "-----\n"); + } + } + + fclose($output); + \GlobalLogger::get()->info("Table dump file $outputFile generated successfully."); + return 0; +} + /** * @param string[] $argv */ @@ -893,7 +932,8 @@ function main(array $argv) : int{ "generate" => [["palette upgrade table file", "schema output file"], cmdGenerate(...)], "test" => [["palette upgrade table file", "schema output file"], cmdTest(...)], "update" => [["schema input file", "old palette file", "updated schema output file"], cmdUpdate(...)], - "update-all" => [["schema folder", "path to BlockPaletteArchive"], cmdUpdateAll(...)] + "update-all" => [["schema folder", "path to BlockPaletteArchive"], cmdUpdateAll(...)], + "dump-table" => [["palette upgrade table file", "txt output file"], cmdDumpTable(...)] ]; $selected = $argv[1] ?? null; From a08b06d3224215e001b54ff30f3017bfba0b1b81 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Feb 2025 15:34:20 +0000 Subject: [PATCH 2/2] also sort table by ID --- tools/blockstate-upgrade-schema-utils.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/blockstate-upgrade-schema-utils.php b/tools/blockstate-upgrade-schema-utils.php index 6bfe44a03..7c34b7728 100644 --- a/tools/blockstate-upgrade-schema-utils.php +++ b/tools/blockstate-upgrade-schema-utils.php @@ -901,6 +901,7 @@ function cmdDumpTable(array $argv) : int{ } $table = loadUpgradeTableFromFile($tableFile, reverse: false); + ksort($table, SORT_STRING); foreach(Utils::stringifyKeys($table) as $oldName => $mappings){ fwrite($output, "---------- MAPPING LIST: $oldName ----------\n");