mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-04-01 01:05:27 +02:00
Villager skinning
This commit is contained in:
parent
d85ebc08f1
commit
7ed780ed70
2 changed files with 30 additions and 5 deletions
|
@ -26,7 +26,7 @@ public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadL
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SkinList get(Identifier id) {
|
public SkinList get(Identifier id) {
|
||||||
return entries.computeIfAbsent(id, SkinList::new);
|
return entries.computeIfAbsent(id, SkinList::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,9 @@ public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadL
|
||||||
return get(poolId, entity.getUuid());
|
return get(poolId, entity.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SkinList {
|
public static final class SkinList {
|
||||||
private final List<Identifier> textures = new ArrayList<>();
|
private final List<Identifier> textures = new ArrayList<>();
|
||||||
|
private final Map<String, List<Identifier>> names = new HashMap<>();
|
||||||
|
|
||||||
private final Identifier id;
|
private final Identifier id;
|
||||||
|
|
||||||
|
@ -56,6 +57,20 @@ public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadL
|
||||||
return Optional.ofNullable(textures.get(MathUtil.mod(uuid.hashCode(), textures.size())));
|
return Optional.ofNullable(textures.get(MathUtil.mod(uuid.hashCode(), textures.size())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Identifier> getByName(String name, UUID uuid) {
|
||||||
|
List<Identifier> options = names.computeIfAbsent(name.toLowerCase(Locale.ROOT).replace(' ', '_') + ".png", id -> {
|
||||||
|
return textures.stream().filter(texture -> {
|
||||||
|
return texture.getPath().endsWith(id);
|
||||||
|
}).toList();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (options.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(options.get(MathUtil.mod(uuid.hashCode(), options.size())));
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadAll(ResourceManager resourceManager) {
|
public void reloadAll(ResourceManager resourceManager) {
|
||||||
textures.clear();
|
textures.clear();
|
||||||
textures.addAll(resourceManager.findResources(id.getPath(), path -> path.getPath().endsWith(".png")).keySet());
|
textures.addAll(resourceManager.findResources(id.getPath(), path -> path.getPath().endsWith(".png")).keySet());
|
||||||
|
|
|
@ -9,11 +9,11 @@ import net.minecraft.village.VillagerDataContainer;
|
||||||
import net.minecraft.village.VillagerProfession;
|
import net.minecraft.village.VillagerProfession;
|
||||||
import net.minecraft.village.VillagerType;
|
import net.minecraft.village.VillagerType;
|
||||||
|
|
||||||
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
import com.minelittlepony.client.pony.PonyManager;
|
||||||
import com.minelittlepony.util.ResourceUtil;
|
import com.minelittlepony.util.ResourceUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached pool of villager textures.
|
* Cached pool of villager textures.
|
||||||
|
@ -51,6 +51,16 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
|
||||||
return entity.isBaby() ? egg2 : egg;
|
return entity.isBaby() ? egg2 : egg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entity.hasCustomName()) {
|
||||||
|
Optional<Identifier> override = MineLittlePony.getInstance().getVariatedTextures()
|
||||||
|
.get(PonyManager.BACKGROUND_PONIES)
|
||||||
|
.getByName(entity.getCustomName().getString(), entity.getUuid());
|
||||||
|
|
||||||
|
if (override.isPresent()) {
|
||||||
|
return override.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VillagerData t = entity.getVillagerData();
|
VillagerData t = entity.getVillagerData();
|
||||||
|
|
||||||
return getTexture(t.getType(), t.getProfession());
|
return getTexture(t.getType(), t.getProfession());
|
||||||
|
|
Loading…
Add table
Reference in a new issue