Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java.lang.invoke.WrongMethodTypeException: #238

Merged
merged 3 commits into from
Dec 24, 2023

Conversation

timderspieler
Copy link
Contributor

Fixed a WrongMethodTypeException thrown when the chest open animation method has been called.

Original error:
[13:24:00 WARN]: java.lang.invoke.WrongMethodTypeException: cannot convert MethodHandle(int,int,int)BlockPosition to (double,double,double)Object [13:24:00 WARN]: at java.base/java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:884) [13:24:00 WARN]: at java.base/java.lang.invoke.MethodHandle.asType(MethodHandle.java:869) [13:24:00 WARN]: at java.base/java.lang.invoke.Invokers.checkGenericType(Invokers.java:542) [13:24:00 WARN]: at ZombieSurvival-Revamped-1.0.0-all.jar//sv.file14.zs.shaded.xseries.xseries.NMSExtras.chest(NMSExtras.java:561) [13:24:00 WARN]: at ZombieSurvival-Revamped-1.0.0-all.jar//sv.file14.zombiesurvival.util.NMSUtil.playChestAnimation(NMSUtil.java:104) [13:24:00 WARN]: at ZombieSurvival-Revamped-1.0.0-all.jar//sv.file14.zombiesurvival.gameSign.MysteryBoxSign.doEvent(MysteryBoxSign.java:70) [13:24:00 WARN]: at ZombieSurvival-Revamped-1.0.0-all.jar//sv.file14.zombiesurvival.listener.PlayerInteract.onEvent(PlayerInteract.java:84)

Fixed a WrongMethodTypeException thrown when the chest open animation method has been called.
@CryptoMorin
Copy link
Owner

You should make it backwards compatible, it used double for the previous versions.

blockPosition = lookup.findConstructor(blockPos,
v(19, MethodType.methodType(void.class, int.class, int.class, int.class)).orElse(
MethodType.methodType(void.class, double.class, double.class, double.class)));

@timderspieler
Copy link
Contributor Author

You should make it backwards compatible, it used double for the previous versions.

blockPosition = lookup.findConstructor(blockPos,
v(19, MethodType.methodType(void.class, int.class, int.class, int.class)).orElse(
MethodType.methodType(void.class, double.class, double.class, double.class)));

Done!

@CryptoMorin
Copy link
Owner

There's another problem now,

Object position = v(19, BLOCK_POSITION.invoke(location.getBlockX(), location.getBlockY(), location.getBlockZ()))
                                   //  ^^^^^ gets called
  .orElse(BLOCK_POSITION.invoke(location.getX(), location.getY(), location.getZ()));
                       // ^^^^^ gets called

Both BLOCK_POSITION invocations are going to be called regardless of which one it's going to pick, so it'd still throw that error. You could use the one with a supplier to prevent it from invoking the unused one:

Object position = v(19, () -> BLOCK_POSITION.invoke(location.getBlockX(), location.getBlockY(), location.getBlockZ()))
  .orElse(() -> BLOCK_POSITION.invoke(location.getX(), location.getY(), location.getZ()));

@CryptoMorin CryptoMorin added the bug Something isn't working label Dec 22, 2023
@timderspieler
Copy link
Contributor Author

@CryptoMorin that should be it now.

@CryptoMorin
Copy link
Owner

Thanks!

@CryptoMorin CryptoMorin merged commit dc23b5c into CryptoMorin:master Dec 24, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants