ProtocolLib

3M Downloads

Error when sending PacketType.Play.Server.MAP to client on 1.17.1

nghuy1610 opened this issue ยท 7 comments

commented

Describe the bug
I want to modify the filled map display on client so I use protocol lib to send a PacketType.Play.Server.MAP packet. It used to work on 1.16.5 but now it doesn't on 1.17.1.

The code in use

byte[] bytes = MapPalette.imageToBytes(image);
WrapperPlayServerMap mapDataPacket = new WrapperPlayServerMap();
mapDataPacket.setItemDamage(mapId);
mapDataPacket.setScale((byte) 4);
mapDataPacket.setTrackingPosition(false);
mapDataPacket.setLocked(false);
mapDataPacket.setColumns(0);
mapDataPacket.setRows(0);
mapDataPacket.setX(Config.IMAGE_SIZE);
mapDataPacket.setZ(Config.IMAGE_SIZE);
mapDataPacket.setData(bytes);
ImgMapperPlugin.getProtocolManager().sendServerPacket(player, mapDataPacket.getHandle());

Error log

java.lang.NoClassDefFoundError: Could not initialize class gg.dynamite.imgmapper.packetwrapper.WrapperPlayServerMap
at...

Caused by: java.lang.RuntimeException: Failed to find NMS class: MapIcon
at com.comphenix.protocol.utility.MinecraftReflection.lambda$getMinecraftClass$1(MinecraftReflection.java:2079) ~[ProtocolLib.jar:?]
at java.util.Optional.orElseThrow(Optional.java:403) ~[?:?]
at com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass(MinecraftReflection.java:2079) ~[ProtocolLib.jar:?]
at com.comphenix.protocol.wrappers.AutoWrapper.wrap(AutoWrapper.java:75) ~[ProtocolLib.jar:?]
at gg.dynamite.imgmapper.packetwrapper.WrapperPlayServerMap.(WrapperPlayServerMap.java:90) ~[ImgMapper-1.0-SNAPSHOT.jar:?]
... 11 more

Version Info
Version 4.8.0

commented

Please verify the package name of MapIcon is still net.minecraft or if it was moved into some sub package of net.minecraft

commented

@derklaro Look like the package name is now net.minecraft.world.level.saveddata.maps.MapIcon
What should I do with this?

commented

Just call (instead of getMinecraftClass("MapIcon")) getMinecraftClass("world.level.saveddata.maps.MapIcon")

commented

I think that piece of code is in ProtocolLib jar file not from my plugin. Does it mean that I have to build a customized version of ProtocolLib myself?

commented

Are you using TinyProtocol? This is currently not supported and outdated :/

commented

I don't use TinyProtocol directly but I'm not sure what happens behind the scene. I have posted the code snippet in use in the issue description.

commented

@derklaro
In class WrapperPlayServerMap which I download from https://github.com/dmulloy2/PacketWrapper, I have replaced MapIcon by world.level.saveddata.maps.MapIcon and MapIcon$Type by world.level.saveddata.maps.MapIcon$Type.

private static final AutoWrapper ICON_WRAPPER = AutoWrapper.wrap(MapIcon.class, "world.level.saveddata.maps.MapIcon")
.field(0, EnumWrappers.getGenericConverter(MinecraftReflection.getMinecraftClass("world.level.saveddata.maps.MapIcon$Type"), MapIconType.class))
.field(4, BukkitConverters.getWrappedChatComponentConverter());

The error that I mentioned now disappear. And a new error emerges
I have already checked the packet structure at https://wiki.vg/index.php?title=Protocol&oldid=16918#Map_Data . The only differences between 1.16.5 and 1.17.1 that I see is the relative position of field Locked and field Tracking Position So I update the code to change the index to write these values (change from 0 to 1 for TrackingPosition and change from 1 to 0 for Locked)

public void setTrackingPosition(boolean value) {
handle.getBooleans().write(1, value);
}

public void setLocked(boolean value) {
    handle.getBooleans().write(0, value);
}

This is the error after the changes. Before the changes, same error happens but the cause is the call to setLocked

[22:18:54 WARN]: [ImgMapper] FieldAccessException: Field index out of bounds. (Index: 1, Size: 1)
at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:373)
at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:349)
at ImgMapper-1.0-SNAPSHOT.jar//gg.dynamite.imgmapper.packetwrapper.WrapperPlayServerMap.setTrackingPosition(WrapperPlayServerMap.java:108)
at ImgMapper-1.0-SNAPSHOT.jar//gg.dynamite.imgmapper.ImgManager.updateFilledMap(ImgManager.java:106)
...

Do you have any ideas about this?