Skip to content

Commit

Permalink
use ModifyArg instead of ModifyArgs, cuz forge 1.17+ crashes with it
Browse files Browse the repository at this point in the history
see SpongePowered/Mixin#584
also splits 1.19.3 version for MinecraftClient for neater look
  • Loading branch information
Fallen-Breath committed Jun 17, 2023
1 parent cb69fd9 commit 9efa767
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 22 deletions.
Expand Up @@ -24,52 +24,64 @@
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import java.io.InputStream;

/**
* The implementation for mc (~, 1.20)
* See {@link IconsMixin} in subproject 1.20 for implementation for mc [1.20, ~)
* The implementation for mc (~, 1.19.3)
* See:
* - {@link MinecraftClientMixin} in subproject 1.19.3-fabric for implementation for mc [1.19.3, 1.20)
* - {@link IconsMixin} in subproject 1.20.1-fabric for implementation for mc [1.20, ~)
*/
@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin
{
@ModifyArgs(
@ModifyArg(
//#if MC >= 11500
method = "<init>",
//#else
//$$ method = "init",
//#endif
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/Window;setIcon(Ljava/io/InputStream;Ljava/io/InputStream;)V"
),
index = 0
)
private InputStream bringTheClassicCraftingTableIconBack_general16x(InputStream icon16)
{
return ClassicMinecraftIconStorage.getResource("icon_16x16.png");
}

@ModifyArg(
//#if MC >= 11500
method = "<init>",
//#else
//$$ method = "init",
//#endif
at = @At(
value = "INVOKE",
//#if MC >= 11903
//$$ target = "Lnet/minecraft/client/util/Window;setIcon(Lnet/minecraft/resource/InputSupplier;Lnet/minecraft/resource/InputSupplier;)V"
//#else
target = "Lnet/minecraft/client/util/Window;setIcon(Ljava/io/InputStream;Ljava/io/InputStream;)V"
//#endif
)
),
index = 1
)
private void bringTheClassicCraftingTableIconBack_general(Args args)
private InputStream bringTheClassicCraftingTableIconBack_general32x(InputStream icon32)
{
args.set(0, ClassicMinecraftIconStorage.getResource("icon_16x16.png"));
args.set(1, ClassicMinecraftIconStorage.getResource("icon_32x32.png"));
return ClassicMinecraftIconStorage.getResource("icon_32x32.png");
}

//#if MC >= 11902
//$$ @ModifyArgs(
//$$ @ModifyArg(
//$$ method = "<init>",
//$$ at = @At(
//$$ value = "INVOKE",
//#if MC >= 11903
//$$ target = "Lnet/minecraft/client/util/MacWindowUtil;setApplicationIconImage(Lnet/minecraft/resource/InputSupplier;)V"
//#else
//$$ target = "Lnet/minecraft/client/util/MacWindowUtil;setApplicationIconImage(Ljava/io/InputStream;)V"
//#endif
//$$ target = "Lnet/minecraft/client/util/MacWindowUtil;setApplicationIconImage(Ljava/io/InputStream;)V"
//$$ )
//$$ )
//$$ private void bringTheClassicCraftingTableIconBack_mac(Args args)
//$$ private InputStream bringTheClassicCraftingTableIconBack_mac(InputStream iconMac)
//$$ {
//$$ args.set(0, ClassicMinecraftIconStorage.getResource("minecraft.icns"));
//$$ return ClassicMinecraftIconStorage.getResource("minecraft.icns");
//$$ }
//#endif
}
@@ -0,0 +1,78 @@
/*
* This file is part of the Classic Minecraft Icon project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* Classic Minecraft Icon is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Classic Minecraft Icon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Classic Minecraft Icon. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.classicminecrafticon.mixins;

import me.fallenbreath.classicminecrafticon.ClassicMinecraftIconStorage;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.InputSupplier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import java.io.InputStream;

/**
* The implementation for mc [1.19.3, 1.20)
* See:
* - {@link MinecraftClientMixin} in subproject 1.15.2-fabric for implementation for mc (~, 1.19.3)
* - {@link IconsMixin} in subproject 1.20.1-fabric for implementation for mc [1.20, ~)
*/
@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin
{
@ModifyArg(
method = "<init>",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/Window;setIcon(Lnet/minecraft/resource/InputSupplier;Lnet/minecraft/resource/InputSupplier;)V"
),
index = 0
)
private InputSupplier<InputStream> bringTheClassicCraftingTableIconBack_general16x(InputSupplier<InputStream> icon16)
{
return ClassicMinecraftIconStorage.getResource("icon_16x16.png");
}

@ModifyArg(
method = "<init>",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/Window;setIcon(Lnet/minecraft/resource/InputSupplier;Lnet/minecraft/resource/InputSupplier;)V"
),
index = 1
)
private InputSupplier<InputStream> bringTheClassicCraftingTableIconBack_general32x(InputSupplier<InputStream> icon32)
{
return ClassicMinecraftIconStorage.getResource("icon_32x32.png");
}

@ModifyArg(
method = "<init>",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/MacWindowUtil;setApplicationIconImage(Lnet/minecraft/resource/InputSupplier;)V"
)
)
private InputSupplier<InputStream> bringTheClassicCraftingTableIconBack_mac(InputSupplier<InputStream> iconMac)
{
return ClassicMinecraftIconStorage.getResource("minecraft.icns");
}
}
Expand Up @@ -33,7 +33,9 @@

/**
* The implementation for mc [1.20, ~)
* See {@link MinecraftClientMixin} in subproject 1.15.2 for implementation for mc (~, 1.20)
* See:
* - {@link MinecraftClientMixin} in subproject 1.15.2-fabric for implementation for mc (~, 1.19.3)
* - {@link MinecraftClientMixin} in subproject 1.19.3-fabric for implementation for mc [1.19.3, 1.20)
*/
@Mixin(Icons.class)
public abstract class IconsMixin
Expand Down

0 comments on commit 9efa767

Please sign in to comment.