mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 04:27:59 +01:00
Be a little more untrusting of values we get from outside. Fixes #175
This commit is contained in:
parent
5b20402f3f
commit
3cfacb1e7b
4 changed files with 32 additions and 9 deletions
|
@ -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<T extends LivingEntity> 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);
|
||||
|
|
|
@ -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<T extends LivingEntity & VillagerDataContainer> 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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
17
src/main/java/com/minelittlepony/util/ResourceUtil.java
Normal file
17
src/main/java/com/minelittlepony/util/ResourceUtil.java
Normal file
|
@ -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_.-]", "_");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue