User Tools

Site Tools


tutorial:blockappearance

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:blockappearance [2019/08/06 18:34] fudgetutorial:blockappearance [2020/01/17 13:53] – 1.15 juuz
Line 1: Line 1:
 ====== Manipulating a Block's appearance ====== ====== Manipulating a Block's appearance ======
 +
 +//This is the 1.15 version of this tutorial. For the 1.14 version, see [[tutorial:1.14:blockappearance|Manipulating a Block's appearance (1.14)]].//
 +
 ===== Making a block transparent ===== ===== Making a block transparent =====
 You may have noticed that even if your block's texture is transparent, it still looks opaque. You may have noticed that even if your block's texture is transparent, it still looks opaque.
-To fix this, override ''getRenderLayer'' and return ''BlockRenderLayer.TRANSLUCENT'':+To fix this, you need to set your block's render layer to cutout or transparent. 
 + 
 +In a client-sided mod initializer, add:
 <code java> <code java>
-class MyBlock extends Block { +BlockRenderLayerMap.INSTANCE.putBlock(ExampleMod.MY_BLOCK, RenderLayer.getCutout())
-    @Override +// Replace `RenderLayer.getCutout()` with `RenderLayer.getTranslucent()` if you have a translucent texture.
-    public BlockRenderLayer getRenderLayer() { +
-        return BlockRenderLayer.TRANSLUCENT+
-    } +
- +
-    [...+
-+
 </code> </code>
  
Line 18: Line 16:
 <code java> <code java>
 class MyBlock extends Block { class MyBlock extends Block {
-     private static Material myMaterial = new Material( +     private static final Material MY_MATERIAL = new Material( 
-            MaterialColor.AIR,   //materialColor, +            MaterialColor.AIR, // materialColor, 
-            false,   //isLiquid,+            false, // isLiquid,
             false, // isSolid,             false, // isSolid,
             true, // blocksMovement,             true, // blocksMovement,
-            false,// blocksLight,  <----- Important part, the other parts change as you wish +            false, // blocksLight,  <----- Important part, the other parts change as you wish 
-            true,//  !requiresTool, +            true, // !requiresTool, 
-            false, //  burnable, +            false, // burnable, 
-            false,//  replaceable, +            false, // replaceable, 
-            PistonBehavior.NORMAL//  pistonBehavior+            PistonBehavior.NORMAL // pistonBehavior
     );     );
  
     public MyBlock() {     public MyBlock() {
-        super(Settings.of(myMaterial);+        super(Settings.of(MY_MATERIAL));
     }     }
  
Line 48: Line 46:
     }     }
 </code> </code>
-We then need to make our block unselectable by making its `outlineShape` be non-existent. +We then need to make our block unselectable by making its outline shape be non-existent. 
-So override ''getOutlineShape' and return an empty ''VoxelShape'':+So override ''getOutlineShape'' and return an empty ''VoxelShape'':
 <code java> <code java>
     @Override     @Override
     public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) {     public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) {
-       return VoxelShapes.cuboid(0,0,0,0,0,0);+       return VoxelShapes.empty;
     }     }
 </code> </code>
tutorial/blockappearance.txt · Last modified: 2024/02/05 16:03 by haykam