mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 05:48:00 +01:00
Some minor optimisations when computing villager clothing
This commit is contained in:
parent
540f8b9f3f
commit
d73c6fb2e3
2 changed files with 16 additions and 29 deletions
|
@ -16,8 +16,7 @@ import com.minelittlepony.client.render.entity.PonyRenderer;
|
|||
import com.minelittlepony.client.render.entity.feature.*;
|
||||
import com.minelittlepony.client.render.entity.npc.textures.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
abstract class AbstractNpcRenderer<T extends MobEntity & VillagerDataContainer> extends PonyRenderer.Caster<T, ClientPonyModel<T>> {
|
||||
|
||||
|
@ -25,7 +24,7 @@ abstract class AbstractNpcRenderer<T extends MobEntity & VillagerDataContainer>
|
|||
|
||||
private final String entityType;
|
||||
|
||||
private final Map<Race, ModelWrapper<T, ClientPonyModel<T>>> models = new HashMap<>();
|
||||
private final Map<Race, ModelWrapper<T, ClientPonyModel<T>>> models = new EnumMap<>(Race.class);
|
||||
|
||||
private final NpcClothingFeature<T, ClientPonyModel<T>, AbstractNpcRenderer<T>> clothing;
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class NpcClothingFeature<
|
|||
a.put(4, new Identifier("emerald"));
|
||||
a.put(5, new Identifier("diamond"));
|
||||
});
|
||||
private final Set<Identifier> loadedTextures = new HashSet<>();
|
||||
|
||||
private final String entityType;
|
||||
|
||||
|
@ -45,27 +46,6 @@ class NpcClothingFeature<
|
|||
entityType = type;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static Identifier getClothingTexture(VillagerDataContainer entity, String entityType) {
|
||||
VillagerProfession profession = entity.getVillagerData().getProfession();
|
||||
|
||||
return createTexture("minelittlepony", entityType, "profession", Registries.VILLAGER_PROFESSION.getId(profession));
|
||||
}
|
||||
|
||||
public static Identifier createTexture(String namespace, String entityType, String category, Identifier profession) {
|
||||
return new Identifier(namespace, String.format("textures/entity/%s/%s/%s.png", entityType, category, profession.getPath()));
|
||||
}
|
||||
|
||||
public Identifier createTexture(VillagerDataContainer entity, String category) {
|
||||
VillagerProfession profession = entity.getVillagerData().getProfession();
|
||||
|
||||
return createTexture(category, Registries.VILLAGER_PROFESSION.getId(profession));
|
||||
}
|
||||
|
||||
public Identifier createTexture(String category, Identifier identifier) {
|
||||
return createTexture("minelittlepony", entityType, category, identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider provider, int i, T entity, float f, float g, float h, float j, float k, float l) {
|
||||
if (entity.isInvisible()) {
|
||||
|
@ -94,22 +74,30 @@ class NpcClothingFeature<
|
|||
|
||||
Identifier key = new Identifier("minelittlepony", (typeId + "/" + profId + "/" + level).replace(':', '_'));
|
||||
|
||||
if (MinecraftClient.getInstance().getTextureManager().getOrDefault(key, null) == null) {
|
||||
TextureFlattener.flatten(computeTextures(type, profession, typeId, profId, level), key);
|
||||
if (loadedTextures.add(key) && MinecraftClient.getInstance().getTextureManager().getOrDefault(key, null) == null) {
|
||||
TextureFlattener.flatten(computeTextures(typeId, profId, profession == VillagerProfession.NITWIT ? -1 : level), key);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
private List<Identifier> computeTextures(VillagerType type, VillagerProfession profession, Identifier typeId, Identifier profId, int level) {
|
||||
private List<Identifier> computeTextures(Identifier typeId, Identifier profId, int level) {
|
||||
List<Identifier> skins = new ArrayList<>();
|
||||
|
||||
skins.add(createTexture("type", typeId));
|
||||
skins.add(createTexture("profession", Registries.VILLAGER_PROFESSION.getId(profession)));
|
||||
if (profession != VillagerProfession.NITWIT) {
|
||||
skins.add(createTexture("profession", profId));
|
||||
if (level != -1) {
|
||||
skins.add(createTexture("profession_level", LEVEL_TO_ID.get(level)));
|
||||
}
|
||||
|
||||
return skins;
|
||||
}
|
||||
|
||||
public Identifier createTexture(VillagerDataContainer entity, String category) {
|
||||
return createTexture(category, Registries.VILLAGER_PROFESSION.getId(entity.getVillagerData().getProfession()));
|
||||
}
|
||||
|
||||
private Identifier createTexture(String category, Identifier identifier) {
|
||||
return new Identifier("minelittlepony", String.format("textures/entity/%s/%s/%s.png", entityType, category, identifier.getPath()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue