LlamaLad7 / MixinExtras

Companion library to SpongePowered Mixin with many custom injectors for a more expressive experience.
MIT License
293 stars 16 forks source link

@WrapOperation on instantiation causes an ArrayIndexOutOfBoundsException #57

Closed KingContaria closed 7 months ago

KingContaria commented 7 months ago

Hi, i am trying to use @WrapOperation to wrap an instantiation but im having some trouble getting it to work:

My working Redirect:

    @Redirect(
            method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V",
            at = @At(
                    value = "NEW",
                    target = "Lnet/minecraft/util/UserCache;"
            )
    )
    private UserCache wrapUserCache(GameProfileRepository profileRepository, File cacheFile) {
        if (...) {
            return ...;
        }
        return new UserCache(profileRepository, cacheFile);
    }

My non-working attempt at a WrapOperation:

    @WrapOperation(
            method = "startIntegratedServer(Ljava/lang/String;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/MinecraftClient$WorldLoadAction;)V",
            at = @At(
                    value = "NEW",
                    target = "Lnet/minecraft/util/UserCache;"
            )
    )
    private UserCache wrapUserCache(GameProfileRepository profileRepository, File cacheFile, Operation<UserCache> original) {
        if (...) {
            return ...;
        }
        return original.call(profileRepository, cacheFile);
    }

I am using Fabricloader 0.15.1 with MixinExtras 0.3.1. (The log confirms that MixinExtras 0.3.1 is in fact loading correctly). Minecraft version is 1.16.1 using Java 17. The MinecraftDev plugin unfortunately isnt of much help because it doesnt recognize the injector correctly on the Redirect either.

Minecraft crashes with java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0, the full crash as a text file can be found here.

KingContaria commented 7 months ago

Apparently there is a little more to it, reproduction steps are:

An example repo can be found here.

LlamaLad7 commented 7 months ago

Fixed in 0.3.2/0.2.2