You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: develop/data-generation/block-models.md
+30-72Lines changed: 30 additions & 72 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,23 @@
1
1
---
2
2
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.
4
4
authors:
5
5
- Fellteros
6
6
- natri0
7
7
- IMB11
8
+
- its-miroma
8
9
---
9
10
10
-
# Block Model Generation {#model-generation}
11
+
# Block Model Generation {#block-model-generation}
11
12
12
13
::: info Prerequisites
13
14
Make sure you've completed the [datagen setup](./setup) process first.
14
15
:::
15
16
16
17
## Setup {#setup}
17
18
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`.
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.
71
72
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
+
73
77
Be aware of this, if you're changing block model of this particular block, as it will result in en error.
78
+
:::
74
79
75
80
You can also append a `BlockFamily`, which will generate models for all of its "children".
76
81
@@ -86,24 +91,25 @@ You can also append a `BlockFamily`, which will generate models for all of its "
86
91
87
92
Doors and trapdoors are a little different. Here, you have to make three new textures - two for the door, and one for the trapdoor.
88
93
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.
95
101
96
102
<DownloadEntryvisualURL="/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>
97
103
98
-
## Custom Block Models and Datagen Methods {#custom-models-and-methods}
104
+
## Custom Block Models {#custom-block-models}
99
105
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.
101
107
102
108
_Points 2. - 6. are declared in an inner static helper class called `CustomBlockStateModelGenerator`._
103
109
104
110
### Custom Block Class {#custom-block-class}
105
111
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.
107
113
Then you should override `getOutlineShape` and `getCollisionShape`, so that the outline is rendered correctly, and the block has the correct collision shape.
@@ -121,54 +127,7 @@ And you're done! You can now test the block out and place it in game.
121
127
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.
122
128
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:
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.
196
155
The `TextureKey`s represent the "placeholders" (`#bottom`, `#top`, ...) as an Object.
197
156
198
157
### Using Texture Map {#using-texture-map}
199
158
200
159
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:
202
160
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.
205
162
206
163
::: tip
207
164
`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
217
174
All `TextureKey`s in the TextureMap **have to** match all `TextureKey`s in your parent block model!
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`.
228
185
Specify which model and which transformations (uvlock, rotation) is used when using `.register()`.
229
186
For example:
230
187
@@ -254,5 +211,6 @@ And that is all! Now all that's left to do is to call our method in our `ModelPr
254
211
255
212
## Sources and Links {#sources-and-links}
256
213
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