mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Zombie villagers neeed this too
This commit is contained in:
parent
fb013ea190
commit
283b7b56c7
4 changed files with 68 additions and 36 deletions
|
@ -2,12 +2,8 @@ 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 com.minelittlepony.util.render.ITextureSupplier;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -15,20 +11,18 @@ import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
||||||
|
|
||||||
private static final ResourceLocation[] PROFESSIONS = {
|
private static final ITextureSupplier<Integer> PROFESSIONS = new VillagerProfessionTextureCache(
|
||||||
|
"textures/entity/villager/%d_pony.png",
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/farmer_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/villager/farmer_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/librarian_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/villager/librarian_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/priest_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/villager/priest_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/smith_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/villager/smith_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/butcher_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/villager/butcher_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/villager/villager_pony.png")
|
new ResourceLocation("minelittlepony", "textures/entity/villager/villager_pony.png")
|
||||||
};
|
);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -41,18 +35,6 @@ 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;
|
||||||
|
@ -60,16 +42,6 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
|
||||||
return EGG;
|
return EGG;
|
||||||
}
|
}
|
||||||
|
|
||||||
int profession = entity.getProfession();
|
return PROFESSIONS.supplyTexture(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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ 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 com.minelittlepony.util.render.ITextureSupplier;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
import net.minecraft.entity.monster.EntityZombieVillager;
|
import net.minecraft.entity.monster.EntityZombieVillager;
|
||||||
|
@ -9,14 +10,15 @@ import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class RenderPonyZombieVillager extends RenderPonyMob<EntityZombieVillager> {
|
public class RenderPonyZombieVillager extends RenderPonyMob<EntityZombieVillager> {
|
||||||
|
|
||||||
private static final ResourceLocation[] PROFESSIONS = {
|
private static final ITextureSupplier<Integer> PROFESSIONS = new VillagerProfessionTextureCache(
|
||||||
|
"textures/entity/zombie_villager/zombie_%d_pony.png",
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_farmer_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_farmer_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_librarian_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_librarian_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_priest_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_priest_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_smith_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_smith_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_butcher_pony.png"),
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_butcher_pony.png"),
|
||||||
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_villager_pony.png")
|
new ResourceLocation("minelittlepony", "textures/entity/zombie_villager/zombie_villager_pony.png")
|
||||||
};
|
);
|
||||||
|
|
||||||
public RenderPonyZombieVillager(RenderManager manager) {
|
public RenderPonyZombieVillager(RenderManager manager) {
|
||||||
super(manager, PMAPI.villager);
|
super(manager, PMAPI.villager);
|
||||||
|
@ -24,7 +26,7 @@ public class RenderPonyZombieVillager extends RenderPonyMob<EntityZombieVillager
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResourceLocation getTexture(EntityZombieVillager entity) {
|
protected ResourceLocation getTexture(EntityZombieVillager entity) {
|
||||||
return PROFESSIONS[entity.getProfession() % PROFESSIONS.length];
|
return PROFESSIONS.supplyTexture(entity.getProfession());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.minelittlepony.render.ponies;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import com.minelittlepony.util.render.ITextureSupplier;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
class VillagerProfessionTextureCache implements ITextureSupplier<Integer> {
|
||||||
|
|
||||||
|
private final ResourceLocation[] pool;
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
private final Map<Integer, ResourceLocation> cache = new HashMap<>();
|
||||||
|
|
||||||
|
public VillagerProfessionTextureCache(String path, ResourceLocation... pool) {
|
||||||
|
this.path = path;
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceLocation supplyTexture(Integer profession) {
|
||||||
|
ResourceLocation texture = getVillagerTexture(profession);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Minecraft.getMinecraft().getResourceManager().getResource(texture);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return pool[5];
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceLocation getVillagerTexture(int profession) {
|
||||||
|
if (profession >= pool.length) {
|
||||||
|
return cache.computeIfAbsent(profession, this::getModProfessionResource);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pool[profession];
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceLocation getModProfessionResource(int professionId) {
|
||||||
|
return new ResourceLocation("minelittlepony", String.format(path, professionId));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.minelittlepony.util.render;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A texture pool for generating multiple associated textures.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface ITextureSupplier<T> {
|
||||||
|
ResourceLocation supplyTexture(T key);
|
||||||
|
}
|
Loading…
Reference in a new issue