VillagerProfessionLayer.java
net.minecraft.client.renderer.entity.layers.VillagerProfessionLayer
信息
- 全限定名:net.minecraft.client.renderer.entity.layers.VillagerProfessionLayer
- 类型:public class
- 包:net.minecraft.client.renderer.entity.layers
- 源码路径:src/main/java/net/minecraft/client/renderer/entity/layers/VillagerProfessionLayer.java
- 起始行号:L31
- 继承:RenderLayer<S,M>
- 职责:
TODO
字段/常量
-
LEVEL_LOCATIONS- 类型:
Int2ObjectMap<Identifier> - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
typeHatCache- 类型:
Object2ObjectMap<ResourceKey<VillagerType>,VillagerMetadataSection.Hat> - 修饰符:
private final - 源码定位:
L40 - 说明:
TODO
- 类型:
-
professionHatCache- 类型:
Object2ObjectMap<ResourceKey<VillagerProfession>,VillagerMetadataSection.Hat> - 修饰符:
private final - 源码定位:
L41 - 说明:
TODO
- 类型:
-
resourceManager- 类型:
ResourceManager - 修饰符:
private final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
path- 类型:
String - 修饰符:
private final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
noHatModel- 类型:
M - 修饰符:
private final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
noHatBabyModel- 类型:
M - 修饰符:
private final - 源码定位:
L45 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public VillagerProfessionLayer(RenderLayerParent<S,M> renderer, ResourceManager resourceManager, String path, M noHatModel, M noHatBabyModel) @ L47
- 构造器名:VillagerProfessionLayer
- 源码定位:L47
- 修饰符:public
参数:
- renderer: RenderLayerParent<S,M>
- resourceManager: ResourceManager
- path: String
- noHatModel: M
- noHatBabyModel: M
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, S state, float yRot, float xRot) @ L55
- 方法名:submit
- 源码定位:L55
- 返回类型:void
- 修饰符:public
参数:
- poseStack: PoseStack
- submitNodeCollector: SubmitNodeCollector
- lightCoords: int
- state: S
- yRot: float
- xRot: float
说明:
TODO
private Identifier getIdentifier(String type, Identifier key) @ L83
- 方法名:getIdentifier
- 源码定位:L83
- 返回类型:Identifier
- 修饰符:private
参数:
- type: String
- key: Identifier
说明:
TODO
private Identifier getIdentifier(String type, Holder<?> holder) @ L87
- 方法名:getIdentifier
- 源码定位:L87
- 返回类型:Identifier
- 修饰符:private
参数:
- type: String
- holder: Holder<?>
说明:
TODO
public <K> VillagerMetadataSection.Hat getHatData(Object2ObjectMap<ResourceKey<K>,VillagerMetadataSection.Hat> cache, String name, Holder<K> holder) @ L91
- 方法名:getHatData
- 源码定位:L91
- 返回类型:
VillagerMetadataSection.Hat - 修饰符:public
参数:
- cache: Object2ObjectMap<ResourceKey
,VillagerMetadataSection.Hat> - name: String
- holder: Holder
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class VillagerProfessionLayer<S extends LivingEntityRenderState & VillagerDataHolderRenderState, M extends EntityModel<S> & VillagerLikeModel<S>>
extends RenderLayer<S, M> {
private static final Int2ObjectMap<Identifier> LEVEL_LOCATIONS = Util.make(new Int2ObjectOpenHashMap<>(), map -> {
map.put(1, Identifier.withDefaultNamespace("stone"));
map.put(2, Identifier.withDefaultNamespace("iron"));
map.put(3, Identifier.withDefaultNamespace("gold"));
map.put(4, Identifier.withDefaultNamespace("emerald"));
map.put(5, Identifier.withDefaultNamespace("diamond"));
});
private final Object2ObjectMap<ResourceKey<VillagerType>, VillagerMetadataSection.Hat> typeHatCache = new Object2ObjectOpenHashMap<>();
private final Object2ObjectMap<ResourceKey<VillagerProfession>, VillagerMetadataSection.Hat> professionHatCache = new Object2ObjectOpenHashMap<>();
private final ResourceManager resourceManager;
private final String path;
private final M noHatModel;
private final M noHatBabyModel;
public VillagerProfessionLayer(RenderLayerParent<S, M> renderer, ResourceManager resourceManager, String path, M noHatModel, M noHatBabyModel) {
super(renderer);
this.resourceManager = resourceManager;
this.path = path;
this.noHatModel = noHatModel;
this.noHatBabyModel = noHatBabyModel;
}
public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, S state, float yRot, float xRot) {
if (!state.isInvisible) {
VillagerData villagerData = state.getVillagerData();
if (villagerData != null) {
Holder<VillagerType> type = villagerData.type();
Holder<VillagerProfession> profession = villagerData.profession();
VillagerMetadataSection.Hat typeHat = this.getHatData(this.typeHatCache, "type", type);
VillagerMetadataSection.Hat professionHat = this.getHatData(this.professionHatCache, "profession", profession);
M model = this.getParentModel();
Identifier typeTexture = this.getIdentifier(state.isBaby ? "baby" : "type", type);
boolean typeHatVisible = professionHat == VillagerMetadataSection.Hat.NONE
|| professionHat == VillagerMetadataSection.Hat.PARTIAL && typeHat != VillagerMetadataSection.Hat.FULL;
M noHatModel = state.isBaby ? this.noHatBabyModel : this.noHatModel;
renderColoredCutoutModel(typeHatVisible ? model : noHatModel, typeTexture, poseStack, submitNodeCollector, lightCoords, state, -1, 1);
if (!profession.is(VillagerProfession.NONE) && !state.isBaby) {
Identifier professionTexture = this.getIdentifier("profession", profession);
renderColoredCutoutModel(model, professionTexture, poseStack, submitNodeCollector, lightCoords, state, -1, 2);
if (!profession.is(VillagerProfession.NITWIT)) {
Identifier professionLevelTexture = this.getIdentifier(
"profession_level", LEVEL_LOCATIONS.get(Mth.clamp(villagerData.level(), 1, LEVEL_LOCATIONS.size()))
);
renderColoredCutoutModel(model, professionLevelTexture, poseStack, submitNodeCollector, lightCoords, state, -1, 3);
}
}
}
}
}
private Identifier getIdentifier(String type, Identifier key) {
return key.withPath(keyPath -> "textures/entity/" + this.path + "/" + type + "/" + keyPath + ".png");
}
private Identifier getIdentifier(String type, Holder<?> holder) {
return holder.unwrapKey().map(k -> this.getIdentifier(type, k.identifier())).orElse(MissingTextureAtlasSprite.getLocation());
}
public <K> VillagerMetadataSection.Hat getHatData(Object2ObjectMap<ResourceKey<K>, VillagerMetadataSection.Hat> cache, String name, Holder<K> holder) {
ResourceKey<K> key = holder.unwrapKey().orElse(null);
return key == null
? VillagerMetadataSection.Hat.NONE
: cache.computeIfAbsent(key, k -> this.resourceManager.getResource(this.getIdentifier(name, key.identifier())).flatMap(resource -> {
try {
return resource.metadata().getSection(VillagerMetadataSection.TYPE).map(VillagerMetadataSection::hat);
} catch (IOException var2x) {
return Optional.empty();
}
}).orElse(VillagerMetadataSection.Hat.NONE));
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
MissingTextureAtlasSprite.getLocation()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.make()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置: