ProtocolLib

3M Downloads

clientbound/minecraft:set_entity_data

ssomar1607 opened this issue ยท 1 comments

commented

This issue is not solved in a development build

Error

io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:set_entity_data'
        at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:55) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:13) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:27) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:12) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[netty-codec-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:120) ~[netty-codec-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) ~[netty-codec-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:875) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:984) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:868) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.ChannelOutboundHandlerAdapter.write(ChannelOutboundHandlerAdapter.java:113) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at net.minecraft.network.Connection$2.write(Connection.java:728) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:893) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:956) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:982) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:950) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:969) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:310) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at ProtocolLib(5).jar/com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.writeAndFlush(NettyChannelProxy.java:227) ~[ProtocolLib(5).jar:?]
        at ProtocolLib(5).jar/com.comphenix.protocol.injector.netty.channel.NettyChannelProxy.writeAndFlush(NettyChannelProxy.java:233) ~[ProtocolLib(5).jar:?]
        at net.minecraft.network.Connection.doSendPacket(Connection.java:492) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.Connection.lambda$sendPacket$13(Connection.java:479) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at ProtocolLib(5).jar/com.comphenix.protocol.injector.netty.channel.NettyEventLoopProxy.lambda$proxyRunnable$2(NettyEventLoopProxy.java:49) ~[ProtocolLib(5).jar:?]
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173) ~[netty-common-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166) ~[netty-common-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[netty-common-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) ~[netty-transport-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.115.Final.jar:4.1.115.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.115.Final.jar:4.1.115.Final]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]
Caused by: java.lang.ClassCastException: class net.minecraft.network.syncher.SynchedEntityData$DataItem cannot be cast to class net.minecraft.network.syncher.SynchedEntityData$DataValue (net.minecraft.network.syncher.SynchedEntityData$DataItem and net.minecraft.network.syncher.SynchedEntityData$DataValue are in unnamed module of loader java.net.URLClassLoader @4dcbadb4)
        at net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket.pack(ClientboundSetEntityDataPacket.java:23) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket.write(ClientboundSetEntityDataPacket.java:44) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.codec.StreamCodec$2.encode(StreamCodec.java:40) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:90) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.codec.StreamCodec$5.encode(StreamCodec.java:80) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        at net.minecraft.network.codec.IdDispatchCodec.encode(IdDispatchCodec.java:53) ~[paper-1.21.4.jar:1.21.4-53-326c687]
        ... 38```
        
   Code
 ```int entityId = (int) (Math.random() * Integer.MAX_VALUE);
        UUID uuid = UUID.randomUUID();

        // Create spawn packet
        PacketContainer spawnPacket = protocolManager.createPacket(PacketType.Play.Server.SPAWN_ENTITY);

        spawnPacket.getIntegers()
                .write(0, entityId); // Entity ID

        spawnPacket.getUUIDs()
                .write(0, uuid); // Entity UUID

        spawnPacket.getEntityTypeModifier()
                .write(0, EntityType.SHULKER); // Entity Type


        // Set position
        spawnPacket.getDoubles()
                .write(0, location.getX())
                .write(1, location.getY())
                .write(2, location.getZ());

        // Set rotation
        spawnPacket.getBytes()
                .write(0, (byte) (location.getYaw() * 256.0F / 360.0F))
                .write(1, (byte) (location.getPitch() * 256.0F / 360.0F));


        PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
        packet.getIntegers().write(0, entityId);
        WrappedDataWatcher watcher = new WrappedDataWatcher();
        WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
        watcher.setEntity(null);
        watcher.setObject(0, serializer, (byte) 0x40 );
        packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());



        try {
            // Send spawn packet
            protocolManager.sendServerPacket(player, spawnPacket);

            protocolManager.sendServerPacket(player, packet);



            return entityId;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }```
commented

I also get the same error with the following code:

        // Create a new PacketContainer for the Entity Metadata packet
        PacketContainer metadatapacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);

        // Set the entity ID
        metadatapacket.getIntegers().write(0, entityId);

        WrappedDataWatcher metadata = new WrappedDataWatcher();
        metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) (0x20)); //set invis 
        
        metadatapacket.getWatchableCollectionModifier().write(0, metadata.getWatchableObjects());

        // Send the packet to all players
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, metadatapacket);