User Tools

Site Tools


tutorial:blockstate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:blockstate [2019/08/28 21:29] – [Giving a block state] Added description of blockstate json b0undarybreakertutorial:blockstate [2019/08/28 21:49] – [Giving a block state] finish adding tutorial for blockstate jsons b0undarybreaker
Line 79: Line 79:
 - The ''"variants"'' block will be where all possible variations for your blockstate go. We'll explore variants more in a little. - The ''"variants"'' block will be where all possible variations for your blockstate go. We'll explore variants more in a little.
 - A variant named ''""'' will apply to //every// permutation of a blockstate. If you have a ''""'' variant, you shouldn't have any other variants in the JSON, or Minecraft will get upset. - A variant named ''""'' will apply to //every// permutation of a blockstate. If you have a ''""'' variant, you shouldn't have any other variants in the JSON, or Minecraft will get upset.
-- The object assigned to the ''""'' variant can have various properties added to it like rotation or texture manipulation. Check out the [[Minecraft wiki]](https://minecraft.gamepedia.com/Model#Block_states) for more documentation on what properties can be added.+- The object assigned to the ''""'' variant can have various properties added to it like rotation or texture manipulation. Check out the linked Model page below for more documentation on what properties can be added. All variants //must// contain a ''"model"'' property. 
 +- The ''"model"'' property is always passed an ID of a model. In this case, the game will look at the location ''src/main/resources/assets/mymod/models/block/my_block.json''. The ID here can be anything. It doesn't //need// to be the same as your block's ID, but if you only have one variant, it probably should. Block models have their own setup, which is documented very well on the Minecraft wiki page linked below. You can either write the JSON by hand or use a program like [[https://blockbench.net|Blockbench]] to generate it more easily. 
 + 
 +If you //do// want to have different models for each blockstate, you'd want to add multiple variants. For the same ''src/main/resources/assets/mymod/blockstates/my_block.json'' location we used above, your could would probably look like such: 
 + 
 +<code json> 
 +
 +    "variants":
 +        "hardened=false": { "model": "mymod:block/my_block" }, 
 +        "hardened=true": { "model": "mymod:block/my_block_hardened"
 +    } 
 +
 +</code> 
 + 
 +In this JSON, there are two variants, one for each possibility of the ''HARDENED'' property we defined above. Since we gave the property the string name of ''hardened'' in the Java, that's what we use here. Booleans only have two states, but if you use properties based on integers or enums, you'll have more variants. Variants are based on possible permutations of the properties added to your block. A property can be totally ignored in the blockstate JSON if you want, like in the first blockstate JSON where we ignored the ''hardened'' property, but if you want to include a property in one variant, it must be included in //all// variants. If ''mymod:my_block'' also had a boolean property called ''glowing'', and you wanted to change the model based on whether it was glowing and based on whether it was hardened, you would need four variants: hardened off and glowing off, hardened on and glowing off, hardened off and glowing on, and hardened on and glowing on. The same model can be assigned to multiple variants if you need it to be. 
 + 
 +This is only a simple introduction to blockstate JSONs. All of the tricks you can do with blockstate and model JSONs are documented on the [[https://minecraft.gamepedia.com/Model|Minecraft wiki]], along with examples of how the features are used in vanillaBest of luck!
 ==== A note about performance ==== ==== A note about performance ====
 Every possible state of a block is registered at the start of the game. This means that if you have 14 boolean properties, the block has 2^14 = 16384 different states and 2^14 states are registered. For this reason blocks should not contain too many blockstate properties. Rather, blockstates should be mostly reserved for visuals, and [[tutorial:blockentity|Block Entities]] should be used for more advanced state. Every possible state of a block is registered at the start of the game. This means that if you have 14 boolean properties, the block has 2^14 = 16384 different states and 2^14 states are registered. For this reason blocks should not contain too many blockstate properties. Rather, blockstates should be mostly reserved for visuals, and [[tutorial:blockentity|Block Entities]] should be used for more advanced state.
tutorial/blockstate.txt · Last modified: 2023/11/18 08:13 by solidblock