Skip to content

Commit 55684d1

Browse files
committed
Changed according to its-miroma's suggestions
1 parent bea15b9 commit 55684d1

File tree

1 file changed

+30
-72
lines changed

1 file changed

+30
-72
lines changed

develop/data-generation/block-models.md

Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
---
22
title: Block Model Generation
3-
description: A guide to generating block models & blockstates via datagen.
3+
description: A guide to generating block models and blockstates via datagen.
44
authors:
55
- Fellteros
66
- natri0
77
- IMB11
8+
- its-miroma
89
---
910

10-
# Block Model Generation {#model-generation}
11+
# Block Model Generation {#block-model-generation}
1112

1213
::: info Prerequisites
1314
Make sure you've completed the [datagen setup](./setup) process first.
1415
:::
1516

1617
## Setup {#setup}
1718

18-
First, we will need to create our ModelProvider. Create a class that `extends FabricModelProvider`. Implement both abstract methods, `generateBlockStateModels` & `generateItemModels`.
19-
Lastly, create constructor matching super.
19+
First, we will need to create our ModelProvider. Create a class that `extends FabricModelProvider`. Implement both abstract methods: `generateBlockStateModels` and `generateItemModels`.
20+
Lastly, create a constructor matching super.
2021

2122
@[code lang=java transcludeWith=:::datagen-model:provider](@/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceModelProvider.java)
2223

@@ -67,10 +68,14 @@ If you're stuck choosing which `TextureModel` you should use, open the `Textured
6768

6869
@[code lang=java transcludeWith=:::datagen-model:block-texture-pool-normal](@/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceModelProvider.java)
6970

