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 [2021/09/26 12:28] – Add reminder to add the client mod initializer to fabric.mod.json skullition
Line 1: Line 1:
 ====== Manipulating a Block's appearance ====== ====== Manipulating a Block's appearance ======
 +
 +//This is the 1.15+ (1.16 and 1.17 work fine too) 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 [[documentation:entrypoint|client-sided mod initializer]], add: 
 +<code java> 
 +BlockRenderLayerMap.INSTANCE.putBlock(ExampleMod.MY_BLOCK, RenderLayer.getCutout()); 
 +// Replace `RenderLayer.getCutout()` with `RenderLayer.getTranslucent()` if you have a translucent texture. 
 +</code> 
 + 
 +You probably also want to make your block transparent. To do that, use the ''nonOpaque'' method on your block settings.
 <code java> <code java>
 class MyBlock extends Block { class MyBlock extends Block {
-    @Override +    public MyBlock() { 
-    public BlockRenderLayer getRenderLayer() { +        super(Settings.of(Material.STONE).nonOpaque());
-        return BlockRenderLayer.TRANSLUCENT;+
     }     }
  
Line 15: Line 25:
 </code> </code>
  
-You probably also want to make your block transparent. To do thatuse the ''Material'' constructor to set ''blocksLight'' to false. +If you do not mark your block as non-opaque like thisthen block faces behind the block will not render and you will be able to see through the world.
-<code java> +
-class MyBlock extends Block { +
-     private static Material myMaterial = new Material( +
-            MaterialColor.AIR,   //materialColor, +
-            false,   //isLiquid, +
-            false, // isSolid, +
-            true, // blocksMovement, +
-            false,// blocksLight,  <----- Important part, the other parts change as you wish +
-            true,//  !requiresTool, +
-            false, //  burnable, +
-            false,//  replaceable, +
-            PistonBehavior.NORMAL//  pistonBehavior +
-    );+
  
-    public MyBlock() { +Be sure to add your client entrypoint to fabric.mod.json
-        super(Settings.of(myMaterial); +You can do this like so: 
-    } +<code json>
- +
-    [...] +
-}+
  
 +  "entrypoints": {
 +    "main": [
 +      "mod.fabricmc.examplemod.ExampleMod"
 +    ],
 +    "client": [
 +      "mod.fabricmc.examplemod.ExampleModClient"
 +    ]
 +  },
 </code> </code>
  
Line 48: Line 50:
     }     }
 </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