Blockstates
Often, you will find yourself in a situation where you want different states of a block. For example, a wheat crop has eight growth stages, and making a separate block for each stage feels wrong. Or you have a slab or slab-like block - one bottom state, one top state, and one state that has both.
This is where blockstates come into play. Blockstates are an easy way to represent the different states a block can have, like a growth stage or a slab placement type.
Blockstate Properties
Blockstates use a system of properties. A block can have multiple properties of multiple types. For example, an end portal frame has two properties: whether it has an eye (eye
, 2 options) and which direction it is placed in (facing
, 4 options). So in total, the end portal frame has 8 (2 * 4) different blockstates:
minecraft:end_portal_frame[facing=north,eye=false]
minecraft:end_portal_frame[facing=east,eye=false]
minecraft:end_portal_frame[facing=south,eye=false]
minecraft:end_portal_frame[facing=west,eye=false]
minecraft:end_portal_frame[facing=north,eye=true]
minecraft:end_portal_frame[facing=east,eye=true]
minecraft:end_portal_frame[facing=south,eye=true]
minecraft:end_portal_frame[facing=west,eye=true]
The notation blockid[property1=value1,property2=value,...]
is the standardized way of representing a blockstate in text form, and is used in some locations in vanilla, for example in commands.
If your block does not have any blockstate properties defined, it still has exactly one blockstate - that is the one without any properties, since there are no properties to specify. This can be denoted as minecraft:oak_planks[]
or simply minecraft:oak_planks
.
As with blocks, every BlockState
exists exactly once in memory. This means that ==
can and should be used to compare BlockState
s. BlockState
is also a final class, meaning it cannot be extended. Any functionality goes in the corresponding Block class!