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
tutorial:blockappearance [2020/01/17 13:42] – 1.14 fixes juuztutorial:blockappearance [2024/08/26 08:28] (current) solidblock
Line 1: Line 1:
 ====== Manipulating a Block's appearance ====== ====== Manipulating a Block's appearance ======
-===== Making a block transparent ===== 
-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'': 
-<code java> 
-class MyBlock extends Block { 
-    @Override 
-    public BlockRenderLayer getRenderLayer() { 
-        return BlockRenderLayer.TRANSLUCENT; 
-    } 
  
-    [...] +//This is the 1.15+ version of this tutorialFor the 1.14 version, see [[tutorial:1.14:blockappearance|Manipulating a Block's appearance (1.14)]].//
-}+
  
-</code>+===== Making a block transparent or translucent ===== 
 +You may have noticed that even if your block's texture is transparent or translucent, it still looks opaque. To fix this, you need to set your block's render layer to cutout or transparent.
  
-You probably also want to make your block transparent. To do that, use the ''Material'' constructor to set ''blocksLight'' to false. +In a [[documentation:entrypoint|client-sided mod initializer]]:
-<code java> +
-class MyBlock extends Block { +
-     private static final Material MY_MATERIAL = 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() { +<yarncode java> 
-        super(Settings.of(MY_MATERIAL));+@Environment(EnvType.CLIENT) 
 +public class ExampleModClient implements ClientModInitializer() { 
 +    public void onInitializeClient() { 
 +        // To make some parts of the block transparent (like glass, saplings and doors): 
 +        BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, class_1921.method_23581()); 
 +         
 +        // To make some parts of the block translucent (like ice, stained glass and portal) 
 +        BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, class_1921.method_23583());
     }     }
- 
-    [...] 
 } }
 +</yarncode>
  
 +You probably also want to make your block non-opaque. To do that, use the ''<yarn method_22488>'' method on your block settings. This will also make sides render inside.
 +
 +<yarncode java>
 +     public static final Block MY_BLOCK = new Block(AbstractBlock.Settings.create().method_22488());
 +</yarncode>
 +
 +If you do not mark your block as non-opaque like this, then block faces behind the block will not render and you will be able to see through the world.
 +
 +Be sure to add your client entrypoint to [[documentation:fabric_mod_json|fabric.mod.json]]. You can do this like so:
 +<code javascript>
 +{
 +  [...]
 +  "entrypoints": {
 +    "main": [
 +      "net.fabricmc.example.ExampleMod"
 +    ],
 +    "client": [
 +      "net.fabricmc.example.ExampleModClient"
 +    ]
 +  },
 +  [...]
 +}
 </code> </code>
 +
 +Note: For non-transparent blocks that are not full, you may have to override the ''<yarn method_9530>'' method to return a non-full shape to avoid seeing through the world.
  
 ===== Making a block invisible ===== ===== Making a block invisible =====
-First we need to make the block appear invisible. + 
-To do this we override ''getRenderType'' in our block class and return ''BlockRenderType.INVISIBLE'': +First we need to make the block appear invisible. To do thiswe override ''<yarn method_9604>'' in our block class and return ''<yarn class_2464>.<yarn field_11455>'': 
-<code java>+ 
 +<yarncode java>
     @Override     @Override
-    public BlockRenderType getRenderType(BlockState blockState) { +    public class_2464 method_9604(class_2680 state) { 
-        return BlockRenderType.INVISIBLE;+        return class_2464.field_11455;
     }     }
-</code+</yarncode> 
-We then need to make our block unselectable by making its outline shape be non-existent. + 
-So override ''getOutlineShape'' and return an empty ''VoxelShape'': +We may also need to make our block unselectable by making its outline shape be non-existent. So override ''<yarn method_9530>'' and return an empty ''<yarn class_265>'': 
-<code java>+ 
 +<yarncode java>
     @Override     @Override
-    public VoxelShape getOutlineShape(BlockState blockStateBlockView blockView, BlockPos blockPosEntityContext entityContext) { +    public class_265 method_9530(class_2680 stateclass_1922 blockView, class_2338 posclass_3726 context) { 
-       return VoxelShapes.empty;+       return class_259.method_1073();
     }     }
-</code>+</yarncode>
tutorial/blockappearance.1579268533.txt.gz · Last modified: 2020/01/17 13:42 by juuz