|
21 | 21 | package top.hendrixshen.magiclib.mixin.malilib.config;
|
22 | 22 |
|
23 | 23 | import fi.dy.masa.malilib.config.options.ConfigBase;
|
| 24 | +import org.spongepowered.asm.mixin.Final; |
24 | 25 | import org.spongepowered.asm.mixin.Mixin;
|
| 26 | +import org.spongepowered.asm.mixin.Shadow; |
| 27 | +import org.spongepowered.asm.mixin.Unique; |
25 | 28 | import org.spongepowered.asm.mixin.injection.At;
|
26 | 29 | import org.spongepowered.asm.mixin.injection.Inject;
|
27 | 30 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 31 | +import top.hendrixshen.magiclib.api.i18n.I18n; |
28 | 32 | import top.hendrixshen.magiclib.api.malilib.config.option.MagicIConfigBase;
|
29 | 33 | 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 |
36 | 34 |
|
37 | 35 | /**
|
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> |
39 | 37 | */
|
40 | 38 | @Mixin(value = ConfigBase.class, remap = false)
|
41 | 39 | 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 | + } |
62 | 51 |
|
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))); |
78 | 57 | }
|
| 58 | + } |
79 | 59 |
|
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 | + } |
82 | 70 | }
|
83 | 71 | }
|
0 commit comments