ModelTemplate.java

net.minecraft.client.data.models.model.ModelTemplate

信息

  • 全限定名:net.minecraft.client.data.models.model.ModelTemplate
  • 类型:public class
  • 包:net.minecraft.client.data.models.model
  • 源码路径:src/main/java/net/minecraft/client/data/models/model/ModelTemplate.java
  • 起始行号:L22
  • 职责:

    TODO

字段/常量

  • model

    • 类型: Optional<Identifier>
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • requiredSlots

    • 类型: Set<TextureSlot>
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • suffix

    • 类型: Optional<String>
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ModelTemplate(Optional<Identifier> model, Optional<String> suffix, TextureSlot... requiredSlots) @ L27

  • 构造器名:ModelTemplate
  • 源码定位:L27
  • 修饰符:public

参数:

  • model: Optional
  • suffix: Optional
  • requiredSlots: TextureSlot…

说明:

TODO

方法

下面的方法块按源码顺序生成。

public Identifier getDefaultModelLocation(Block block) @ L33

  • 方法名:getDefaultModelLocation
  • 源码定位:L33
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • block: Block

说明:

TODO

public Identifier create(Block block, TextureMapping textures, BiConsumer<Identifier,ModelInstance> output) @ L37

  • 方法名:create
  • 源码定位:L37
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • block: Block
  • textures: TextureMapping
  • output: BiConsumer<Identifier,ModelInstance>

说明:

TODO

public Identifier createWithSuffix(Block block, String extraSuffix, TextureMapping textures, BiConsumer<Identifier,ModelInstance> output) @ L41

  • 方法名:createWithSuffix
  • 源码定位:L41
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • block: Block
  • extraSuffix: String
  • textures: TextureMapping
  • output: BiConsumer<Identifier,ModelInstance>

说明:

TODO

public Identifier createWithOverride(Block block, String suffixOverride, TextureMapping textures, BiConsumer<Identifier,ModelInstance> output) @ L45

  • 方法名:createWithOverride
  • 源码定位:L45
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • block: Block
  • suffixOverride: String
  • textures: TextureMapping
  • output: BiConsumer<Identifier,ModelInstance>

说明:

TODO

public Identifier create(Item item, TextureMapping textures, BiConsumer<Identifier,ModelInstance> output) @ L49

  • 方法名:create
  • 源码定位:L49
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • item: Item
  • textures: TextureMapping
  • output: BiConsumer<Identifier,ModelInstance>

说明:

TODO

public Identifier create(Identifier target, TextureMapping textures, BiConsumer<Identifier,ModelInstance> output) @ L53

  • 方法名:create
  • 源码定位:L53
  • 返回类型:Identifier
  • 修饰符:public

参数:

  • target: Identifier
  • textures: TextureMapping
  • output: BiConsumer<Identifier,ModelInstance>

说明:

TODO

private Map<TextureSlot,Material> createMap(TextureMapping mapping) @ L72

  • 方法名:createMap
  • 源码定位:L72
  • 返回类型:Map<TextureSlot,Material>
  • 修饰符:private

参数:

  • mapping: TextureMapping

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ModelTemplate {
    private final Optional<Identifier> model;
    private final Set<TextureSlot> requiredSlots;
    private final Optional<String> suffix;
 
    public ModelTemplate(Optional<Identifier> model, Optional<String> suffix, TextureSlot... requiredSlots) {
        this.model = model;
        this.suffix = suffix;
        this.requiredSlots = ImmutableSet.copyOf(requiredSlots);
    }
 
    public Identifier getDefaultModelLocation(Block block) {
        return ModelLocationUtils.getModelLocation(block, this.suffix.orElse(""));
    }
 
    public Identifier create(Block block, TextureMapping textures, BiConsumer<Identifier, ModelInstance> output) {
        return this.create(ModelLocationUtils.getModelLocation(block, this.suffix.orElse("")), textures, output);
    }
 
    public Identifier createWithSuffix(Block block, String extraSuffix, TextureMapping textures, BiConsumer<Identifier, ModelInstance> output) {
        return this.create(ModelLocationUtils.getModelLocation(block, extraSuffix + this.suffix.orElse("")), textures, output);
    }
 
    public Identifier createWithOverride(Block block, String suffixOverride, TextureMapping textures, BiConsumer<Identifier, ModelInstance> output) {
        return this.create(ModelLocationUtils.getModelLocation(block, suffixOverride), textures, output);
    }
 
    public Identifier create(Item item, TextureMapping textures, BiConsumer<Identifier, ModelInstance> output) {
        return this.create(ModelLocationUtils.getModelLocation(item, this.suffix.orElse("")), textures, output);
    }
 
    public Identifier create(Identifier target, TextureMapping textures, BiConsumer<Identifier, ModelInstance> output) {
        Map<TextureSlot, Material> slots = this.createMap(textures);
        output.accept(target, () -> {
            JsonObject result = new JsonObject();
            this.model.ifPresent(m -> result.addProperty("parent", m.toString()));
            if (!slots.isEmpty()) {
                JsonObject textureObj = new JsonObject();
                slots.forEach((slot, value) -> {
                    JsonElement valueJson = Material.CODEC.encodeStart(JsonOps.INSTANCE, value).getOrThrow();
                    textureObj.add(slot.getId(), valueJson);
                });
                result.add("textures", textureObj);
            }
 
            return result;
        });
        return target;
    }
 
    private Map<TextureSlot, Material> createMap(TextureMapping mapping) {
        return Streams.concat(this.requiredSlots.stream(), mapping.getForced()).collect(ImmutableMap.toImmutableMap(Function.identity(), mapping::get));
    }
}

引用的其他类