tools/generate-bedrock-data-from-packets: make duplicate reporting less spammy

This commit is contained in:
Dylan K. Taylor 2023-09-01 20:51:45 +01:00
parent 4cc858829f
commit 540f088eda
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -440,17 +440,22 @@ class ParserPacketHandler extends PacketHandler{
//how the data is ordered doesn't matter as long as it's reproducible //how the data is ordered doesn't matter as long as it's reproducible
foreach($recipes as $_type => $entries){ foreach($recipes as $_type => $entries){
$_sortedRecipes = []; $_sortedRecipes = [];
$_seen = [];
foreach($entries as $entry){ foreach($entries as $entry){
$entry = self::sort($entry); $entry = self::sort($entry);
$_key = json_encode($entry); $_key = json_encode($entry);
while(isset($_sortedRecipes[$_key])){ $duplicates = $_seen[$_key] ??= 0;
echo "warning: duplicated $_type recipe: $_key\n"; $_seen[$_key]++;
$_key .= "a"; $suffix = chr(ord("a") + $duplicates);
} $_sortedRecipes[$_key . $suffix] = $entry;
$_sortedRecipes[$_key] = $entry;
} }
ksort($_sortedRecipes, SORT_STRING); ksort($_sortedRecipes, SORT_STRING);
$recipes[$_type] = array_values($_sortedRecipes); $recipes[$_type] = array_values($_sortedRecipes);
foreach($_seen as $_key => $_seenCount){
if($_seenCount > 1){
fwrite(STDERR, "warning: $_type recipe $_key was seen $_seenCount times\n");
}
}
} }
ksort($recipes, SORT_STRING); ksort($recipes, SORT_STRING);