User Tools

Site Tools


zh_cn:tutorial:blockappearance

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
zh_cn:tutorial:blockappearance [2019/12/19 05:39] – created lightcolourzh_cn:tutorial:blockappearance [2023/11/18 08:40] (current) – [使方块透明] solidblock
Line 1: Line 1:
-====== Manipulating a Block's appearance ====== +====== 操纵方块的外观 ====== 
-===== Making a block transparent ===== +//这是教程的 1.15+ (对 1.16、1.17、1.18 和 1.19 也适用)版本。如需1.14版本,请参考[[zh_cn:tutorial:1.14:blockappearance|操纵方块的外观(1.14)]]。// 
-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''+您可能已经注意到,即使方块的材质是透明的,它仍然看起来是不透明的。如需解决,请将方块的渲染层设为 cutout 或 transparent 
-<code java> + 
-class MyBlock extends Block { +在[[zh_cn:documentation:entrypoint|客户端模组初始化器]]中,添加: 
-    @Override +<yarncode java> 
-    public BlockRenderLayer getRenderLayer() { +@Environment(EnvType.CLIENT) 
-        return BlockRenderLayer.TRANSLUCENT;+public class ExampleModClient implements ClientModInitializer() 
 +    public void onInitializeClient() { 
 +         BlockRenderLayerMap.INSTANCE.putBlock(ExampleMod.MY_BLOCK, class_1921.method_23581()); 
 +         // 如果有半透明纹理,可以将`class_1921.method_23581()` 替换为 `class_1921.method_23583()`。
     }     }
- 
-    [...] 
 } }
 +</yarncode>
  
 +您可能还想使方块透明。为此,可在方块设置中使用 ''<yarn method_22488>'' 方法。
 +<yarncode java>
 +     public static final Block MY_BLOCK = new Block(FabricBlockSettings.create().method_22488());
 +</yarncode>
 +如果你不像这样把方块标记为非不透明的,则方块后面的面不会渲染,你将会“看穿”整个世界(到虚空或渲染范围之外之类的)。
 +
 +确保在 ''fabric.mod.json'' 中添加了客户端入口点,你可以这样做:
 +<code json>
 +  "entrypoints": {
 +    "main": [
 +      "mod.fabricmc.examplemod.ExampleMod"
 +    ],
 +    "client": [
 +      "mod.fabricmc.examplemod.ExampleModClient"
 +    ]
 +  },
 </code> </code>
 +注意:对于不透明但不完整的方块,你可能需要覆盖 ''<yarn method_9530>'' 方法并返回非完整的图形,以避免看穿整个世界。
  
-You probably also want to make your block transparent. To do that, use the ''Material'' constructor to set ''blocksLight'' to false. +===== 使方块不可见 ===== 
-<code java> +首先,我们需要使该方块看起来不可见。为此,我们在方块类中重写 ''<yarn method_9604>'' 并返回 ''<yarn class_2464>.<yarn field_11455>'' 
-class MyBlock extends Block { +<yarncode java> 
-     private static Material myMaterial = new Material( +    @Override 
-            MaterialColor.AIR,   //materialColor, +    public class_2464 method_9604(class_2680 state) { 
-            false,   //isLiquid, +        return class_2464.field_11455;
-            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() { +
-        super(Settings.of(myMaterial);+
     }     }
 +</yarncode>
  
-    [...] +然后,我们需要通过使其 ''outlineShape'' 不存在来使我们的方块不能被选中。因此,覆盖 ''<yarn method_9530>'' 并返回一个空的 ''<yarn class_265>''
-+
- +
-</code>+
  
-===== Making a block invisible ===== +<yarncode java>
-First we need to make the block appear invisible. +
-To do this we override ''getRenderType'' in our block class and return ''BlockRenderType.INVISIBLE'': +
-<code java>+
     @Override     @Override
-    public BlockRenderType getRenderType(BlockState blockState) { +    public class_265 method_9530(class_2680 state, class_1922 blockView, class_2338 pos, class_3726 context) { 
-        return BlockRenderType.INVISIBLE;+       return class_259.method_1073();
     }     }
-</code> +</yarncode>
-We then need to make our block unselectable by making its `outlineShape` be non-existent. +
-So override ''getOutlineShape' and return an empty ''VoxelShape'': +
-<code java> +
-    @Override +
-    public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) { +
-       return VoxelShapes.cuboid(0,0,0,0,0,0); +
-    } +
-</code>+
zh_cn/tutorial/blockappearance.1576733995.txt.gz · Last modified: 2019/12/19 05:39 by lightcolour