MinecraftDev icon indicating copy to clipboard operation
MinecraftDev copied to clipboard

Wrong Return and Parameter Completion using Mixins with @ModifyVariable in Fabric

Open Dev0Louis opened this issue 3 years ago • 3 comments
trafficstars

Please include the following information in all bug reports:

  • Minecraft Development: 2022.1-1.5.20-339 (Nightly)
  • InteliJ: 2022.1.4
  • Linux
  • Fabric (Mixin)

Wrong return and parameter Completion

When working with Injects regarding net.minecraft.client.option.ServerList

public void saveFile() {
	try {
	    NbtList nbtList = new NbtList();
	    Iterator var2 = this.servers.iterator();

	    ServerInfo serverInfo;
	    NbtCompound nbtCompound;
	    [...]

I tried changing a Variable with:

    @ModifyVariable(
            method = "saveFile",
            at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"))
    public Iterator<ServerInfo> mixin(Iterator<ServerInfo> value) {
        return value;
    } 

It is marked wrong by Minecraft Development, but I can start Minecraft perfectly fine.

But when using what Minecraft Development recommended:

    @ModifyVariable(
            method = "saveFile",
            at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"))
    public ServerList mixin(ServerList value) {
        return value;
    }

It is saying that it should is return Serverlist so the calls it self. [So maybe it has something to do it being this.servers.iterator();] But when I try booting the Game and clicking Multiplayer it crashes with these Logs

If there a Question feel free to ask me I will try to answer asap.

Dev0Louis avatar Aug 16 '22 21:08 Dev0Louis

Does mcdev complain if you put NbtList there? I'm wondering if it's just a case of INVOKE_ASSIGN resolving to slightly the wrong place.

Earthcomputer avatar Aug 16 '22 22:08 Earthcomputer

Does mcdev complain if you put NbtList there? I'm wondering if it's just a case of INVOKE_ASSIGN resolving to slightly the wrong place.

            @ModifyVariable(
            method = "saveFile",
            at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"),
            index = 1)
    public NbtList mixin(NbtList value) {
        return value;
    }

If you put index = 1, then it is referencing the NbtList. But if you do not set the Index it recommends is "Serverlist", but what it should recommend is "Iterator<ServerInfo>"

Dev0Louis avatar Aug 16 '22 23:08 Dev0Louis

Updated to InteliJ: IDEA 2022.2 Minecraft Development: 2022.2-1.5.20-339 (Nightly)

Problem continues to be there

Dev0Louis avatar Aug 17 '22 00:08 Dev0Louis

I think related to this issue (Fabric):

@Mixin(InGameHud.class)
public abstract class MixinInGameHud {
    @ModifyVariable(method = "renderScoreboardSidebar", ordinal = 0, at = @At(value = "STORE", ordinal = 0))
    private String removeScoreboardScores(String score, MatrixStack matrices, ScoreboardObjective objective) {
        return "";
    }
}

The plugin marks me following (Coming from the inspection Invalid injector method signature):

  • It wants to change the String return type to InGameHud (Expected return type 'InGameHud' for ModifyVariable method)
  • It wants to chante the (String score, MatrixStack matrices, ScoreboardObjective objective) method parameters to (InGameHud value) (Method parameters do not match expected parameters for ModifyVariable) image

BlockyTheDev avatar Feb 04 '23 21:02 BlockyTheDev

https://github.com/minecraft-dev/MinecraftDev/commit/151f2eac15cbbd813ac61f3aa786a8b984f7bdda

Earthcomputer avatar Nov 24 '23 15:11 Earthcomputer