User Tools

Site Tools


tutorial:directionalblock

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
tutorial:directionalblock [2022/01/31 01:12] – [Directional Blocks] solidblocktutorial:directionalblock [2023/09/26 05:43] (current) – Fix typo [Making a Directional Block] poopooracoocoo
Line 1: Line 1:
 ====== Making a Directional Block ====== ====== Making a Directional Block ======
- 
  
 Making blocks directional (facing into certain directions) is also done using block states. Making blocks directional (facing into certain directions) is also done using block states.
Line 12: Line 11:
  public VerticalSlabBlock(Settings settings) {  public VerticalSlabBlock(Settings settings) {
  super(settings);  super(settings);
- setDefaultState(this.stateManager.getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));+ setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
  }  }
  
  @Override  @Override
- protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { + protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { 
- stateManager.add(Properties.HORIZONTAL_FACING);+ builder.add(Properties.HORIZONTAL_FACING);
  }  }
  
  @Override  @Override
- public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {+ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
  Direction dir = state.get(FACING);  Direction dir = state.get(FACING);
  switch(dir) {  switch(dir) {
Line 39: Line 38:
         @Override         @Override
  public BlockState getPlacementState(ItemPlacementContext ctx) {  public BlockState getPlacementState(ItemPlacementContext ctx) {
- return (BlockState)this.getDefaultState().with(Properties.HORIZONTAL_FACING, ctx.getPlayerFacing().getOpposite());+ return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
  }  }
  
 +}
 +</code>
 +<code java>
 +public class ExampleMod implements ModInitializer {
 +    public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = Registry.register(
 +        Registries.BLOCK,
 +        new Identifier("tutorial", "polished_andesite_vertical_slab"),
 +        new VerticalSlabBlock(FabricBlockSettings.copyOf(Blocks.POLISHED_ANDESITE)));
 } }
 </code> </code>
  
 +===== Defining Blockstate JSON =====
  
-===== Defining Blockstate ===== +<code javascript src/main/resources/assets/tutorial/blockstates/polished_andesite_vertical_slab.json>
- +
-<code javascript src/main/resources/assets/tutorial/blockstates/polished_andesite_side_block.json>+
 { {
   "variants": {   "variants": {
-    "facing=north": { "model": "bitmod:block/polished_andesite_side_block", "uvlock": true }, +    "facing=north": { "model": "tutorial:block/polished_andesite_vertical_slab", "uvlock": true }, 
-    "facing=east":  { "model": "bitmod:block/polished_andesite_side_block", "y":  90, "uvlock": true }, +    "facing=east":  { "model": "tutorial:block/polished_andesite_vertical_slab", "y":  90, "uvlock": true }, 
-    "facing=south": { "model": "bitmod:block/polished_andesite_side_block", "y": 180, "uvlock": true }, +    "facing=south": { "model": "tutorial:block/polished_andesite_vertical_slab", "y": 180, "uvlock": true }, 
-    "facing=west":  { "model": "bitmod:block/polished_andesite_side_block", "y": 270, "uvlock": true }+    "facing=west":  { "model": "tutorial:block/polished_andesite_vertical_slab", "y": 270, "uvlock": true }
   }   }
 } }
 </code> </code>
- 
  
 ===== Defining Block Models ===== ===== Defining Block Models =====
  
- +<code javascript src/main/resources/assets/tutorial/models/block/vertical_slab.json>
-<code javascript src/main/resources/assets/tutorial/models/block/side.json>+
 {   "parent": "block/block", {   "parent": "block/block",
     "textures": {     "textures": {
Line 84: Line 88:
 </code> </code>
  
-<code javascript src/main/resources/assets/tutorial/models/block/polished_andesite_side_block.json>+<code javascript src/main/resources/assets/tutorial/models/block/polished_andesite_vertical_slab.json>
 { {
-    "parent": "tutorial:block/side",+    "parent": "tutorial:block/vertical_slab",
     "textures": {     "textures": {
         "bottom": "block/polished_andesite",         "bottom": "block/polished_andesite",
Line 96: Line 100:
  
 ===== Defining rotation and mirroring of blocks ===== ===== Defining rotation and mirroring of blocks =====
-For directional blocks, you may have to override ''rotate'' and ''mirror'' methods, so that in structure blocks, they can be correctly rotated or mirrored.+For directional blocks, you may have to override ''rotate'' and ''mirror'' methods, so that in structure blocks, they can be correctly rotated or mirrored. However, in this case, the ''HorizontalFacingBlock'' class has already done it for you. 
 + 
 +===== Next ===== 
 +Try to make it [[waterloggable]].
tutorial/directionalblock.1643591523.txt.gz · Last modified: 2022/01/31 01:12 by solidblock