Skip to content

Commit 242009e

Browse files
authored
Fix #135 (#137)
* Aggressive ConfigBase getPrettyName / getComment impl overrides are necessary especially when new malilib changes the default implementation logic and breaks everything (e.g. mc1.21.3, malilib 1.21.3-0.22.0-sakura.5) * Update mod dependency malilib to latest * Use our logger --------- Signed-off-by: Hendrix-Shen <[email protected]>
1 parent 40e2166 commit 242009e

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

magiclib-legacy-compat/src/main/java/top/hendrixshen/magiclib/mixin/malilib/backport/MixinConfigBooleanHotkeyed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.gson.JsonElement;
44
import com.google.gson.JsonObject;
55
import com.google.gson.JsonPrimitive;
6-
import fi.dy.masa.malilib.MaLiLib;
76
import fi.dy.masa.malilib.config.IHotkeyTogglable;
87
import fi.dy.masa.malilib.config.options.ConfigBoolean;
98
import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed;
@@ -16,6 +15,7 @@
1615
import org.spongepowered.asm.mixin.Final;
1716
import org.spongepowered.asm.mixin.Mixin;
1817
import org.spongepowered.asm.mixin.Shadow;
18+
import top.hendrixshen.magiclib.MagicLib;
1919
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;
2020
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;
2121

@@ -72,7 +72,7 @@ public void setValueFromJsonElement(JsonElement element) {
7272
super.setValueFromJsonElement(element);
7373
}
7474
} catch (Exception e) {
75-
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
75+
MagicLib.getLogger().warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
7676
}
7777
}
7878

magiclib-malilib-extra/src/main/java/top/hendrixshen/magiclib/mixin/malilib/config/ConfigBaseMixin.java

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,51 @@
2121
package top.hendrixshen.magiclib.mixin.malilib.config;
2222

2323
import fi.dy.masa.malilib.config.options.ConfigBase;
24+
import org.spongepowered.asm.mixin.Final;
2425
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Shadow;
27+
import org.spongepowered.asm.mixin.Unique;
2528
import org.spongepowered.asm.mixin.injection.At;
2629
import org.spongepowered.asm.mixin.injection.Inject;
2730
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
31+
import top.hendrixshen.magiclib.api.i18n.I18n;
2832
import top.hendrixshen.magiclib.api.malilib.config.option.MagicIConfigBase;
2933
import top.hendrixshen.magiclib.impl.malilib.config.GlobalConfigManager;
30-
import top.hendrixshen.magiclib.util.MiscUtil;
31-
32-
//#if MC > 11701
33-
//$$ import org.spongepowered.asm.mixin.Shadow;
34-
//$$ import org.spongepowered.asm.mixin.injection.ModifyArg;
35-
//#endif
3634

