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

Both sides previous revisionPrevious revision
Next revision
Previous revision
zh_cn:tutorial:blockappearance [2019/12/19 05:53] lightcolourzh_cn:tutorial:blockappearance [2023/11/18 08:40] (current) – [使方块透明] solidblock
Line 1: Line 1:
 ====== 操纵方块的外观 ====== ====== 操纵方块的外观 ======
 +//这是教程的 1.15+ (对 1.16、1.17、1.18 和 1.19 也适用)版本。如需1.14版本,请参考[[zh_cn:tutorial:1.14:blockappearance|操纵方块的外观(1.14)]]。//
 ===== 使方块透明 ===== ===== 使方块透明 =====
-您可能已经注意到,即使块的纹理是透明的,它仍然看起来是不透明的。 +您可能已经注意到,即使块的材质是透明的,它仍然看起来是不透明的。如需解决,请将方块的渲染层设为 cutout 或 transparent。 
-解决此问题,请覆盖''getRenderLayer''并返回''BlockRenderLayer.TRANSLUCENT'': + 
-<code java> +在[[zh_cn:documentation:entrypoint|客户端模组初始化器]]中,添加: 
-class MyBlock extends Block { +<yarncode java> 
-    @Override +@Environment(EnvType.CLIENT) 
-    public BlockRenderLayer getRenderLayer() { +public class ExampleModClient implements ClientModInitializer() 
-        return BlockRenderLayer.TRANSLUCENT;+    public void onInitializeClient() { 
 +         BlockRenderLayerMap.INSTANCE.putBlock(ExampleMod.MY_BLOCK, class_1921.method_23581()); 
 +         // 如果有半透明纹理,可以将`class_1921.method_23581()` 替换为 `class_1921.method_23583()`。
     }     }
- 
-    [...] 
 } }
 +</yarncode>
  
-</code> +您可能还想使方块透明。为此,可在方块设置中使用 ''<yarn method_22488>'' 方法。 
- +<yarncode java> 
-您可能还想使方块透明。 为此,使用Material构造函数将''blocksLight''设置为false。 +     public static final Block MY_BLOCK = new Block(FabricBlockSettings.create().method_22488()); 
-<code java> +</yarncode> 
-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() +
-        super(Settings.of(myMaterial); +
-    } +
- +
-    [...] +
-}+
  
 +确保在 ''fabric.mod.json'' 中添加了客户端入口点,你可以这样做:
 +<code json>
 +  "entrypoints": {
 +    "main": [
 +      "mod.fabricmc.examplemod.ExampleMod"
 +    ],
 +    "client": [
 +      "mod.fabricmc.examplemod.ExampleModClient"
 +    ]
 +  },
 </code> </code>
 +注意:对于不透明但不完整的方块,你可能需要覆盖 ''<yarn method_9530>'' 方法并返回非完整的图形,以避免看穿整个世界。
  
 ===== 使方块不可见 ===== ===== 使方块不可见 =====
-首先,我们需要使该方块看起来不可见。 +首先,我们需要使该方块看起来不可见。为此,我们在块类中重写 ''<yarn method_9604>'' 并返回 ''<yarn class_2464>.<yarn field_11455>'': 
-为此,我们在块类中重写''getRenderType''并返回''BlockRenderType.INVISIBLE'': +<yarncode java>
-<code 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> 
-然后,我们需要通过使其''outlineShape''不存在来使我们的块不 + 
-因此,覆盖''getOutlineShape''并返回一个空的''VoxelShape'': +然后,我们需要通过使其 ''outlineShape'' 不存在来使我们的块不能被。因此,覆盖 ''<yarn method_9530>'' 并返回一个空的 ''<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.cuboid(0,0,0,0,0,0);+       return class_259.method_1073();
     }     }
-</code>+</yarncode>
zh_cn/tutorial/blockappearance.1576734784.txt.gz · Last modified: 2019/12/19 05:53 by lightcolour