# 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](../entities/index.md#entity-models). ## 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](../blocks/index.md#looks), 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, unless it sets an [`item_model`](#item-models). ## Texture Variables Models name their textures with variables, like `#side`, and blocks fill them in with `textures`: ```json { "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](../blocks/states.md#facing), 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`: ```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:oak_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. | | `parent` | Another model this one starts from, see [Parents](#parents). | | `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 `angle` degrees, from -180 to 180. `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. ## Parents A model can start from another with `parent`, like Minecraft's. It gets the parent's elements unless it has its own, and the parent's texture defaults, with its own winning. A parent can have a parent too. `models/brass_gear.json` reuses a gear's shape with other textures: ```json { "format_version": 1, "model": { "id": "copper_tools:brass_gear", "parent": "copper_tools:gear", "textures": { "teeth": "copper_tools:brass" } } } ``` A parent can be the mod's own model, a built-in one, or one from a mod it depends on. A model with no `elements` is only there to be a parent, or to give its children texture defaults. Parents are merged in once, when the game loads, so a model with a parent draws exactly as if it had everything written out. `check-mods` reports a parent that doesn't exist and parents that loop. The base game has Minecraft's template models in `mods/bworld/models/templates/`, with the same names and texture variables: `bworld:cube`, `cube_all`, `cube_column`, `cube_column_horizontal`, `cube_bottom_top`, `orientable`, `orientable_with_bottom`, `slab`, `slab_top`, `stairs`, `inner_stairs`, `outer_stairs`, the `template_wall_*` and `template_glass_pane_*` models, and `wall_inventory`. A pillar from a log's textures: ```json { "format_version": 1, "model": { "id": "copper_tools:pillar", "parent": "bworld:cube_column", "textures": { "end": "copper_tools:pillar_top", "side": "copper_tools:pillar" } } } ``` ## 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](../blocks/states.md) can set their own, like a crop that's taller the older it is: ```json { "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. ### Collision Shapes What entities bump into is the shape, unless the block sets `collision_shape`, like Minecraft's `getCollisionShape`. It's in pixels like `shape`, and is the only shape that can go higher than the block: up to 24 pixels, so a fence is too tall to jump over while players still point at a block-high post. Variants and [parts](#parts) can set their own. ## Parts A block can be made of pieces instead of one model, like Minecraft's multipart blockstates. Each of `parts` is a model that's drawn when its `when` matches the block's [states](../blocks/states.md) (always, without one), turned by its `y`. Its `shape` and `collision_shape` are added to the block's when it's drawn. A fence is a post, and a bar for each side it joins, `blocks/oak_fence.json`: ```json "states": [ { "name": "north", "bits": 1, "default": 0 }, { "name": "east", "bits": 1, "default": 0 }, { "name": "south", "bits": 1, "default": 0 }, { "name": "west", "bits": 1, "default": 0 } ], "parts": [ { "model": "bworld:fence_post", "shape": [[6, 0, 6, 10, 16, 10]], "collision_shape": [[6, 0, 6, 10, 24, 10]] }, { "when": "north=1", "model": "bworld:fence_side", "shape": [[7, 0, 0, 9, 16, 9]], "collision_shape": [[7, 0, 0, 9, 24, 9]] }, { "when": "east=1", "model": "bworld:fence_side", "y": 90, "shape": [[7, 0, 0, 9, 16, 9]], "collision_shape": [[7, 0, 0, 9, 24, 9]] }, ... ] ``` The side model is the bars on the north side, and `y` turns it to the others. Parts use the block's `textures` unless they set their own, so one pair of models serves every kind of wood. Parts replace `model` and `variants`' models. What sets the states is up to the block's [components](../blocks/components.md): the fences' `bworld:fence` sets them from what's beside it, every time something next to it changes. ## Item Models `item_model` draws a block's item with another model, filled in with the block's textures, like Minecraft's `fence_inventory`. Fences use `bworld:fence_inventory`, two posts and the bars between them, since a single post wouldn't look like a fence. It's drawn in slots, in hands and on the ground. ## 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.