Skip to content

Commit

Permalink
Skip invalid translation keys instead of disabling resourcepack (#178)
Browse files Browse the repository at this point in the history
* Skip invalid translation keys instead of crashing the game
Closes #177

* Fix import order
  • Loading branch information
thecatcore authored Jul 31, 2024
1 parent 110dc1f commit 6a75296
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class ResourceManagerHelperImpl implements ResourceManagerHelper {
private static final ResourceManagerHelperImpl INSTANCE = new ResourceManagerHelperImpl();
private static final Logger LOGGER = Logger.get(LoggerImpl.API, "ResourceManagerHelperImpl");
public static final Logger LOGGER = Logger.get(LoggerImpl.API, "ResourceManagerHelperImpl");

private final Set<Identifier> addedListenerIds = new HashSet<>();
private final Set<IdentifiableResourceReloadListener> addedListeners = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.minecraft.util.Identifier;

import net.legacyfabric.fabric.api.util.VersionUtils;
import net.legacyfabric.fabric.impl.resource.loader.ResourceManagerHelperImpl;

@Mixin(TranslationStorage.class)
public abstract class TranslationStorageMixin {
Expand Down Expand Up @@ -148,7 +149,13 @@ private void recursiveLoadTranslations(@NotNull String currentKey, JsonObject ob
key = entry.getKey();
}

this.translations.put(key, TOKEN_PATTERN.matcher(entry.getValue().getAsString()).replaceAll("%$1s"));
JsonElement value = entry.getValue();

if (value.isJsonPrimitive()) {
this.translations.put(key, TOKEN_PATTERN.matcher(value.getAsString()).replaceAll("%$1s"));
} else {
ResourceManagerHelperImpl.LOGGER.warn("Skipping translation key \"" + key + "\" with unsupported format " + value);
}
}
}
}
Expand Down

0 comments on commit 6a75296

Please sign in to comment.