tutorial:blockstate
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:blockstate [2022/03/20 13:59] – solidblock | tutorial:blockstate [2023/11/18 08:13] (current) – [Adding models for your blockstates] update Minecraft Wiki link solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Giving a block state ====== | ====== Giving a block state ====== | ||
- | Every type of block in Minecraft is represented by a singular '' | + | Every type of block in Minecraft is represented by a singular '' |
- | This makes it impossible to change a specific block' | + | |
- | as every other block of that type will be affected! | + | This is what '' |
- | But, what if you //do// want to give a singular block state, so it can change based on some condition? | + | |
- | This is what '' | + | |
- | Say we wanted a block that can summon lightning, but only when charged up. | + | |
| | ||
- | First we define the boolean property of the block - whether or not it is charged (careful not to import the wrong BooleanProperty!): | + | First we define the boolean property of the block - whether or not it is charged (careful not to import the wrong '' |
+ | |||
+ | In fact, you can also use existing properties defined in vanilla, which can be found in '' | ||
<code java> | <code java> | ||
public class ChargeableBlock extends Block { | public class ChargeableBlock extends Block { | ||
public static final BooleanProperty CHARGED = BooleanProperty.of(" | public static final BooleanProperty CHARGED = BooleanProperty.of(" | ||
| | ||
- | // The block instance. You can place it anywhere. | + | // The block instance. You can place it anywhere. Make the class is initialized. |
- | public static final ChargeableBlock CHARGEABLE_BLOCK = Registry.register( | + | public static final ChargeableBlock CHARGEABLE_BLOCK = new ChargeableBlock(FabricBlockSettings.copyOf(Blocks.STONE)); |
- | Registry.BLOCK, | + | } |
- | | + | </ |
- | new ChargeableBlock( | + | <code java> |
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registries.BLOCK, new Identifier(" | ||
+ | | ||
+ | } | ||
} | } | ||
</ | </ | ||
Line 36: | Line 41: | ||
public ChargeableBlock(Settings settings) { | public ChargeableBlock(Settings settings) { | ||
super(settings); | super(settings); | ||
- | setDefaultState(getStateManager().getDefaultState().with(CHARGED, | + | setDefaultState(getDefaultState().with(CHARGED, |
} | } | ||
| | ||
Line 77: | Line 82: | ||
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 " | 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 " | ||
- | Let's say you register an instance of '' | + | Let's say you register an instance of '' |
<code JavaScript resources/ | <code JavaScript resources/ | ||
Line 90: | Line 95: | ||
* The '' | * The '' | ||
- | * A variant named '' | + | * A variant named '' |
* The object assigned to the '' | * The object assigned to the '' | ||
* The '' | * The '' | ||
Line 109: | Line 114: | ||
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 '' | 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 '' | ||
- | 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:// | + | 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 | + | Every possible |
+ | |||
+ | As all possible states have been built, an equal state for a block is a same object, and the '' |
tutorial/blockstate.1647784775.txt.gz · Last modified: 2022/03/20 13:59 by solidblock