tutorial:extendedscreenhandler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:extendedscreenhandler [2020/08/14 16:38] – [Registering our ScreenHandler] manymoney2 | tutorial:extendedscreenhandler [2022/05/27 15:59] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Syncing Custom Data with Extended ScreenHandlers ====== | ====== Syncing Custom Data with Extended ScreenHandlers ====== | ||
- | In this tutorial we will use the ExtendedScreenHandler to transfer arbitary data from the Server | + | In this tutorial we will use the ExtendedScreenHandler to transfer arbitary data from the server |
- | In our example we will send the position of the block and render it as the containers | + | In our example we will send the position of the block and render it as the container' |
To understand this tutorial you need to read the first [[tutorial: | To understand this tutorial you need to read the first [[tutorial: | ||
- | Methods which have no code here were already shown in that tutorial | + | Methods which have no code here were already shown in that tutorial. |
====== BlockEntity ====== | ====== BlockEntity ====== | ||
As the Block class does not need to be changed at all we leave it out here. | As the Block class does not need to be changed at all we leave it out here. | ||
- | Our blockEntity | + | Our block entity |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 41: | Line 41: | ||
@Override | @Override | ||
public Text getDisplayName() { | public Text getDisplayName() { | ||
+ | // versions 1.18 and below | ||
return new TranslatableText(getCachedState().getBlock().getTranslationKey()); | return new TranslatableText(getCachedState().getBlock().getTranslationKey()); | ||
+ | | ||
+ | // versions 1.19 and later | ||
+ | return Text.translatable(getCachedState().getBlock().getTranslationKey()); | ||
} | } | ||
Line 127: | Line 131: | ||
if (handler instanceof BoxScreenHandler) { | if (handler instanceof BoxScreenHandler) { | ||
BlockPos pos = ((BoxScreenHandler) handler).getPos(); | BlockPos pos = ((BoxScreenHandler) handler).getPos(); | ||
- | return pos != null ? Optional.of(new LiteralText(" | + | |
+ | | ||
} else { | } else { | ||
return Optional.empty(); | return Optional.empty(); | ||
Line 169: | Line 174: | ||
====== Result ====== | ====== Result ====== | ||
- | You have now seen how to transfer data when the ScreenHandler is opened. In the image you can see the result: The Blocks | + | You have now seen how to transfer data when the ScreenHandler is opened. In the image you can see the result: The Block' |
- | Setting | + | there are easier ways of setting |
+ | |||
+ | You might be wondering: //Can I transfer this data again even after the Screen was opened?// | ||
+ | This is possible | ||
+ | You might also want to have a look at the '' | ||
+ | |||
+ | If you only want to sync integer values you can use '' | ||
{{: | {{: | ||
tutorial/extendedscreenhandler.txt · Last modified: 2022/12/17 15:38 by miir