tutorial:blockstate
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:blockstate [2019/08/28 21:29] – [Giving a block state] Added description of blockstate json b0undarybreaker | tutorial:blockstate [2020/03/19 10:19] – don't hardcode a single Block instance in onUse juuz | ||
---|---|---|---|
Line 8: | Line 8: | ||
it would become harder and gain a hardness of '' | it would become harder and gain a hardness of '' | ||
| | ||
- | First we define the boolean property of the block - whether or not it is hard: | + | First we define the boolean property of the block - whether or not it is hard (careful not to import the wrong BooleanProperty!): |
<code java> | <code java> | ||
public class MyBlock extends Block { | public class MyBlock extends Block { | ||
Line 19: | Line 19: | ||
[...] | [...] | ||
@Override | @Override | ||
- | protected void appendProperties(StateFactory.Builder< | + | protected void appendProperties(StateManager.Builder< |
- | | + | |
} | } | ||
| | ||
Line 31: | Line 31: | ||
public MyBlock(Settings settings) { | public MyBlock(Settings settings) { | ||
super(settings); | super(settings); | ||
- | setDefaultState(getStateFactory().getDefaultState().with(HARDENED, | + | setDefaultState(getStateManager().getDefaultState().with(HARDENED, |
} | } | ||
| | ||
} | } | ||
</ | </ | ||
+ | (To set multiple properties, chain '' | ||
- | Now, to set the property we need to call | + | Now, to set the property we need to call '' |
- | + | ||
- | '' | + | |
(Replace '' | (Replace '' | ||
Line 46: | Line 45: | ||
[...] | [...] | ||
@Override | @Override | ||
- | public | + | public |
- | world.setBlockState(pos, | + | world.setBlockState(pos, |
- | return | + | return |
} | } | ||
} | } | ||
Line 65: | Line 64: | ||
</ | </ | ||
- | You can also make the texture and model of your block change based on the state. This is done through a JSON file called a Blockstate JSON. All blocks need a blockstate JSON, whether they have multiple states or not, but the contents of the JSON can be as simple or complex as you like. Let's say you register an instance of '' | + | ==== Adding models for your blockstates |
- | <code json> | + | You can also make the texture and model of your block change based on the state. This is done through a JSON file called a Blockstate JSON. All blocks need a blockstate JSON, whether they have multiple states or not, but the contents of the JSON can be as simple or complex as you like. If you want to change the textures of your block based on the state, you //will// need multiple models. |
+ | |||
+ | Let's say you register an instance of '' | ||
+ | |||
+ | < | ||
{ | { | ||
" | " | ||
Line 79: | Line 82: | ||
- The ''" | - The ''" | ||
- A variant named ''""'' | - A variant named ''""'' | ||
- | - The object assigned to the ''""'' | + | - The object assigned to the ''""'' |
+ | - The ''" | ||
+ | |||
+ | If you //do// want to have different models | ||
+ | |||
+ | <code JavaScript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In this JSON, there are two variants, one for each possibility of the '' | ||
+ | |||
+ | Variants are based on possible permutations of the properties | ||
+ | |||
+ | 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:// | ||
==== 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: | 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: |
tutorial/blockstate.txt · Last modified: 2024/08/26 01:19 by solidblock