mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Clear the villager base textures when reloading
This commit is contained in:
parent
3593bf672b
commit
3edf26b1f5
2 changed files with 18 additions and 5 deletions
|
@ -19,7 +19,7 @@ abstract class AbstractVillagerRenderer<
|
|||
T extends MobEntity & VillagerDataContainer,
|
||||
M extends ClientPonyModel<T> & IUnicorn<PonyRenderer> & ModelWithHat> extends RenderPonyMob.Caster<T, M> {
|
||||
|
||||
private final ITextureSupplier<T> professions;
|
||||
private final ITextureSupplier<T> baseTextures;
|
||||
|
||||
private final String entityType;
|
||||
|
||||
|
@ -27,7 +27,7 @@ abstract class AbstractVillagerRenderer<
|
|||
super(manager, model);
|
||||
|
||||
entityType = type;
|
||||
professions = new PonyTextures<>(formatter);
|
||||
baseTextures = new PonyTextures<>(formatter);
|
||||
addFeature(new ClothingLayer<>(this, entityType));
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,6 @@ abstract class AbstractVillagerRenderer<
|
|||
|
||||
@Override
|
||||
public Identifier findTexture(T villager) {
|
||||
return professions.supplyTexture(villager);
|
||||
return baseTextures.supplyTexture(villager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.minelittlepony.client.render.entities.villager;
|
|||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.SynchronousResourceReloadListener;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.village.VillagerData;
|
||||
import net.minecraft.village.VillagerDataContainer;
|
||||
|
@ -18,7 +21,7 @@ import java.util.Optional;
|
|||
/**
|
||||
* Cached pool of villager textures.
|
||||
*/
|
||||
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements ITextureSupplier<T> {
|
||||
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements ITextureSupplier<T>, SynchronousResourceReloadListener {
|
||||
|
||||
private final ITextureSupplier<String> formatter;
|
||||
|
||||
|
@ -29,6 +32,8 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
|||
private final Identifier egg;
|
||||
private final Identifier egg2;
|
||||
|
||||
private final ReloadableResourceManager resourceManager;
|
||||
|
||||
/**
|
||||
* Creates a new profession cache
|
||||
*
|
||||
|
@ -37,10 +42,18 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
|||
* @param fallback The default if any generated textures fail to load. This is stored in place of failing textures.
|
||||
*/
|
||||
public PonyTextures(ITextureSupplier<String> formatter) {
|
||||
this.resourceManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
|
||||
this.formatter = formatter;
|
||||
this.fallback = formatter.supplyTexture("villager_pony");
|
||||
this.egg = formatter.supplyTexture("silly_pony");
|
||||
this.egg2 = formatter.supplyTexture("tiny_silly_pony");
|
||||
|
||||
resourceManager.registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ResourceManager manager) {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +95,7 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
|||
}
|
||||
|
||||
protected Optional<Identifier> verifyTexture(Identifier texture) {
|
||||
if (!MinecraftClient.getInstance().getResourceManager().containsResource(texture)) {
|
||||
if (!resourceManager.containsResource(texture)) {
|
||||
MineLittlePony.logger.warn("Villager texture `" + texture + "` was not found.");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue