zh_cn:tutorial:blockappearance
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:blockappearance [2019/12/19 05:53] – lightcolour | zh_cn:tutorial:blockappearance [2024/08/27 04:22] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 操纵方块的外观 ====== | ====== 操纵方块的外观 ====== | ||
- | ===== 使方块透明 ===== | + | // |
- | 您可能已经注意到,即使块的纹理是透明的,它仍然看起来是不透明的。 | + | ===== 使方块透明或半透明 ===== |
- | 要解决此问题,请覆盖'' | + | 你可能已经注意到,即使方块的纹理是透明或半透明的,看起来仍是不透明的。如需解决,请将方块的渲染层设为 cutout 或 transparent。 |
- | <code java> | + | |
- | class MyBlock extends Block { | + | 在[[zh_cn: |
- | @Override | + | <yarncode |
- | public | + | @Environment(EnvType.CLIENT) |
- | | + | public |
+ | public | ||
+ | | ||
+ | BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, | ||
+ | |||
+ | // 如果方块一些部分是半透明的(例如冰、染色玻璃、传送门): | ||
+ | BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, | ||
} | } | ||
- | |||
- | [...] | ||
} | } | ||
+ | </ | ||
- | </code> | + | 您可能还想使方块非不透明。为此,可在方块设置中使用 '' |
- | 您可能还想使方块透明。 为此,请使用Material构造函数将'' | + | <yarncode |
- | <code java> | + | public |
- | class MyBlock extends Block { | + | </yarncode> |
- | private | + | |
- | MaterialColor.AIR, // | + | |
- | | + | |
- | false, // isSolid, | + | |
- | true, // blocksMovement, | + | |
- | false,// blocksLight, | + | |
- | true,// !requiresTool, | + | |
- | false, // burnable, | + | |
- | false,// | + | |
- | PistonBehavior.NORMAL// | + | |
- | ); | + | |
- | public MyBlock() { | + | 如果你不像这样把方块标记为非不透明的,则方块后面的面不会渲染,你将会“看穿”整个世界(到虚空或渲染范围之外之类的)。 |
- | super(Settings.of(myMaterial); | + | |
- | } | + | |
- | | + | 确保在 [[documentation: |
+ | <code javascript> | ||
+ | { | ||
+ | [...] | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | }, | ||
+ | | ||
} | } | ||
- | |||
</ | </ | ||
+ | 注意:对于不透明但不完整的方块,你可能需要覆盖 ''< | ||
===== 使方块不可见 ===== | ===== 使方块不可见 ===== | ||
- | 首先,我们需要使该方块看起来不可见。 | + | 首先,我们需要使该方块看起来不可见。为此,我们在方块类中重写 '' |
- | 为此,我们在块类中重写'' | + | <yarncode |
- | <code java> | + | |
@Override | @Override | ||
- | public | + | public |
- | return | + | return |
} | } | ||
- | </code> | + | </yarncode> |
- | 然后,我们需要通过使其'' | + | |
- | 因此,覆盖'' | + | 然后,我们需要通过使其形状不存在,从而使方块不能被选中。因此,覆盖 '' |
- | <code java> | + | |
+ | <yarncode | ||
@Override | @Override | ||
- | public | + | public |
- | | + | |
} | } | ||
- | </code> | + | </yarncode> |
zh_cn/tutorial/blockappearance.1576734784.txt.gz · Last modified: 2019/12/19 05:53 by lightcolour