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

@WrapOperation parameter substitution is broken #5

Open
dima-dencep opened this issue Sep 26, 2024 · 8 comments
Open

@WrapOperation parameter substitution is broken #5

dima-dencep opened this issue Sep 26, 2024 · 8 comments

Comments

@dima-dencep
Copy link

dima-dencep commented Sep 26, 2024

I need to add a parameter with index 0 (at the very beginning), but when I do this I get an error:

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 3
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.lambda$extractWrapOperation$0(ParamTransformationUtil.java:175)
	at java.base/java.util.HashMap.forEach(HashMap.java:1429)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.extractWrapOperation(ParamTransformationUtil.java:165)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform.apply(InjectParameterTransform.java:76)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.TransformParameters.apply(TransformParameters.java:54)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.PatchInstance.apply(PatchInstance.java:72)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.connector.transformer.MixinPatchTransformer.process(MixinPatchTransformer.java:219)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.EntryImpl$ClassEntry.process(EntryImpl.java:58)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.EntryImpl$ClassEntry.process(EntryImpl.java:36)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.RenamerImpl.processEntry(RenamerImpl.java:215)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.AsyncHelper.lambda$null$2(AsyncHelper.java:40)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1456)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

So I thought a great solution would be to use swap, and my code started to look like this:

.transformParams(builder -> builder
    .targetType(ParamTransformTarget.INJECTION_POINT)
    .inject(2, Type.getObjectType("net/minecraft/world/entity/Entity"))
    .inject(3, Type.getObjectType("net/minecraft/world/item/ItemStack"))
    .swap(0, 2)
    .swap(1, 3)
    .inject(4, Type.getObjectType("net/minecraft/world/entity/EquipmentSlot"))
)

It works, but the order of the arguments in WrapOperation hasn't changed, so I think the code that adds the parameters there works, but it can't swap them around:
image

@Su5eD
Copy link
Member

Su5eD commented Sep 26, 2024

Can you show your original code?

@dima-dencep
Copy link
Author

.transformParams(builder -> builder
    .targetType(ParamTransformTarget.INJECTION_POINT)
    .inject(0, Type.getObjectType("net/minecraft/world/entity/Entity"))
    .inject(1, Type.getObjectType("net/minecraft/world/item/ItemStack"))
    .inject(4, Type.getObjectType("net/minecraft/world/entity/EquipmentSlot"))
)

@dima-dencep
Copy link
Author

I know what causes the error of injecting a parameter with 0 index, and I fixed it in the adapter

But now I encounter an error when trying to inject a parameter with index 1:

Caused by: java.util.NoSuchElementException
	at java.base/java.util.ArrayList.getLast(ArrayList.java:454)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.lambda$extractWrapOperation$0(ParamTransformationUtil.java:198)
	at java.base/java.util.HashMap.forEach(HashMap.java:1429)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.ParamTransformationUtil.extractWrapOperation(ParamTransformationUtil.java:165)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform.apply(InjectParameterTransform.java:76)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.transformer.operation.param.TransformParameters.apply(TransformParameters.java:54)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.adapter.patch.PatchInstance.apply(PatchInstance.java:72)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/org.sinytra.connector.transformer.MixinPatchTransformer.process(MixinPatchTransformer.java:219)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.EntryImpl$ClassEntry.process(EntryImpl.java:58)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.EntryImpl$ClassEntry.process(EntryImpl.java:36)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.RenamerImpl.processEntry(RenamerImpl.java:215)
	at LAYER SERVICE/[email protected]+1.21.1+dev-g6ae9c7f-full/reloc.net.minecraftforge.fart.internal.AsyncHelper.lambda$null$2(AsyncHelper.java:40)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1456)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

@Su5eD
Copy link
Member

Su5eD commented Sep 26, 2024

Looks like it's mistakenly trying to get the last element of an empty list.

@dima-dencep
Copy link
Author

It is, but I don't know how to fix it

@dima-dencep
Copy link
Author

Is there any progress? I can't write a mod because it is delayed by this bug...
I'd also like to throw a pr that is also delayed because of this 😢

@Su5eD
Copy link
Member

Su5eD commented Sep 28, 2024

I will have a look as soon as I have time. If you'd like to speed things up, contributions are always welcome 😊

@dima-dencep
Copy link
Author

I'd like to, but I don't understand how to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants