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 revision
Previous revision
Next revisionBoth sides next revision
tutorial:blockstate [2019/08/28 21:54] – [Adding models for your blockstates] b0undarybreakertutorial:blockstate [2019/12/15 22:55] – re-yarn b0undarybreaker
Line 8: Line 8:
 it would become harder and gain a hardness of ''2''   it would become harder and gain a hardness of ''2''  
      
-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<Block, BlockState> stateFactory) { +    protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { 
-        stateFactory.add(HARDENED);+        stateManager.add(HARDENED);
     }     }
          
Line 31: Line 31:
     public MyBlock(Settings settings) {     public MyBlock(Settings settings) {
         super(settings);         super(settings);
-        setDefaultState(getStateFactory().getDefaultState().with(HARDENED, false));+        setDefaultState(getStateManager().getDefaultState().with(HARDENED, false));
     }     }
          
 } }
 </code> </code>
 +(To set multiple properties, chain ''with()'' calls)
  
-Now, to set the property we need to call   +Now, to set the property we need to call  ''world.setBlockState()'':  
- +
-''world.setBlockState(<block-position>, <block-instance>.getDefaultState().with(<property-name>, <new-value>)'':  +
            
 (Replace ''MyBlocks.MY_BLOCK_INSTANCE'' with your block's instance) (Replace ''MyBlocks.MY_BLOCK_INSTANCE'' with your block's instance)
Line 71: Line 70:
 Let's say you register an instance of ''MyBlock'' to the ID ''mymod:my_block''. Minecraft would look for a file at the location ''src/main/resources/assets/mymod/blockstates/my_block.json'' to load the state from. If you don't want your block to change models between states, the blockstate JSON can be very simple. It would look something like this: Let's say you register an instance of ''MyBlock'' to the ID ''mymod:my_block''. Minecraft would look for a file at the location ''src/main/resources/assets/mymod/blockstates/my_block.json'' to load the state from. If you don't want your block to change models between states, the blockstate JSON can be very simple. It would look something like this:
  
-<code json>+<code JavaScript resources/assets/mymod/blockstates/my_block.json>
 { {
     "variants": {     "variants": {
Line 88: Line 87:
 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: 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>+<code JavaScript resources/assets/mymod/blockstates/my_block.json>
 { {
     "variants": {     "variants": {
tutorial/blockstate.txt · Last modified: 2023/11/18 08:13 by solidblock