Skip to content

Commit

Permalink
common: Sanitize enum names for things we turn into a registry (#3656)
Browse files Browse the repository at this point in the history
This resolves issues where mods add enum entries with names that are not valid resource locations
  • Loading branch information
zml2008 authored May 28, 2022
1 parent e832fda commit 453c7f5
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void loadEnumRegistries() {
this.knownName(RegistryTypes.BANNER_PATTERN_SHAPE, BannerPattern.values(), b -> ((BannerPatternAccessor) (Object) b).accessor$filename());
this.automaticName(RegistryTypes.TROPICAL_FISH_SHAPE, TropicalFish.Pattern.values());
this.automaticName(RegistryTypes.HEIGHT_TYPE, Heightmap.Types.values());
this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), MobCategory::getName);
this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), VanillaRegistryLoader.sanitizedName(MobCategory::getName));
}

private static RegistryLoader<Criterion> criterion() {
Expand Down Expand Up @@ -293,7 +293,7 @@ private static RegistryLoader<Trigger<?>> trigger() {

@SuppressWarnings("UnusedReturnValue")
private <A, I extends Enum<I>> Registry<A> automaticName(final RegistryType<A> type, final I[] values) {
return this.naming(type, values, value -> value.name().toLowerCase(Locale.ROOT));
return this.naming(type, values, VanillaRegistryLoader.sanitizedName(Enum::name));
}

@SuppressWarnings("UnusedReturnValue")
Expand Down Expand Up @@ -363,4 +363,8 @@ private <A, I> Registry<A> naming(final RegistryType<A> type, final int values,
private interface Manual<A, I> {
void put(final I value, final String key);
}

private static <I> Function<I, String> sanitizedName(final Function<I, String> original) {
return original.andThen(s -> s.toLowerCase(Locale.ROOT));
}
}

0 comments on commit 453c7f5

Please sign in to comment.