70-
Another useful method is `registerCubeAllModelTexturePool`. Define the textures by passing in the "base block", and then append the "children", which will have the same textures.
71+
Another useful method is `registerCubeAllModelTexturePool`: define the textures by passing in the "base block", and then append the "children", which will have the same textures.
7172
In this case, we passed in the `RUBY_BLOCK`, so the stairs, slab and fence will use the `RUBY_BLOCK` texture.
72-
**_It will also generate a [simple cube all JSON model](#simple-cube-all) for the "base block" to ensure that it has a block model._**
73+
74+
::: warning
75+
It will also generate a [simple cube all JSON model](#simple-cube-all) for the "base block" to ensure that it has a block model.
76+
7377
Be aware of this, if you're changing block model of this particular block, as it will result in en error.
78+
:::
7479

7580
You can also append a `BlockFamily`, which will generate models for all of its "children".
7681

@@ -86,24 +91,25 @@ You can also append a `BlockFamily`, which will generate models for all of its "
8691

8792
Doors and trapdoors are a little different. Here, you have to make three new textures - two for the door, and one for the trapdoor.
8893

89-
1. **The door**. It has two parts - the upper half and the lower half. **Each needs its own texture:** in this case `ruby_door_top` for the upper half and `ruby_door_bottom` for the lower.
90-
The `registerDoor()` method will create models for all orientations of the door, both open and closed.
91-
**You also need an item texture!** Put it in `assets/<mod_id>/textures/item/` folder.
92-
2. **The trapdoor**. Here, you need only one texture, in this case named `ruby_trapdoor`. It will be used for all sides.
93-
Since `TrapdoorBlock` has a `FACING` property, you can use the commented out method to generate model files with rotated textures = the trapdoor will be "orientable".
94-
Otherwise, it will look the same no matter the direction it's facing.
94+
1. The door:
95+
- It has two parts - the upper half and the lower half. **Each needs its own texture:** in this case `ruby_door_top` for the upper half and `ruby_door_bottom` for the lower.
96+
- The `registerDoor()` method will create models for all orientations of the door, both open and closed.
97+
- **You also need an item texture!** Put it in `assets/<mod_id>/textures/item/` folder.
98+
2. The trapdoor:
99+
- Here, you need only one texture, in this case named `ruby_trapdoor`. It will be used for all sides.
100+
- Since `TrapdoorBlock` has a `FACING` property, you can use the commented out method to generate model files with rotated textures = the trapdoor will be "orientable". Otherwise, it will look the same no matter the direction it's facing.
95101

96102
<DownloadEntry visualURL="/assets/develop/data-generation/block-model/ruby_door_trapdoor_big.png" downloadURL="/assets/develop/data-generation/block-model/ruby_door_trapdoor_textures.zip">Ruby Door and Trapdoor</DownloadEntry>
97103

98-
## Custom Block Models and Datagen Methods {#custom-models-and-methods}
104+
## Custom Block Models {#custom-block-models}
99105

100-
In this section, we'll create the models for a **vertical slab block** with Oak Log textures => _Vertical Oak Log Slab_.
106+
In this section, we'll create the models for a Vertical Oak Log Slab, with Oak Log textures.
101107

102108
_Points 2. - 6. are declared in an inner static helper class called `CustomBlockStateModelGenerator`._
103109

104110
### Custom Block Class {#custom-block-class}
105111

106-
Create a `VerticalSlab` block with a `FACING` property and a `SINGLE` boolean property, like in the [Block States](../blocks/block-states) tutorial. `SINGLE` will indicate if there are both slabs.
112+
Create a `VerticalSlab` block with a `FACING` property and a `SINGLE` boolean property, like in the [Block States](../blocks/blockstates) tutorial. `SINGLE` will indicate if there are both slabs.
107113
Then you should override `getOutlineShape` and `getCollisionShape`, so that the outline is rendered correctly, and the block has the correct collision shape.
108114

109115
@[code lang=java transcludeWith=:::datagen-model-custom:voxels](@/reference/latest/src/main/java/com/example/docs/block/custom/VerticalSlabBlock.java)
@@ -121,54 +127,7 @@ And you're done! You can now test the block out and place it in game.
121127
Now, let's create a parent block model. It will determine the size, position in hand or other slots and the `x` and `y` coordinates of the texture.
122128
I highly recommend using [Blockbench](https://www.blockbench.net/) for this, as making it manually is a really tedious process. It should look something like this:
123129

124-
```json
125-
{
126-
"parent": "minecraft:block/block",
127-
"textures": {
128-
"particle": "#side"
129-
},
130-
"display": {
131-
"gui": {
132-
"rotation": [ 30, -135, 0 ],
133-
"translation": [ -1.5, 0.75, 0],
134-
"scale":[ 0.625, 0.625, 0.625 ]
135-
},
136-
"firstperson_righthand": {
137-
"rotation": [ 0, -45, 0 ],
138-
"translation": [ 0, 2, 0],
139-
"scale":[ 0.375, 0.375, 0.375 ]
140-
},
141-
"firstperson_lefthand": {
142-
"rotation": [ 0, 315, 0 ],
143-
"translation": [ 0, 2, 0],
144-
"scale":[ 0.375, 0.375, 0.375 ]
145-
},
146-
"thirdperson_righthand": {
147-
"rotation": [ 75, -45, 0 ],
148-
"translation": [ 0, 0, 2],
149-
"scale":[ 0.375, 0.375, 0.375 ]
150-
},
151-
"thirdperson_lefthand": {
152-
"rotation": [ 75, 315, 0 ],
153-
"translation": [ 0, 0, 2],
154-
"scale":[ 0.375, 0.375, 0.375 ]
155-
}
156-
},
157-
"elements": [
158-
{ "from": [ 0, 0, 0 ],
159-
"to": [ 16, 16, 8 ],
160-
"faces": {
161-
"down": { "uv": [ 0, 8, 16, 16 ], "texture": "#bottom", "cullface": "down", "tintindex": 0 },
162-
"up": { "uv": [ 0, 0, 16, 8 ], "texture": "#top", "cullface": "up", "tintindex": 0 },
163-
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "cullface": "north", "tintindex": 0 },
164-
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#side", "tintindex": 0 },
165-
"west": { "uv": [ 0, 0, 8, 16 ], "texture": "#side", "cullface": "west", "tintindex": 0 },
166-
"east": { "uv": [ 8, 0, 16, 16 ], "texture": "#side", "cullface": "east", "tintindex": 0 }
167-
}
168-
}
169-
]
170-
}
171-
```
130+
@[code lang=json](@/reference/latest/src/main/resources/assets/fabric-docs-reference/models/block/vertical_slab.json)
172131

173132
See [how blockstates are formatted](https://minecraft.wiki/w/Blockstates_definition_format) for more information.
174133
Notice the `#bottom`, `#top`, `#side` keywords. They act as variables that can be set by models that have this one as a parent:
@@ -184,24 +143,22 @@ Notice the `#bottom`, `#top`, `#side` keywords. They act as variables that can b
184143
}
185144
```
186145

187-
The `bottom` value will replace the `#bottom` placeholder and so on. **Put it in the `resources/assets/<mod_id>/models/block/` folder.**
146+
The `bottom` value will replace the `#bottom` placeholder and so on. **Put it in the `resources/assets/mod_id/models/block/` folder.**
188147

189148
### Custom Model {#custom-model}
190149

191150
Another thing we will need is an instance of the `Model` class. It will represent the actual [parent block model](#parent-block-model) inside our mod.
192151

193152
@[code lang=java transcludeWith=:::datagen-model-custom:model](@/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceModelProvider.java)
194153

195-
The `block()` method creates a new `Model`, pointing to the `vertical_slab.json` file inside the `resources/assets/<mod_id>/models/block/` folder.
154+
The `block()` method creates a new `Model`, pointing to the `vertical_slab.json` file inside the `resources/assets/mod_id/models/block/` folder.
196155
The `TextureKey`s represent the "placeholders" (`#bottom`, `#top`, ...) as an Object.
197156

198157
### Using Texture Map {#using-texture-map}
199158

200159
What does `TextureMap` do? It actually provides the Identifiers that point to the textures. It technically behaves like a normal map - you associate a `TextureKey` (Key) with an `Identifier` (Value).
201-
You can:
202160

203-
1. Use the Vanilla ones, e.g. `TextureMap.all()`(associates all TextureKeys with the same Identifier) or other.
204-
2. Create a new one by creating a new instance and then using `.put()` to associate keys with values.
161+
You can either use the vanilla ones, like `TextureMap.all()`(which associates all TextureKeys with the same Identifier), or create a new one, by creating a new instance and then using `.put()` to associate keys with values.
205162

206163
::: tip
207164
`TextureMap.all()` associates all TextureKeys with the same Identifier, no matter how many of them there are!
@@ -217,14 +174,14 @@ The ``bottom`` and ``top`` faces will use `oak_log_top.png`, the sides will use
217174
All `TextureKey`s in the TextureMap **have to** match all `TextureKey`s in your parent block model!
218175
:::
219176

220-
### Custom BlockStateSupplier Method {#custom-supplier-method}
177+
### Custom `BlockStateSupplier` Method {#custom-supplier-method}
221178

222179
The `BlockStateSupplier` contains all blockstate variants, their rotation, and other options like uvlock.
223180

224181
@[code lang=java transcludeWith=:::datagen-model-custom:supplier](@/reference/latest/src/client/java/com/example/docs/datagen/FabricDocsReferenceModelProvider.java)
225182

226183
First, we create a new `VariantsBlockStateSupplier` using `VariantsBlockStateSupplier.create()`.
227-
Then we create a new `BlockStateVariantMap` that contains parameters for all variants of the block, in this case `FACING` & `SINGLE`, and pass it into the `VariantsBlockStateSupplier`.
184+
Then we create a new `BlockStateVariantMap` that contains parameters for all variants of the block, in this case `FACING` and `SINGLE`, and pass it into the `VariantsBlockStateSupplier`.
228185
Specify which model and which transformations (uvlock, rotation) is used when using `.register()`.
229186
For example:
230187

@@ -254,5 +211,6 @@ And that is all! Now all that's left to do is to call our method in our `ModelPr
254211

255212
## Sources and Links {#sources-and-links}
256213

257-
Other examples of using custom datagen methods have been created using [Vanilla+ Blocks](https://github.com/Fellteros/vanillablocksplus) and [Vanilla+ Verticals](https://github.com/Fellteros/vanillavsplus) mods.
258-
You can also view the example tests in Fabric API and the Fabric docs reference mod for more information.
214+
You can view the example tests in Fabric API and the Fabric docs reference mod for more information.
215+
216+
You can also find more examples of using custom datagen methods by browsing mods' open-source code, for example [Vanilla+ Blocks](https://github.com/Fellteros/vanillablocksplus) and [Vanilla+ Verticals](https://github.com/Fellteros/vanillavsplus) by Fellteros.

0 commit comments

Comments
 (0)