7.0 KiB
Block Models
A block's model is its shape: the boxes it's made of and which texture goes on each face. Blocks use engine:cube
unless they set model. For entity models, see Entities.
Built-In Models
| Model | Texture variables | Shape |
|---|---|---|
engine:cube |
one texture, { top, bottom, side } or { front, side } |
A full block. |
engine:cross |
cross |
Two crossed planes, like flowers and saplings. |
engine:crop |
crop |
Four planes in a # shape, like wheat. |
Blocks that aren't full cubes should use the cutout or translucent render layer, since
solid blocks hide their neighbors' faces. They usually want "collision": false too.
In inventories, a block with a full cube model is drawn as a cube. Any other block is drawn flat, as its first texture, like Minecraft's plants.
Texture Variables
Models name their textures with variables, like #side, and blocks fill them in with textures:
{
"id": "bworld:sapling",
"model": "engine:cross",
"textures": { "cross": "bworld:sapling" }
}
For engine:cube, one texture id fills every face. { "front", "side" } puts front on the north face and side on
the rest. It's for blocks that face a way, and can also set top and bottom.
Custom Models
Mods add models in models/, in Minecraft's block model format: boxes measured in pixels, where 0 to 16 is the block,
with a texture per face. models/slab.json:
{
"format_version": 1,
"model": {
"id": "copper_tools:slab",
"textures": { "top": "#side", "bottom": "#side" },
"elements": [{
"from": [0, 0, 0],
"to": [16, 8, 16],
"faces": {
"top": { "texture": "#top" },
"bottom": { "texture": "#bottom", "cullface": "bottom" },
"north": { "texture": "#side", "cullface": "north" },
"south": { "texture": "#side", "cullface": "south" },
"west": { "texture": "#side", "cullface": "west" },
"east": { "texture": "#side", "cullface": "east" }
}
}]
}
}
A block using it sets "model": "copper_tools:slab" and "textures": { "side": "bworld:planks" }, and gets planks on
every face, since top and bottom default to #side.
| Field | Meaning |
|---|---|
id |
The model's id, in the mod's namespace. |
textures |
Defaults for texture variables. Values are texture ids or other variables, like "#side". |
elements[].from, to |
Opposite corners of the box, [x, y, z] in pixels. |
elements[].rotation |
{ origin, axis, angle, rescale }: turns the box around origin on x, y or z by -45, -22.5, 0, 22.5 or 45 degrees. rescale stretches it back to the block's width. |
elements[].shade |
Darker faces on the sides and bottom. true by default, plants turn it off. |
elements[].faces |
Any of top, bottom, north, south, west and east. |
faces.*.texture |
A variable like "#side", filled in by the block's textures, or a texture id. |
faces.*.uv |
[u1, v1, u2, v2], the part of the texture in pixels. Defaults to the part the face covers. |
faces.*.rotation |
Turns the texture on the face clockwise by 0, 90, 180 or 270 degrees. |
faces.*.cullface |
Hides the face when the neighbor on that side is a solid block. Only for faces on the block's edge. |
Faces are only drawn from the front, so a flat plane that should be seen from both sides needs a face each way.
Shapes
A block's shape is the boxes it's made of, like Minecraft's VoxelShape. It's what players point at, so they can look
past the empty half of a slab, what the cracks are drawn on while it's being broken, and, unless the block sets
"collision": false, what entities bump into and stand on. A block that's only half there can't be placed where a
player is standing in its other half, either.
By default it comes from the model: one box per element, turned with the block's y. An element turned by its own
rotation gets the box around it. Elements that are flat planes aren't boxes, so a model made only of planes, like
engine:cross and engine:crop, gets one box around all of them, which is what players point at to break the plant.
A block can set its own with shape, a list of boxes in pixels like from and to put together, as Minecraft's
Block.box does. That's for a shape simpler than the model, or one that's different from what's drawn, like a flower
pot's plant you can't click on. shape is turned with the block's y too, and variants can set
their own, like a crop that's taller the older it is:
{
"id": "copper_tools:rice",
"model": "engine:crop",
"textures": { "crop": "copper_tools:rice_3" },
"collision": false,
"states": [{ "name": "age", "bits": 2, "default": 0 }],
"shape": [[0, 0, 0, 16, 16, 16]],
"variants": {
"age=0": { "textures": { "crop": "copper_tools:rice_0" }, "shape": [[0, 0, 0, 16, 4, 16]] },
"age=1": { "textures": { "crop": "copper_tools:rice_1" }, "shape": [[0, 0, 0, 16, 8, 16]] },
"age=2": { "textures": { "crop": "copper_tools:rice_2" }, "shape": [[0, 0, 0, 16, 12, 16]] }
}
}
Boxes stay inside the block, from 0 to 16, so a shape can't be taller than a block like Minecraft's fences.
Lighting
Faces flat against the block's edge get smooth lighting and ambient occlusion like a full block's. Anything inside the block is lit evenly with the light of the block's own space.