• 论坛

导航

  • 主页
  • 样式指南
  • 入门
    • 概述
    • Mod的结构
    • Forge更新检查器
    • 依赖管理
    • 调试分析器
  • 概念
    • Sides
    • 资源
    • 注册表
    • Jar签名
    • 国际化和本地化
  • 方块
    • 概述
    • 介绍方块状态
    • 方块互动
  • 动画 API
    • 概述
    • 骨骼
    • 动画状态机
    • 使用API
  • TileEntity
    • 概述
    • 特殊渲染器
  • 物品
    • 主页
    • 战利品表
  • 模型
    • 模型概述
    • 模型文件
    • 方块状态
      • 方块状态JSON概述
      • Forge方块状态JSON
    • 绑定模型到方块和物品
    • 彩色纹理
    • 物品属性概述
    • 高级模型(未翻译)
      • 高级模型介绍
      • IModel
        • getDependencies
        • getTextures
        • bake
        • process
        • smoothLighting
        • gui3D
        • retexture
        • uvlock
      • IModelState and IModelPart
      • IBakedModel
      • Extended Blockstates
      • Perspective
      • ItemOverrideList
      • ICustomModelLoader
  • 渲染
    • TileEntityItemStackRenderer
  • 事件
    • 基本用法
  • 网络
    • 主页
    • 概述
    • SimpleImpl
    • 实体
  • 数据储存
    • 能力系统
    • World Saved Data
    • 拓展实体属性
    • Config注解
  • 工具
    • 合成
    • 矿物词典
    • 权限API
  • 效果
    • 音效
  • 惯例
    • 版本命名
    • 文件位置
    • 加载阶段
  • 参与Forge开发
    • 入门
    • PR指南

IModel

IModel is a type that represents a model in its raw state. This is how a model is represented right after it has been loaded. Usually this directly represents the source of the model (e.g. an object deserialized from JSON, or an OBJ container).

At this high level, a model has no concept of items, blocks, or anything of that sort; it purely represents a shape.

重要

IModel is immutable. Methods such as process that alter the model should never mutate the IModel, as they should construct new IModels instead.

getDependencies

This is a collection of the ResourceLocations of all the models this model depends on. These models are guaranteed to be loaded before this one is baked. For example, a model deserialized from a blockstate JSON will depend on the models defined within. Only models that are directly mapped to a block/item are loaded normally; to ensure loading of other models, they must be declared as dependencies of another. Cyclic dependencies will cause a LoaderException to be thrown.

getTextures

This is a collection of the ResourceLocations of all the textures this model depends on. These textures are guaranteed to be loaded before this model is baked. For example, a vanilla JSON model depends on all the textures defined within.

bake

This is the main method of IModel. It takes an IModelState, a VertexFormat, and a function ResourceLocation → TextureAtlasSprite, to return an IBakedModel. IBakedModel is less abstract than IModel, and it is what interacts with blocks and items. The function ResourceLocation → TextureAtlasSprite is used to get textures from ResourceLocations (i.e. the ResourceLocations of textures are passed to this function and the returned TextureAtlasSprite contains the texture).

process

This method allows a model to process extra data from external sources. The Forge blockstate variant format provides a way to define this data in the resource pack. Within the Forge blockstate format, the property that is used to pass this data is called custom. First, an example:

{
  "forge_marker": 1,
  "defaults": {
    "custom": {
      "__comment": "These can be any JSON primitives with any names, but models should only use what they understand.",
      "meaningOfLife": 42,
      "showQuestion": false
    },
    "model": "examplemod:life_meaning"
  },
  "variants": {
    "dying": {
      "true": {
        "__comment": "Custom data is inherited. Therefore, here `meaningOfLife` is inherited but `showQuestion` is overriden. The model itself remains inherited.",
        "custom": {
          "showQuestion": true
        }
      },
      "false": {}
    }
  }
}

As seen above, custom data can be of any type. Additionally, it is inherited from the defaults into the variants. The custom data is passed in as an ImmutableMap<String, String>. This is a map where the keys are the property names (in the above example, “meaningOfLife”, “showQuestion”, and “title”). Astute observers may notice that numeric and boolean data were defined in within the blockstate but this method only receives Strings. This is because all data is converted into strings before being processed. If a model does not understand what a property means, it should just ignore it.

smoothLighting

In vanilla, smooth lighting enables ambient occlusion. This flag can be controlled by the smooth_lighting property in a Forge blockstate (which can appear wherever a model property can and is inherited). The default implementation does nothing.

gui3D

gui3D controls whether a model looks “flat” in certain positions (e.g. with gui3d set to true, EntityItem renders a stack with multiple items as several layers of the model. With gui3d set to false, the item is always one layer), and also controls lighting inside GUIs. This flag can be controlled by the gui3d property in a Forge blockstate. The default implementation does nothing.

retexture

This method is used to change the textures a model might use. This is similar to how texture variables in vanilla JSON models work. A model can start out with certain faces with certain textures, and then by setting/overriding texture variables these faces can be changed. An example:

{
  "forge_marker": 1,
  "defaults": {
    "textures": {
      "varA": "examplemod:items/hgttg",
      "varB": "examplemod:blocks/earth",
      "varC": "#varA",
      "varZ": null
    },
    "model": "examplemod:universe"
  }
}

In this example, the textures block will be deserialized as-is into an ImmutableMap with the exception that nulls are turned into "" (i.e. the final result is "varA" → "examplemod:items/hgttg", "varB" → "examplemod:blocks/earth", "varC" → "#varA", "varZ" → ""). Then, retexture is called to change the textures as needed. How this is done is up to the model. It may be advisable, however, to support resolving texture variables such as “#var” (like vanilla JSON models) instead of taking them literally. The default implementation does nothing.

uvlock

This method is used to toggle UV lock. UV lock means that when the model itself rotates, the textures applied to the model do not rotate with it. The default implementation does nothing. This can be controlled with the uvlock property in a Forge blockstate. An example:

{
  "forge_marker": 1,
  "defaults": {
    "model": "minecraft:half_slab",
    "textures": {
      "__comment": "Texture definitions here..."
    }
  },
  "variants": {
    "a": [{ "__comment": "No change" }],
    "b": [{
      "__comment": "This is like literally taking the slab and flipping it upside down. The 'side' texture on the side faces is cropped to the bottom half and rotated 180 degrees, just as if a real object were turned upside down.",
      "x": 180
    }],
    "c": [{
      "__comment": "Now this is more interesting. The UV vertices are altered so that the texture won't rotate with the model, so that the side faces have the side texture rightside up and cropped to the top half.",
      "x": 180,
      "uvlock": true
    }]
  }
}
基于 MkDocs 使用自定义主题构建. 托管于 Read the Docs.
启用夜间模式