diff --git a/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java b/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java index 62fdb844..b5cdf426 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java +++ b/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java @@ -12,6 +12,7 @@ import com.google.common.base.Strings; import com.minelittlepony.model.armour.ArmourLayer; import com.minelittlepony.model.armour.ArmourVariant; import com.minelittlepony.model.armour.IArmourTextureResolver; +import com.minelittlepony.util.ResourceUtil; import javax.annotation.Nullable; @@ -40,10 +41,10 @@ public class DefaultArmourTextureResolver implements IAr texture = texture.substring(idx + 1); } - String customType = type.isEmpty() ? "" : String.format("_%s", type); + String customType = type.isEmpty() ? "" : "_" + type; - String res = String.format("%s:textures/models/armor/%s_layer_%s%s.png", domain, texture, layer.name().toLowerCase(), customType); - String oldRes = String.format("%s:textures/models/armor/%s_layer_%d%s.png", domain, texture, layer == ArmourLayer.INNER ? 2 : 1, customType); + String res = ResourceUtil.format("%s:textures/models/armor/%s_layer_%s%s.png", domain, texture, layer, customType); + String oldRes = ResourceUtil.format("%s:textures/models/armor/%s_layer_%d%s.png", domain, texture, layer.getLegacyId(), customType); Identifier human = getArmorTexture(res, type); Identifier pony = ponifyResource(human); diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/PonyTextures.java b/src/main/java/com/minelittlepony/client/render/entity/npc/PonyTextures.java index 91d10654..564a6c6d 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/PonyTextures.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/PonyTextures.java @@ -10,6 +10,7 @@ import net.minecraft.village.VillagerProfession; import net.minecraft.village.VillagerType; import com.minelittlepony.client.MineLittlePony; +import com.minelittlepony.util.ResourceUtil; import java.util.HashMap; import java.util.Map; @@ -62,7 +63,7 @@ public class PonyTextures implem return fallback; } - String key = String.format("pony/%s/%s", type, profession); + String key = ResourceUtil.format("pony/%s/%s", type, profession); if (cache.containsKey(key)) { return cache.get(key); // People often complain that villagers cause lag, diff --git a/src/main/java/com/minelittlepony/model/armour/ArmourLayer.java b/src/main/java/com/minelittlepony/model/armour/ArmourLayer.java index c12457d4..11d34cd6 100644 --- a/src/main/java/com/minelittlepony/model/armour/ArmourLayer.java +++ b/src/main/java/com/minelittlepony/model/armour/ArmourLayer.java @@ -4,12 +4,16 @@ package com.minelittlepony.model.armour; * The layer used to render a given armour piece. */ public enum ArmourLayer { - /** - * Fits snugly to the player's model. - */ - INNER, /** * Hanging loose and sagging free */ - OUTER + OUTER, + /** + * Fits snugly to the player's model. + */ + INNER; + + public int getLegacyId() { + return ordinal() + 1; + } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/util/ResourceUtil.java b/src/main/java/com/minelittlepony/util/ResourceUtil.java new file mode 100644 index 00000000..dbcc383b --- /dev/null +++ b/src/main/java/com/minelittlepony/util/ResourceUtil.java @@ -0,0 +1,17 @@ +package com.minelittlepony.util; + +public final class ResourceUtil { + + public static String format(String template, Object... args) { + for (int i = 0; i < args.length; i++) { + if (!(args[i] instanceof Number)) { + args[i] = toPathComponent(args[i]); + } + } + return String.format(template, args); + } + + private static String toPathComponent(Object value) { + return value.toString().toLowerCase().replaceAll("[^a-z0-9_.-]", "_"); + } +}