Mapping issue with 1.20.1 - 1.20.4
gXLg opened this issue · 1 comments
I am writing a mod which should work on multiple versions. Some things already work as intended, but there's been one issue I couldn't resolve for over 4 hours now!
Scenario:
- I create a mod with 1.20.4 mappings
- I want to use that mod on 1.20.1 as well
- The mod uses
Lnet/minecraft/client/network/ClientCommonNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V
in 1.20.4 which isLnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V
in 1.20.1
Intermediary names:
- 1.20.1 -
Lnet/minecraft/class_634;method_2883(Lnet/minecraft/class_2596;)V
- 1.20.4 -
Lnet/minecraft/class_8673;method_52787(Lnet/minecraft/class_2596;)V
I tried in my code (my current goal is only to bring the mod compiled in 1.20.4 to work on 1.20.1):
try {
MappingResolver resolver = FabricLoader.getInstance().getMappingResolver();
Class<?> cls = Class.forName(resolver.mapClassName("intermediary", "net.minecraft.class_634"));
Class<?> pack = Class.forName(resolver.mapClassName("intermediary", "net.minecraft.class_2596"));
MethodHandles.Lookup lookup = MethodHandles.publicLookup();
MethodHandle methodHandle = lookup.findVirtual(cls,
resolver.mapMethodName(
"intermediary",
resolver.unmapClassName("intermediary", cls.getName()),
"method_2883",
"(Lnet/minecraft/class_2596;)V"
),
MethodType.methodType(void.class, pack)
);
methodHandle.invokeExact(handler, packet);
} catch (Throwable e) {
throw new RuntimeException(e);
}
I also tried usual reflection, but this also didn't work.
The issue:
No matter how I try to reference Lnet/minecraft/class_634;method_2883(Lnet/minecraft/class_2596;)V
, even if the method and class resolve correctly, in the end Lnet/minecraft/class_634;method_52787(Lnet/minecraft/class_2596;)V
is being called which produces NoSuchMethodError
(NoSuchMethodException
which would come from reflection).
If there is any way to achieve this, or if I am doing anything wrong - in any way, I need help! 🙏