mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Try to handle unknown villager professions. If this works correctly skins not present should become the generic villager pony
This commit is contained in:
parent
585912cdfa
commit
005f5c0f45
1 changed files with 32 additions and 1 deletions
|
@ -3,6 +3,11 @@ package com.minelittlepony.render.ponies;
|
||||||
import com.minelittlepony.model.PMAPI;
|
import com.minelittlepony.model.PMAPI;
|
||||||
import com.minelittlepony.render.RenderPonyMob;
|
import com.minelittlepony.render.RenderPonyMob;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
import net.minecraft.entity.passive.EntityVillager;
|
import net.minecraft.entity.passive.EntityVillager;
|
||||||
|
@ -21,6 +26,9 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
||||||
private static final ResourceLocation EGG = new ResourceLocation("minelittlepony", "textures/entity/villager/silly_pony.png");
|
private static final ResourceLocation EGG = new ResourceLocation("minelittlepony", "textures/entity/villager/silly_pony.png");
|
||||||
private static final ResourceLocation EGG_2 = new ResourceLocation("minelittlepony", "textures/entity/villager/tiny_silly_pony.png");
|
private static final ResourceLocation EGG_2 = new ResourceLocation("minelittlepony", "textures/entity/villager/tiny_silly_pony.png");
|
||||||
|
|
||||||
|
|
||||||
|
private static final Map<Integer, ResourceLocation> MOD_PROFESSIONS = new HashMap<>();
|
||||||
|
|
||||||
public RenderPonyVillager(RenderManager manager) {
|
public RenderPonyVillager(RenderManager manager) {
|
||||||
super(manager, PMAPI.villager);
|
super(manager, PMAPI.villager);
|
||||||
}
|
}
|
||||||
|
@ -33,12 +41,35 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getTexture(EntityVillager entity) {
|
protected ResourceLocation getTexture(EntityVillager entity) {
|
||||||
|
ResourceLocation texture = getVillagerTexture(entity);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Minecraft.getMinecraft().getResourceManager().getResource(texture);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return PROFESSIONS[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceLocation getVillagerTexture(EntityVillager entity) {
|
||||||
if ("Derpy".equals(entity.getCustomNameTag())) {
|
if ("Derpy".equals(entity.getCustomNameTag())) {
|
||||||
if (entity.isChild()) {
|
if (entity.isChild()) {
|
||||||
return EGG_2;
|
return EGG_2;
|
||||||
}
|
}
|
||||||
return EGG;
|
return EGG;
|
||||||
}
|
}
|
||||||
return PROFESSIONS[entity.getProfession() % PROFESSIONS.length];
|
|
||||||
|
int profession = entity.getProfession();
|
||||||
|
|
||||||
|
if (profession >= PROFESSIONS.length) {
|
||||||
|
return MOD_PROFESSIONS.computeIfAbsent(profession, this::getModProfessionResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PROFESSIONS[profession];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ResourceLocation getModProfessionResource(int professionId) {
|
||||||
|
return new ResourceLocation("minelittlepony", String.format("textures/entity/villager/%d_pony.png", professionId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue