Error receiving packet 82, problem while converting bukkit ItemStack to nms ItemStack
SquidXTV opened this issue ยท 1 comments
- This issue is not solved in a development build
Describe the bug
Trying to send map into item frame entity using ProtocolLib.
Getting error which causes the map to fail getting send over.
To Reproduce
Steps to reproduce the behavior:
- create PacketContainer, SPAWN_ENTITY
- create PacketContainer, ENTITY_METADATA
- change ENTITY_METADATA to hold a map (ItemStack)
- send over packets to the player
->
[22:29:28] [Netty Server IO #0/ERROR]: Error receiving packet 82
java.lang.ClassCastException: class org.bukkit.inventory.ItemStack cannot be cast to class net.minecraft.world.item.ItemStack (org.bukkit.inventory.ItemStack and net.minecraft.world.item.ItemStack are in unnamed module of loader java.net.URLClassLoader @46ee7fe8)
at net.minecraft.network.syncher.DataWatcherRegistry$1.a(SourceFile:49) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.syncher.DataWatcher$b.a(DataWatcher.java:323) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata.a(SourceFile:22) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata.a(SourceFile:41) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.PacketEncoder.a(SourceFile:45) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.PacketEncoder.encode(SourceFile:14) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:306) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at net.minecraft.network.NetworkManager.a(NetworkManager.java:231) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at net.minecraft.network.NetworkManager.lambda$7(NetworkManager.java:220) ~[spigot-1.19.4-R0.1-SNAPSHOT.jar:3763-Spigot-7d7b241-5a5e43e]
at com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:48) ~[?:?]
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.82.Final.jar:4.1.82.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) ~[netty-common-4.1.82.Final.jar:4.1.82.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) ~[netty-common-4.1.82.Final.jar:4.1.82.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[netty-transport-4.1.82.Final.jar:4.1.82.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.82.Final.jar:4.1.82.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.82.Final.jar:4.1.82.Final]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Expected behavior
Successfully change item frames item (map).
Version Info
Dump
Additional context
Code:
public static class ItemFrameDataPacket extends PacketContainer {
public ItemFrameDataPacket(int entityId) {
super(PacketType.Play.Server.ENTITY_METADATA);
getModifier().writeDefaults();
getIntegers().write(0, entityId);
}
public void setInvisible(boolean invisible) {
List<WrappedDataValue> values = List.of(
new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) (invisible ? 0x20 : 0))
);
getDataValueCollectionModifier().writeSafely(0, values);
}
public void setMap(@NotNull ItemStack map) {
if (map.getType() != Material.FILLED_MAP) {
throw new IllegalArgumentException("ItemStack must be of type FILLED_MAP.");
}
List<WrappedDataValue> values = List.of(
new WrappedDataValue(8, WrappedDataWatcher.Registry.getItemStackSerializer(false), BukkitConverters.getItemStackConverter().getGeneric(map))
);
getDataValueCollectionModifier().writeSafely(0, values);
}
}