Rewrote villager textures handling
|
@ -0,0 +1,17 @@
|
||||||
|
package com.minelittlepony.client.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||||
|
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mixin(BlockEntityRenderDispatcher.class)
|
||||||
|
public interface MixinBlockEntityRenderDispatcher {
|
||||||
|
|
||||||
|
@Accessor("renderers")
|
||||||
|
Map<Class<? extends BlockEntity>, BlockEntityRenderer<? extends BlockEntity>> getRenderers();
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.minelittlepony.client.model.entities;
|
package com.minelittlepony.client.model.entities;
|
||||||
|
|
||||||
|
import net.minecraft.client.render.entity.model.ModelWithHat;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.village.VillagerDataContainer;
|
import net.minecraft.village.VillagerDataContainer;
|
||||||
import net.minecraft.village.VillagerProfession;
|
import net.minecraft.village.VillagerProfession;
|
||||||
|
@ -8,7 +9,7 @@ import com.minelittlepony.client.model.ModelMobPony;
|
||||||
import com.minelittlepony.client.util.render.plane.PlaneRenderer;
|
import com.minelittlepony.client.util.render.plane.PlaneRenderer;
|
||||||
import com.minelittlepony.pony.meta.Wearable;
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
|
|
||||||
public class ModelVillagerPony<T extends LivingEntity & VillagerDataContainer> extends ModelMobPony<T> {
|
public class ModelVillagerPony<T extends LivingEntity & VillagerDataContainer> extends ModelMobPony<T> implements ModelWithHat {
|
||||||
|
|
||||||
public PlaneRenderer apron;
|
public PlaneRenderer apron;
|
||||||
public PlaneRenderer trinket;
|
public PlaneRenderer trinket;
|
||||||
|
@ -76,4 +77,9 @@ public class ModelVillagerPony<T extends LivingEntity & VillagerDataContainer> e
|
||||||
.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z)
|
.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z)
|
||||||
.south(-2, -4, -9, 4, 5, stretch);
|
.south(-2, -4, -9, 4, 5, stretch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHatVisible(boolean visible) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,25 +5,40 @@ import com.minelittlepony.util.resources.FormattedTextureSupplier;
|
||||||
import com.minelittlepony.util.resources.ITextureSupplier;
|
import com.minelittlepony.util.resources.ITextureSupplier;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||||
|
import net.minecraft.client.render.entity.feature.VillagerClothingFeatureRenderer;
|
||||||
import net.minecraft.entity.passive.VillagerEntity;
|
import net.minecraft.entity.passive.VillagerEntity;
|
||||||
|
import net.minecraft.resource.ReloadableResourceManager;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.village.VillagerData;
|
|
||||||
|
|
||||||
public class RenderPonyVillager extends RenderPonyMob.Caster<VillagerEntity, ModelVillagerPony<VillagerEntity>> {
|
public class RenderPonyVillager extends RenderPonyMob.Caster<VillagerEntity, ModelVillagerPony<VillagerEntity>> {
|
||||||
|
|
||||||
private static final ITextureSupplier<String> FORMATTER = new FormattedTextureSupplier("minelittlepony", "textures/entity/villager/%s_pony.png");
|
private static final ITextureSupplier<String> FORMATTER = new FormattedTextureSupplier("minelittlepony", "textures/entity/villager/%s.png");
|
||||||
|
|
||||||
private static final Identifier DEFAULT = FORMATTER.supplyTexture("villager");
|
private static final ITextureSupplier<VillagerEntity> PROFESSIONS = new VillagerProfessionTextureCache<>(FORMATTER);
|
||||||
private static final Identifier EGG = FORMATTER.supplyTexture("silly");
|
|
||||||
private static final Identifier EGG_2 = FORMATTER.supplyTexture("tiny_silly");
|
|
||||||
|
|
||||||
private static final ITextureSupplier<VillagerData> PROFESSIONS = new VillagerProfessionTextureCache(FORMATTER, DEFAULT);
|
|
||||||
|
|
||||||
public RenderPonyVillager(EntityRenderDispatcher manager) {
|
public RenderPonyVillager(EntityRenderDispatcher manager) {
|
||||||
super(manager, new ModelVillagerPony<>());
|
super(manager, new ModelVillagerPony<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addLayers() {
|
||||||
|
ReloadableResourceManager resManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
|
||||||
|
|
||||||
|
addFeature(new VillagerClothingFeatureRenderer<>(this, resManager, "villager"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindTexture(Identifier texture) {
|
||||||
|
|
||||||
|
if (!"minelittlepony".contentEquals(texture.getNamespace())) {
|
||||||
|
texture = new Identifier("minelittlepony", texture.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
super.bindTexture(texture);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scale(VillagerEntity villager, float ticks) {
|
public void scale(VillagerEntity villager, float ticks) {
|
||||||
super.scale(villager, ticks);
|
super.scale(villager, ticks);
|
||||||
|
@ -32,16 +47,6 @@ public class RenderPonyVillager extends RenderPonyMob.Caster<VillagerEntity, Mod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier findTexture(VillagerEntity entity) {
|
public Identifier findTexture(VillagerEntity entity) {
|
||||||
if (entity.hasCustomName()) {
|
return PROFESSIONS.supplyTexture(entity);
|
||||||
String name = entity.getCustomName().getString();
|
|
||||||
if ("Derpy".equals(name) || (entity.isBaby() && "Dinky".equals(name))) {
|
|
||||||
if (entity.isBaby()) {
|
|
||||||
return EGG_2;
|
|
||||||
}
|
|
||||||
return EGG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PROFESSIONS.supplyTexture(entity.getVillagerData());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,38 +4,44 @@ import com.minelittlepony.client.model.entities.ModelZombieVillagerPony;
|
||||||
import com.minelittlepony.util.resources.FormattedTextureSupplier;
|
import com.minelittlepony.util.resources.FormattedTextureSupplier;
|
||||||
import com.minelittlepony.util.resources.ITextureSupplier;
|
import com.minelittlepony.util.resources.ITextureSupplier;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||||
|
import net.minecraft.client.render.entity.feature.VillagerClothingFeatureRenderer;
|
||||||
import net.minecraft.entity.mob.ZombieVillagerEntity;
|
import net.minecraft.entity.mob.ZombieVillagerEntity;
|
||||||
|
import net.minecraft.resource.ReloadableResourceManager;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.village.VillagerData;
|
|
||||||
|
|
||||||
public class RenderPonyZombieVillager extends RenderPonyMob.Caster<ZombieVillagerEntity, ModelZombieVillagerPony> {
|
public class RenderPonyZombieVillager extends RenderPonyMob.Caster<ZombieVillagerEntity, ModelZombieVillagerPony> {
|
||||||
|
|
||||||
private static final ITextureSupplier<String> FORMATTER = new FormattedTextureSupplier("minelittlepony", "textures/entity/zombie_villager/zombie_%s_pony.png");
|
private static final ITextureSupplier<String> FORMATTER = new FormattedTextureSupplier("minelittlepony", "textures/entity/zombie_villager/zombie_%s.png");
|
||||||
|
|
||||||
private static final Identifier DEFAULT = FORMATTER.supplyTexture("villager");
|
private static final ITextureSupplier<ZombieVillagerEntity> PROFESSIONS = new VillagerProfessionTextureCache<>(FORMATTER);
|
||||||
private static final Identifier EGG = FORMATTER.supplyTexture("silly");
|
|
||||||
private static final Identifier EGG_2 = FORMATTER.supplyTexture("tiny_silly");
|
|
||||||
|
|
||||||
private static final ITextureSupplier<VillagerData> PROFESSIONS = new VillagerProfessionTextureCache(FORMATTER, DEFAULT);
|
|
||||||
|
|
||||||
public RenderPonyZombieVillager(EntityRenderDispatcher manager) {
|
public RenderPonyZombieVillager(EntityRenderDispatcher manager) {
|
||||||
super(manager, new ModelZombieVillagerPony());
|
super(manager, new ModelZombieVillagerPony());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier findTexture(ZombieVillagerEntity entity) {
|
protected void addLayers() {
|
||||||
if (entity.hasCustomName()) {
|
ReloadableResourceManager resManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
|
||||||
String name = entity.getCustomName().getString();
|
|
||||||
if ("Derpy".equals(name) || (entity.isBaby() && "Dinky".equals(name))) {
|
addFeature(new VillagerClothingFeatureRenderer<>(this, resManager, "zombie_villager"));
|
||||||
if (entity.isBaby()) {
|
}
|
||||||
return EGG_2;
|
|
||||||
}
|
@Override
|
||||||
return EGG;
|
public void bindTexture(Identifier texture) {
|
||||||
}
|
|
||||||
|
if (!"minelittlepony".contentEquals(texture.getNamespace())) {
|
||||||
|
texture = new Identifier("minelittlepony", texture.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return PROFESSIONS.supplyTexture(entity.getVillagerData());
|
super.bindTexture(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identifier findTexture(ZombieVillagerEntity entity) {
|
||||||
|
return PROFESSIONS.supplyTexture(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
package com.minelittlepony.client.render.entities;
|
package com.minelittlepony.client.render.entities;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.village.VillagerData;
|
import net.minecraft.village.VillagerData;
|
||||||
|
import net.minecraft.village.VillagerDataContainer;
|
||||||
|
import net.minecraft.village.VillagerProfession;
|
||||||
|
import net.minecraft.village.VillagerType;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.util.resources.ITextureSupplier;
|
import com.minelittlepony.util.resources.ITextureSupplier;
|
||||||
import com.minelittlepony.util.resources.ProfessionStringMapper;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached pool of villager textures.
|
* Cached pool of villager textures.
|
||||||
*/
|
*/
|
||||||
class VillagerProfessionTextureCache implements ITextureSupplier<VillagerData> {
|
class VillagerProfessionTextureCache<T extends LivingEntity & VillagerDataContainer> implements ITextureSupplier<T> {
|
||||||
|
|
||||||
private final ITextureSupplier<String> formatter;
|
private final ITextureSupplier<String> formatter;
|
||||||
|
|
||||||
private final Function<VillagerData, String> keyMapper = new ProfessionStringMapper();
|
|
||||||
|
|
||||||
private final Identifier fallback;
|
private final Identifier fallback;
|
||||||
|
|
||||||
private final Map<String, Identifier> cache = new HashMap<>();
|
private final Map<String, Identifier> cache = new HashMap<>();
|
||||||
|
|
||||||
|
private final Identifier egg;
|
||||||
|
private final Identifier egg2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new profession cache
|
* Creates a new profession cache
|
||||||
*
|
*
|
||||||
|
@ -33,17 +36,41 @@ class VillagerProfessionTextureCache implements ITextureSupplier<VillagerData> {
|
||||||
* @param keyMapper Mapper to convert integer ids into a string value for format insertion
|
* @param keyMapper Mapper to convert integer ids into a string value for format insertion
|
||||||
* @param fallback The default if any generated textures fail to load. This is stored in place of failing textures.
|
* @param fallback The default if any generated textures fail to load. This is stored in place of failing textures.
|
||||||
*/
|
*/
|
||||||
public VillagerProfessionTextureCache(ITextureSupplier<String> formatter, Identifier fallback) {
|
public VillagerProfessionTextureCache(ITextureSupplier<String> formatter) {
|
||||||
this.formatter = formatter;
|
this.formatter = formatter;
|
||||||
this.fallback = fallback;
|
this.fallback = formatter.supplyTexture("villager_pony");
|
||||||
|
this.egg = formatter.supplyTexture("silly_pony");
|
||||||
|
this.egg2 = formatter.supplyTexture("tiny_silly_pony");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier supplyTexture(VillagerData data) {
|
public Identifier supplyTexture(T entity) {
|
||||||
return cache.computeIfAbsent(keyMapper.apply(data), this::getModProfessionResource);
|
if (entity.hasCustomName()) {
|
||||||
|
String name = entity.getCustomName().getString();
|
||||||
|
if ("Derpy".equals(name) || (entity.isBaby() && "Dinky".equals(name))) {
|
||||||
|
if (entity.isBaby()) {
|
||||||
|
return egg2;
|
||||||
|
}
|
||||||
|
return egg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.getVillagerData().getProfession() == VillagerProfession.NONE) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache.computeIfAbsent(formatTexture(entity), this::getTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Identifier getModProfessionResource(String professionId) {
|
public String formatTexture(T entity) {
|
||||||
|
VillagerData t = entity.getVillagerData();
|
||||||
|
VillagerType type = t.getType();
|
||||||
|
VillagerProfession profession = t.getProfession();
|
||||||
|
|
||||||
|
return String.format("pony/%s/%s", type, profession.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Identifier getTexture(String professionId) {
|
||||||
Identifier generated = formatter.supplyTexture(professionId);
|
Identifier generated = formatter.supplyTexture(professionId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.minelittlepony.util.resources;
|
|
||||||
|
|
||||||
import net.minecraft.village.VillagerData;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ProfessionStringMapper implements Function<VillagerData, String> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String apply(VillagerData t) {
|
|
||||||
return String.format("level_%d_%s", t.getLevel(), t.getProfession().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 793 B |
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 932 B |
After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 670 B |
After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 4 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 4 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 191 B |
After Width: | Height: | Size: 184 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 134 B |
After Width: | Height: | Size: 5 KiB |
After Width: | Height: | Size: 4 KiB |
After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 4.7 KiB |