3735
/**
38-
* Reference to <a href="https://github.com/Fallen-Breath/tweakermore/blob/10e1a937aadcefb1f2d9d9bab8badc873d4a5b3d/src/main/java/me/fallenbreath/tweakermore/mixins/core/config/ConfigBaseMixin.java">TweakerMore</a>
36+
* Reference to <a href="https://github.com/Fallen-Breath/tweakermore/blob/476a25a5458a7058bdd402683b1fd833b189ae60/src/main/java/me/fallenbreath/tweakermore/mixins/core/config/ConfigBaseMixin.java">TweakerMore</a>
3937
*/
4038
@Mixin(value = ConfigBase.class, remap = false)
4139
public class ConfigBaseMixin {
42-
//#if MC > 11701
43-
//$$ @Shadow
44-
//$$ private String comment;
45-
//$$
46-
//$$ @ModifyArg(
47-
//$$ method = "getComment",
48-
//$$ at = @At(
49-
//$$ value = "INVOKE",
50-
//$$ target = "Lfi/dy/masa/malilib/util/StringUtils;getTranslatedOrFallback(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"
51-
//$$ ),
52-
//$$ index = 0
53-
//$$ )
54-
//$$ private String magicConfigCommentIsTheTranslationKey(String key) {
55-
//$$ if (MiscUtil.cast(this) instanceof MagicIConfigBase) {
56-
//$$ key = this.comment;
57-
//$$ }
58-
//$$
59-
//$$ return key;
60-
//$$ }
61-
//#endif
40+
@Shadow
41+
private String comment;
42+
43+
@Final
44+
@Shadow
45+
private String prettyName;
46+
47+
@Unique
48+
private boolean magiclib$isMagicConfig() {
49+
return this instanceof MagicIConfigBase;
50+
}
6251

63-
@Inject(
64-
method = "getComment",
65-
at = @At(
66-
//#if MC > 12101
67-
//$$ value = "RETURN",
68-
//$$ ordinal = 1
69-
//#else
70-
value = "TAIL"
71-
//#endif
72-
),
73-
cancellable = true
74-
)
75-
private void appendComment(CallbackInfoReturnable<String> cir) {
76-
if (!(MiscUtil.cast(this) instanceof MagicIConfigBase)) {
77-
return;
52+
@Inject(method = "getPrettyName", at = @At("HEAD"), cancellable = true, remap = false)
53+
private void tweakerMoreUseMyPrettyName(CallbackInfoReturnable<String> cir) {
54+
if (this.magiclib$isMagicConfig()) {
55+
GlobalConfigManager.getInstance().getContainerByConfig((MagicIConfigBase) this)
56+
.ifPresent(configContainer -> cir.setReturnValue(I18n.tr(this.prettyName)));
7857
}
58+
}
7959

80-
GlobalConfigManager.getInstance().getContainerByConfig((MagicIConfigBase) this)
81-
.ifPresent(configContainer -> cir.setReturnValue(configContainer.modifyComment(cir.getReturnValue())));
60+
@Inject(method = "getComment", at = @At("HEAD"), cancellable = true, remap = false)
61+
private void magiclibUseMagicComment(CallbackInfoReturnable<String> cir) {
62+
if (this.magiclib$isMagicConfig()) {
63+
GlobalConfigManager.getInstance().getContainerByConfig((MagicIConfigBase) this)
64+
.ifPresent(configContainer -> {
65+
String translatedComment = I18n.tr(this.comment);
66+
translatedComment = configContainer.modifyComment(translatedComment);
67+
cir.setReturnValue(translatedComment);
68+
});
69+
}
8270
}
8371
}

magiclib-malilib-extra/versions/1.21.1-fabric/gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
dependencies.minecraft_dependency=>=1.21- <1.21.2-
33
dependencies.minecraft_version=1.21.1
44

5-
# Malilib 0.21.4
6-
# malilib-fabric-1.21-0.21.4.jar
7-
dependencies.api.malilib_version=0.21.4
5+
# Malilib 0.21.5
6+
# malilib-fabric-1.21-0.21.5.jar
7+
dependencies.api.malilib_version=0.21.5
88

99
# Publish properties
1010
publish.game_version=1.21,1.21.1
1111
publish.dependencies_list=\
12-
[email protected].4(optional){modrinth:GcWjdA9I}{curseforge:303119}#(ignore:github)
12+
[email protected].5(optional){modrinth:GcWjdA9I}{curseforge:303119}#(ignore:github)

magiclib-malilib-extra/versions/1.21.3-fabric/gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
dependencies.minecraft_dependency=>=1.21.2- <1.21.4-
33
dependencies.minecraft_version=1.21.3
44

5-
# Malilib 0.22.2
6-
# malilib-fabric-1.21.3-0.22.2.jar
7-
dependencies.api.malilib_version=0.22.2
5+
# Malilib 0.22.3
6+
# malilib-fabric-1.21.3-0.22.3.jar
7+
dependencies.api.malilib_version=0.22.3
88

99
# Publish properties
1010
publish.game_version=1.21.2,1.21.3
1111
publish.dependencies_list=\
12-
[email protected].2(optional){modrinth:GcWjdA9I}{curseforge:303119}#(ignore:github)
12+
[email protected].3(optional){modrinth:GcWjdA9I}{curseforge:303119}#(ignore:github)

0 commit comments

Comments
 (0)