Skip to content

Commit

Permalink
Fix incorrect tag warnings, and add fail option.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jun 10, 2024
1 parent 0dcf6c8 commit 5a42e9b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ loom {
inherit testmodClient
name "Auto Test Client"
vmArg "-Dfabric.autoTest"
vmArg "-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail"
vmArg "-Dfabric-tag-conventions-v1.legacyTagWarning=fail"
}

// Create duplicate tasks for this, as jacoco slows things down a bit
Expand Down Expand Up @@ -525,6 +527,8 @@ tasks.register('runProductionAutoTestClient', JavaExec) {
jvmArgs(
"-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}",
"-Dfabric.autoTest",
"-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail",
"-Dfabric-tag-conventions-v1.legacyTagWarning=fail"
)
jvmArgs(debugArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
Expand All @@ -49,7 +48,7 @@ public class ConventionLogWarnings implements ModInitializer {
private static final LogWarningMode LOG_LEGACY_WARNING_MODE = setupLogWarningModeProperty();

private static LogWarningMode setupLogWarningModeProperty() {
String property = System.getProperty("fabric-tag-conventions-v1.legacyTagWarning", LogWarningMode.DEV_SHORT.name()).toUpperCase(Locale.ROOT);
String property = System.getProperty("fabric-tag-conventions-v1.legacyTagWarning", LogWarningMode.SHORT.name()).toUpperCase(Locale.ROOT);

try {
return LogWarningMode.valueOf(property);
Expand All @@ -61,8 +60,13 @@ private static LogWarningMode setupLogWarningModeProperty() {

private enum LogWarningMode {
SILENCED,
DEV_SHORT,
DEV_VERBOSE
SHORT,
VERBOSE,
FAIL;

boolean isVerbose() {
return this == VERBOSE || this == FAIL;
}
}

/**
Expand Down Expand Up @@ -211,25 +215,7 @@ private enum LogWarningMode {
createMapEntry(RegistryKeys.ITEM, "stews", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.SOUPS_FOODS),
createMapEntry(RegistryKeys.ITEM, "candy", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.CANDIES_FOODS),
createMapEntry(RegistryKeys.ITEM, "candies", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.CANDIES_FOODS),
createMapEntry(TagKey.of(RegistryKeys.ITEM, Identifier.of("minecraft", "music_discs")), net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.MUSIC_DISCS),

// V2 tags that are now discouraged
createMapEntry(ConventionalItemTags.COAL, ItemTags.COALS),
createMapEntry(RegistryKeys.ITEM, "tools/shears", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.SHEAR_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/spears", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.SPEAR_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/bows", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.BOW_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/crossbows", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.CROSSBOW_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/shields", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.SHIELD_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/fishing_rods", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.FISHING_ROD_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/brushes", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.BRUSH_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/melee_weapons", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.MELEE_WEAPON_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/ranged_weapons", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.RANGED_WEAPON_TOOLS),
createMapEntry(RegistryKeys.ITEM, "tools/mining_tools", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.MINING_TOOL_TOOLS),
createMapEntry(RegistryKeys.ITEM, "raw_blocks", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.STORAGE_BLOCKS),
createMapEntry(RegistryKeys.ITEM, "raw_blocks/copper", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.STORAGE_BLOCKS_RAW_COPPER),
createMapEntry(RegistryKeys.ITEM, "raw_blocks/gold", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.STORAGE_BLOCKS_RAW_GOLD),
createMapEntry(RegistryKeys.ITEM, "raw_blocks/iron", net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.STORAGE_BLOCKS_RAW_IRON),
createMapEntry(net.fabricmc.fabric.api.tag.convention.v2.ConventionalBlockTags.SHULKER_BOXES, BlockTags.SHULKER_BOXES)
createMapEntry(TagKey.of(RegistryKeys.ITEM, Identifier.of("minecraft", "music_discs")), net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags.MUSIC_DISCS)
);

@Override
Expand Down Expand Up @@ -273,9 +259,7 @@ private static void setupLegacyTagWarning() {
""");

// Print out all legacy tags when desired.
boolean isConfigSetToVerbose = LOG_LEGACY_WARNING_MODE == LogWarningMode.DEV_VERBOSE;

if (isConfigSetToVerbose) {
if (LOG_LEGACY_WARNING_MODE.isVerbose()) {
stringBuilder.append("\nLegacy tags and their replacement:");

for (TagKey<?> tagKey : legacyTags) {
Expand All @@ -284,6 +268,10 @@ private static void setupLegacyTagWarning() {
}

LOGGER.warn(stringBuilder.toString());

if (LOG_LEGACY_WARNING_MODE == LogWarningMode.FAIL) {
throw new RuntimeException("Legacy Tag validation failed");
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, T
translationBuilder.add(ConventionalItemTags.PLAYER_WORKSTATIONS_CRAFTING_TABLES, "Crafting Tables");
translationBuilder.add(ConventionalItemTags.PLAYER_WORKSTATIONS_FURNACES, "Furnaces");
translationBuilder.add(ConventionalItemTags.STRINGS, "Strings");
translationBuilder.add(ConventionalItemTags.LEATHERS, "Leathers");
translationBuilder.add(ConventionalItemTags.MUSIC_DISCS, "Music Discs");
translationBuilder.add(ConventionalItemTags.RODS, "Rods");
translationBuilder.add(ConventionalItemTags.WOODEN_RODS, "Wooden Rods");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"tag.item.c.ingots.gold": "Gold Ingots",
"tag.item.c.ingots.iron": "Iron Ingots",
"tag.item.c.ingots.netherite": "Netherite Ingots",
"tag.item.c.leathers": "Leathers",
"tag.item.c.music_discs": "Music Discs",
"tag.item.c.nuggets": "Nuggets",
"tag.item.c.ores": "Ores",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ private static LogWarningMode setupLogWarningModeProperty() {
private enum LogWarningMode {
SILENCED,
SHORT,
VERBOSE
VERBOSE,
FAIL;

boolean verbose() {
return this == VERBOSE || this == FAIL;
}
}

public void onInitialize() {
Expand Down Expand Up @@ -99,9 +104,7 @@ private static void setupUntranslatedItemTagWarning() {
""");

// Print out all untranslated tags when desired.
boolean isConfigSetToVerbose = LOG_UNTRANSLATED_WARNING_MODE == LogWarningMode.VERBOSE;

if (isConfigSetToVerbose) {
if (LOG_UNTRANSLATED_WARNING_MODE.verbose()) {
stringBuilder.append("\nUntranslated item tags:");

for (TagKey<Item> tagKey : untranslatedItemTags) {
Expand All @@ -110,6 +113,10 @@ private static void setupUntranslatedItemTagWarning() {
}

LOGGER.warn(stringBuilder.toString());

if (LOG_UNTRANSLATED_WARNING_MODE == LogWarningMode.FAIL) {
throw new RuntimeException("Tag translation validation failed");
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tag.item.fabric-resource-conditions-api-v1-testmod.test_condition": "Test Condition"
}

0 comments on commit 5a42e9b

Please sign in to comment.