zh_cn:tutorial:extendedscreenhandler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:extendedscreenhandler [2022/02/10 13:19] – [使用扩展的 ScreenHandler 同步数据] timothy_starman | zh_cn:tutorial:extendedscreenhandler [2022/02/10 13:32] (current) – Result timothy_starman | ||
---|---|---|---|
Line 7: | Line 7: | ||
由于 Block 类根本不需要更改,我们将其留在这里。 | 由于 Block 类根本不需要更改,我们将其留在这里。 | ||
- | 我们的方块实体现在实现了 | + | 我们的方块实体现在实现了 |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 106: | Line 106: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ====== 在 Screen 中使用 ExtendedScreenHandler 信息 ====== | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | |||
+ | public class BoxScreen extends HandledScreen< | ||
+ | private static final Identifier TEXTURE = new Identifier(" | ||
+ | |||
+ | public BoxScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { | ||
+ | super(handler, | ||
+ | // | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // | ||
+ | private static Optional< | ||
+ | if (handler instanceof BoxScreenHandler) { | ||
+ | BlockPos pos = ((BoxScreenHandler) handler).getPos(); | ||
+ | return pos != null ? Optional.of(new LiteralText(" | ||
+ | } else { | ||
+ | return Optional.empty(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | @Override | ||
+ | protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { [...] } | ||
+ | |||
+ | @Override | ||
+ | public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { [...] } | ||
+ | |||
+ | @Override | ||
+ | protected void init() { [...] } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== 注册我们的 ScreenHandler ====== | ||
+ | |||
+ | <code java [enable_line_numbers=" | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | [...] | ||
+ | public static final ScreenHandlerType< | ||
+ | |||
+ | static { | ||
+ | [...] | ||
+ | |||
+ | // | ||
+ | BOX_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(BOX, | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====== 结果 ====== | ||
+ | 您现在已经了解了如何在 ScreenHandler 打开时传输数据。 在图像中您可以看到结果:方块的标题现在是它的位置。 | ||
+ | 请注意,这只是一个演示,还有更简单的方法可以将位置设置为标题。 | ||
+ | |||
+ | 您可能想知道:// | ||
+ | 这可以通过在屏幕打开后发送自定义数据包来实现。 (see: [[tutorial: | ||
+ | 您可能还想看看'' | ||
+ | |||
+ | 如果您只想同步整数值,您可以使用'' | ||
+ | |||
+ | {{: | ||
+ | |||
zh_cn/tutorial/extendedscreenhandler.1644499180.txt.gz · Last modified: 2022/02/10 13:19 by timothy_starman