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
Last revisionBoth sides next revision
zh_cn:tutorial:blockappearance [2019/12/19 05:53] lightcolourzh_cn:tutorial:blockappearance [2023/05/04 11:32] – [操纵方块的外观] 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> +
-class MyBlock extends Block { +
-    @Override +
-    public BlockRenderLayer getRenderLayer() { +
-        return BlockRenderLayer.TRANSLUCENT; +
-    } +
- +
-    [...] +
-+
- +
-</code> +
- +
-您可能还想使方块透明。 为此,请使用Material构造函数将''blocksLight''false +
-<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() { +在[[zh_cn:documentation:entrypoint|客户端模组初始化器]]中,添加: 
-        super(Settings.of(myMaterial);+<yarncode java> 
 +@Environment(EnvType.CLIENT) 
 +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>
  
-</code>+您可能还想使方块透明。为此,可在方块设置中使用 ''<yarn method_22488>'' 方法。 
 +<yarncode java> 
 +     public static final Block MY_BLOCK = new Block(FabricBlockSettings.of(...).method_22488()); 
 +</yarncode> 
 +如果你不像这样把方块标记为非不透明的,则方块后面的面不会渲染,你将会“看穿”整个世界(到虚空或渲染范围之外之类的)。
  
 ===== 使方块不可见 ===== ===== 使方块不可见 =====
-首先,我们需要使该方块看起来不可见。 +首先,我们需要使该方块看起来不可见。为此,我们在块类中重写 ''<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.txt · Last modified: 2023/11/18 08:40 by solidblock