ProtocolLib

3M Downloads

Spawn bed

LMS5413 opened this issue ยท 5 comments

commented

Make sure you're doing the following

  • [X ] You're using the latest build for your server version
  • [X ] This isn't an issue caused by another plugin
  • [X ] You've checked for duplicate issues
  • [X ] You didn't use /reload

Describe the question
How can I create a bed?

API method(s) used
PacketContainer

Expected behavior
Im trying but received this error: Internal Exception: io.netty.handler.codec.EncoderException: java.io.IOException: Can't serialize unregistered packet

Code

       PacketContainer bed = new PacketContainer(PacketType.Play.Client.BLOCK_PLACE);
        bed.getBlockPositionModifier().write(0, new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
        bed.getIntegers().write(0, 1);
        bed.getItemModifier().write(0, new ItemStack(Material.BED));

        getProtocolManager().sendServerPacket(p, bed);```
commented

The packet PacketType.Play.Client.BLOCK_PLACE is expected to be send from client to server. However, you are sending it from the server to the client.

You should be using PacketType.Play.Server.BLOCK_CHANGE instead. However, the field of the packet are incorrect in your example. The first field is the BlockPosition, which you provide correctly. This is followed by a WrappedBlockData, that contains the block you want to change. Here is an example how you could do this: https://github.com/lukalt/PacketWrapper/blob/master/src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerBlockChange.java

commented

i don't know

commented

1.8.9

commented

Which Minecraft Version do you want to use?

commented

Its works only 1.19.4 or major