====== 操纵方块的外观 ====== //这是教程的 1.15+ (对 1.16、1.17、1.18 和 1.19 也适用)版本。如需1.14版本,请参考[[zh_cn:tutorial:1.14:blockappearance|操纵方块的外观(1.14)]]。// ===== 使方块透明 ===== 您可能已经注意到,即使方块的材质是透明的,它仍然看起来是不透明的。如需解决,请将方块的渲染层设为 cutout 或 transparent。 在[[zh_cn:documentation:entrypoint|客户端模组初始化器]]中,添加: @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()`。 } } 您可能还想使方块透明。为此,可在方块设置中使用 '''' 方法。 public static final Block MY_BLOCK = new Block(FabricBlockSettings.create().method_22488()); 如果你不像这样把方块标记为非不透明的,则方块后面的面不会渲染,你将会“看穿”整个世界(到虚空或渲染范围之外之类的)。 确保在 ''fabric.mod.json'' 中添加了客户端入口点,你可以这样做: "entrypoints": { "main": [ "mod.fabricmc.examplemod.ExampleMod" ], "client": [ "mod.fabricmc.examplemod.ExampleModClient" ] }, 注意:对于不透明但不完整的方块,你可能需要覆盖 '''' 方法并返回非完整的图形,以避免看穿整个世界。 ===== 使方块不可见 ===== 首先,我们需要使该方块看起来不可见。为此,我们在方块类中重写 '''' 并返回 ''.'': @Override public class_2464 method_9604(class_2680 state) { return class_2464.field_11455; } 然后,我们需要通过使其 ''outlineShape'' 不存在来使我们的方块不能被选中。因此,覆盖 '''' 并返回一个空的 '''': @Override public class_265 method_9530(class_2680 state, class_1922 blockView, class_2338 pos, class_3726 context) { return class_259.method_1073(); }