Posted October 14, 20222 yr Hi all! I want to show some data from my BlockEntity in the method renderTooltip of my screen that implements AbstractContainerScreen. But i dont know how to get a reference to the BlockEntity of the block clicched to open the screen. Any suggestions? Thx
October 14, 20222 yr See "synchronizing data to the client" here: https://forge.gemwire.uk/wiki/Block_Entities or https://forums.minecraftforge.net/topic/115679-1182-block-entity-renderer-disappears-after-leaving-the-world/#comment-511734 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
October 14, 20222 yr Author First of all thanks for the quick reply! The problem is that I want to show in the renderTooltip of my screen some data that is already synchronized in my client side blockentity. The method is AbstractContainerScreen.renderTooltip(PoseStack pose, int mousex, int mousey) @Override protected void renderTooltip(PoseStack pose, int mousex, int mousey) { if (menu.getCarried().isEmpty() && hoveredSlot != null && hoveredSlot.hasItem()) { this.renderTooltip(pose, hoveredSlot.getItem(), mousex, mousey); } else if (mousex > leftPos + 94 && mousex < leftPos + 94 + 17 && mousey > topPos + 51 - 17 && mousey < topPos + 51) { List<Component> lines = new ArrayList<Component>(); MyBlockEntity mbe = null;//I dont know how to get a reference to my block entity CompoundTag tag = new CompoundTag(); mbe.saveAdditional(tag); lines.add(Component.literal("tag=" + tag)); lines.add(Component.literal("pos=" + mbe.getBlockPos())); lines.add(Component.literal("line 3")); lines.add(Component.literal("line 4")); lines.add(Component.literal("line 5")); this.renderComponentTooltip(pose, lines, mousex, mousey); } }
October 14, 20222 yr Ah ok. I saw you say rendering and thought this was the usual FAQ. 🙂 Look at forge's NetworkHooks.openScreen() and IContainerFactory extension to the vanilla MenuSupplier that lets you pass additional data to the client. You can see an example of immersive engineering using openScreen() here to pass the BlockEntity's BlockPos https://github.com/BluSunrize/ImmersiveEngineering/blob/4bd8d08d6362a19ed51372b6a3933b6a15853a14/src/main/java/blusunrize/immersiveengineering/common/blocks/IEEntityBlock.java#L303 and retrieving the BlockEntity on the client from the BlockPos by registering the MenuType using the IContainerFactory that gets the additional data https://github.com/BluSunrize/ImmersiveEngineering/blob/4bd8d08d6362a19ed51372b6a3933b6a15853a14/src/main/java/blusunrize/immersiveengineering/common/register/IEMenuTypes.java#L137 Obviously you can just use Minecraft.getInstance().level but you should also check level.isLoaded(BlockPos) if you want to avoid potential crashes. Edited October 14, 20222 yr by warjort Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.