ConditionalItemModel.java
net.minecraft.client.renderer.item.ConditionalItemModel
信息
- 全限定名:net.minecraft.client.renderer.item.ConditionalItemModel
- 类型:public class
- 包:net.minecraft.client.renderer.item
- 源码路径:src/main/java/net/minecraft/client/renderer/item/ConditionalItemModel.java
- 起始行号:L23
- 实现:ItemModel
- 职责:
TODO
字段/常量
-
property- 类型:
ItemModelPropertyTest - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
onTrue- 类型:
ItemModel - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
onFalse- 类型:
ItemModel - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.renderer.item.ConditionalItemModel.Unbaked- 类型:
record - 修饰符:
public - 源码定位:
L50 - 说明:
TODO
- 类型:
构造器
public ConditionalItemModel(ItemModelPropertyTest property, ItemModel onTrue, ItemModel onFalse) @ L28
- 构造器名:ConditionalItemModel
- 源码定位:L28
- 修饰符:public
参数:
- property: ItemModelPropertyTest
- onTrue: ItemModel
- onFalse: ItemModel
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void update(ItemStackRenderState output, ItemStack item, ItemModelResolver resolver, ItemDisplayContext displayContext, ClientLevel level, ItemOwner owner, int seed) @ L34
- 方法名:update
- 源码定位:L34
- 返回类型:void
- 修饰符:public
参数:
- output: ItemStackRenderState
- item: ItemStack
- resolver: ItemModelResolver
- displayContext: ItemDisplayContext
- level: ClientLevel
- owner: ItemOwner
- seed: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ConditionalItemModel implements ItemModel {
private final ItemModelPropertyTest property;
private final ItemModel onTrue;
private final ItemModel onFalse;
public ConditionalItemModel(ItemModelPropertyTest property, ItemModel onTrue, ItemModel onFalse) {
this.property = property;
this.onTrue = onTrue;
this.onFalse = onFalse;
}
@Override
public void update(
ItemStackRenderState output,
ItemStack item,
ItemModelResolver resolver,
ItemDisplayContext displayContext,
@Nullable ClientLevel level,
@Nullable ItemOwner owner,
int seed
) {
output.appendModelIdentityElement(this);
(this.property.get(item, level, owner == null ? null : owner.asLivingEntity(), seed, displayContext) ? this.onTrue : this.onFalse)
.update(output, item, resolver, displayContext, level, owner, seed);
}
@OnlyIn(Dist.CLIENT)
public record Unbaked(Optional<Transformation> transformation, ConditionalItemModelProperty property, ItemModel.Unbaked onTrue, ItemModel.Unbaked onFalse)
implements ItemModel.Unbaked {
public static final MapCodec<ConditionalItemModel.Unbaked> MAP_CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(
Transformation.EXTENDED_CODEC.optionalFieldOf("transformation").forGetter(ConditionalItemModel.Unbaked::transformation),
ConditionalItemModelProperties.MAP_CODEC.forGetter(ConditionalItemModel.Unbaked::property),
ItemModels.CODEC.fieldOf("on_true").forGetter(ConditionalItemModel.Unbaked::onTrue),
ItemModels.CODEC.fieldOf("on_false").forGetter(ConditionalItemModel.Unbaked::onFalse)
)
.apply(i, ConditionalItemModel.Unbaked::new)
);
@Override
public MapCodec<ConditionalItemModel.Unbaked> type() {
return MAP_CODEC;
}
@Override
public ItemModel bake(ItemModel.BakingContext context, Matrix4fc transformation) {
Matrix4fc childTransform = Transformation.compose(transformation, this.transformation);
return new ConditionalItemModel(
this.adaptProperty(this.property, context.contextSwapper()),
this.onTrue.bake(context, childTransform),
this.onFalse.bake(context, childTransform)
);
}
private ItemModelPropertyTest adaptProperty(ConditionalItemModelProperty originalProperty, @Nullable RegistryContextSwapper contextSwapper) {
if (contextSwapper == null) {
return originalProperty;
} else {
CacheSlot<ClientLevel, ItemModelPropertyTest> remappedModelCache = new CacheSlot<>(
context -> swapContext(originalProperty, contextSwapper, context)
);
return (itemStack, level, owner, seed, displayContext) -> {
ItemModelPropertyTest property = (ItemModelPropertyTest)(level == null ? originalProperty : remappedModelCache.compute(level));
return property.get(itemStack, level, owner, seed, displayContext);
};
}
}
private static <T extends ConditionalItemModelProperty> T swapContext(T originalProperty, RegistryContextSwapper contextSwapper, ClientLevel context) {
return (T)contextSwapper.swapTo((com.mojang.serialization.Codec<T>)originalProperty.type().codec(), originalProperty, context.registryAccess()).result().orElse(originalProperty);
}
@Override
public void resolveDependencies(ResolvableModel.Resolver resolver) {
this.onTrue.resolveDependencies(resolver);
this.onFalse.resolveDependencies(resolver);
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Transformation.compose()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/实现
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: