mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Changed fallback handling for villager textures to try the plains biome as fail-safe before going to the default/nitwit texture
This commit is contained in:
parent
fb235f9179
commit
7f6222d0d6
1 changed files with 31 additions and 21 deletions
|
@ -11,9 +11,9 @@ 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 java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached pool of villager textures.
|
* Cached pool of villager textures.
|
||||||
|
@ -55,33 +55,43 @@ class VillagerProfessionTextureCache<T extends LivingEntity & VillagerDataContai
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.getVillagerData().getProfession() == VillagerProfession.NONE) {
|
VillagerData t = entity.getVillagerData();
|
||||||
|
|
||||||
|
return getTexture(t.getType(), t.getProfession());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Identifier getTexture(final VillagerType type, final VillagerProfession profession) {
|
||||||
|
|
||||||
|
if (profession == VillagerProfession.NONE) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache.computeIfAbsent(formatTexture(entity), this::getTexture);
|
String key = String.format("pony/%s/%s", type, profession);
|
||||||
|
|
||||||
|
if (cache.containsKey(key)) {
|
||||||
|
return cache.get(key); // People often complain that villagers cause lag,
|
||||||
|
// so let's do better than Mojang and rather NOT go
|
||||||
|
// through all the lambda generations if we can avoid it.
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatTexture(T entity) {
|
return cache.computeIfAbsent(key, k -> {
|
||||||
VillagerData t = entity.getVillagerData();
|
return verifyTexture(formatter.supplyTexture(k)).orElseGet(() -> {
|
||||||
VillagerType type = t.getType();
|
if (type == VillagerType.PLAINS) {
|
||||||
VillagerProfession profession = t.getProfession();
|
|
||||||
|
|
||||||
return String.format("pony/%s/%s", type, profession.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Identifier getTexture(String professionId) {
|
|
||||||
Identifier generated = formatter.supplyTexture(professionId);
|
|
||||||
|
|
||||||
try {
|
|
||||||
MinecraftClient.getInstance().getResourceManager().getResource(generated);
|
|
||||||
} catch (IOException e) {
|
|
||||||
MineLittlePony.logger.error("Error loading villager texture `" + generated + "`.", e);
|
|
||||||
|
|
||||||
// if texture loading fails, use the fallback.
|
// if texture loading fails, use the fallback.
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return generated;
|
return getTexture(VillagerType.PLAINS, profession);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Optional<Identifier> verifyTexture(Identifier texture) {
|
||||||
|
if (!MinecraftClient.getInstance().getResourceManager().containsResource(texture)) {
|
||||||
|
MineLittlePony.logger.warn("Villager texture `" + texture + "` was not found.");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue