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.