ProtocolLib

3M Downloads

can't convert Byte to Integer, working on 1.16

leChapelierFou-D opened this issue ยท 3 comments

commented

Describe the bug
I create some fakePlayers on my server for interacting with real players.
I have update to 1.17 and some errors appears, I have fix someones like EnumWrappers.NativeGameMode.NOT_SET (this enum value from minecraft not exist in 1.17).

To Reproduce
With ENTITY_METADATA (because: PacketPlayOutEntityMetadata) I have this error:
[14:36:23] [Netty Epoll Server IO #1/ERROR]: Packet encoding of packet ID 77 threw (skippable? false) java.lang.ClassCastException: class java.lang.Byte cannot be cast to class java.lang.Integer (java.lang.Byte and java.lang.Integer are in module java.base of loader 'bootstrap') at net.minecraft.network.syncher.DataWatcherRegistry$12.a(DataWatcherRegistry.java:44) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.syncher.DataWatcher.a(DataWatcher.java:231) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.syncher.DataWatcher.a(DataWatcher.java:168) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata.a(PacketPlayOutEntityMetadata.java:34) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:44) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.PacketEncoder.encode(PacketEncoder.java:15) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at jdk.internal.reflect.GeneratedMethodAccessor17.invoke(Unknown Source) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] at com.comphenix.protocol.injector.netty.ChannelInjector.encode(ChannelInjector.java:528) ~[?:?] at com.comphenix.protocol.injector.netty.ChannelInjector.access$100(ChannelInjector.java:70) ~[?:?] at com.comphenix.protocol.injector.netty.ChannelInjector$1.encode(ChannelInjector.java:268) ~[?:?] at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at com.comphenix.protocol.injector.netty.ChannelInjector$1.write(ChannelInjector.java:274) ~[?:?] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:306) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at com.comphenix.protocol.injector.netty.ChannelProxy.writeAndFlush(ChannelProxy.java:327) ~[?:?] at net.minecraft.network.NetworkManager.a(NetworkManager.java:315) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at net.minecraft.network.NetworkManager.lambda$sendPacket$4(NetworkManager.java:295) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at com.comphenix.protocol.injector.netty.ChannelInjector$3.lambda$onMessageScheduled$1(ChannelInjector.java:351) ~[?:?] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:387) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[patched_1.17.jar:git-Paper-"33d6b6f"] at java.lang.Thread.run(Thread.java:831) [?:?]

commented

Can you share the code you're using?

commented

hum, I have remove:

            var wo3D = watcher.getWatchableObject(index3D);
            var woPose = watcher.getWatchableObject(indexPose);
            watcher.clear();
            wo3D.setValue(value3D);
            watcher.setObject(wo3D.getWatcherObject(), wo3D);
            watcher.setObject(woPose.getWatcherObject(), woPose);

And now that works again.

commented

I save one watcher for any FakePlayer copied from the first Player.

    protected WrappedDataWatcher getDefaultWatcher(Player player, Pose entityPose) {
        if (watcher == null) {
            watcher = WrappedDataWatcher.getEntityWatcher(player).deepClone();
            var wo3D = watcher.getWatchableObject(index3D);
            var woPose = watcher.getWatchableObject(indexPose);
            watcher.clear();
            wo3D.setValue(value3D);
            watcher.setObject(wo3D.getWatcherObject(), wo3D);
            watcher.setObject(woPose.getWatcherObject(), woPose);

        }
        if (entityPose != null) {
            watcher.setObject(indexPose, WrappedDataWatcher.Registry.get(EnumWrappers.getEntityPoseClass()), mapPoseToNMS.get(entityPose));
        }
        return watcher;
    }

public static PacketContainer createPacketEM(int entityID, WrappedDataWatcher watcher) {
		var emPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
		//emPacket.getModifier().writeDefaults();
		emPacket.getIntegers().write(0, entityID);

        if(watcher!=null) {
        	emPacket.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
        }
		return emPacket;
	}