Jump to content

[1.16.5] How to send the instruction to open the "written book" GUI from the Server-Side (with text)


IsaacDeadGod

Recommended Posts

If anyone can help me with this . I'm creating a command to open the GUI of a book.
Supposedly this should work. But it doesn't do anything. Can somebody help me?
Forge 1.16.5 - Server Side Mod

 

dispatcher.register(
                Commands.literal("dummyCommand")
                        .executes(context -> {
                            
                            ItemStack book = new ItemStack(Items.WRITTEN_BOOK);

                            CompoundNBT nbt = new CompoundNBT();

                            ListNBT pages = new ListNBT();

                            pages.add(StringNBT.valueOf("{\"text\":\"Hello World\"}"));

                            nbt.putString("author", "Steve");
                            nbt.putString("title", "my_book");
                            nbt.put("pages", pages);
                            nbt.putByte("resolved", (byte) 1);

                            book.setTag(nbt);
                            
                            context.getSource().getPlayerOrException().openItemGui(book, Hand.MAIN_HAND);
                            return 1;
                        })
        );


I have tried with "SOpenBookWindowPacket" but it only sends the instruction to open a book that the user has in their hand.

ServerPlayerEntity serverPlayerEntity = context.getSource().getPlayerOrException();
                            SOpenBookWindowPacket packet = new SOpenBookWindowPacket(serverPlayerEntity.getUsedItemHand());
                            serverPlayerEntity.connection.send(packet);


The idea is that this mod is an information command for the user. You should not give a book to the user and have them read it. I have seen the Spigot documentation and have found some examples of how this is done on servers.

PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload("MC|BOpen", new PacketDataSerializer(buf));


Is there a way to do this with Forge Server Side? I've been dealing with this for 2 days and I can't find a solution. I've searched on Google and can't find anything.

spacer.png

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.