Packet Lectern Block State Change
Make sure you're doing the following
- [✓] You're using the latest build for your server version
- [✓] This isn't an issue caused by another plugin
- [✓] You've checked for duplicate issues
- [✓] You didn't use
/reload
Describe the question How to properly install a book into a lectern using the TILE_ENTITY_DATA packet?
API method(s) used ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.TILE_ENTITY_DATA)
Expected behavior When a book appears in a fake lectern, the main thing is that it is visual.
Code
val position = block.position
block.setFakeData(NbtFactory.ofCompound("").apply {
put("id", "minecraft:lectern")
put("x", position.x)
put("y", position.y)
put("z", position.z)
put("Book", NbtFactory.ofCompound("").apply {
put(NbtFactory.of("Count", 1.toByte()))
put(NbtFactory.of("id", "minecraft:written_book"))
})
put("Page", 0)
}.print(), player)
private fun Block.setFakeData(nbt: NbtCompound, player: Player) {
val packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.TILE_ENTITY_DATA).apply {
blockPositionModifier.write(0, position)
blockEntityTypeModifier.write(0, WrappedRegistrable.blockEntityType("lectern"))
nbtModifier.write(0, nbt)
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player,packet)
}
Additional context Initially, the packet block is already installed and visually observed by the player. Sending a block state change packet, occurs after sending the BLOCK_CHANGE with lectern.
Server version 1.19.4
NBT instance in console -
{"name": "", "Book": {"name": "Book", "Count": 1, "id": "minecraft:written_book"}, "x": 20, "y": 61, "z": 7, "Page": 0, "id": "minecraft:lectern"}