diff --git a/src/main/java/com/plusls/MasaGadget/api/fake/mod_tweak/malilib/favoritesSupport/GuiBaseInjector.java b/src/main/java/com/plusls/MasaGadget/api/fake/mod_tweak/malilib/favoritesSupport/GuiBaseInjector.java new file mode 100644 index 0000000..7e0890d --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/api/fake/mod_tweak/malilib/favoritesSupport/GuiBaseInjector.java @@ -0,0 +1,12 @@ +package com.plusls.MasaGadget.api.fake.mod_tweak.malilib.favoritesSupport; + +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public interface GuiBaseInjector { + default void masa_gadget_mod$addFastSwitcherWidget() { + } + + default void masa_gadget_mod$addFavoritesWidget() { + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/common/MixinGuiBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/common/MixinGuiBase.java new file mode 100644 index 0000000..4edca90 --- /dev/null +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/common/MixinGuiBase.java @@ -0,0 +1,17 @@ +package com.plusls.MasaGadget.mixin.mod_tweak.common; + +import com.plusls.MasaGadget.api.fake.mod_tweak.malilib.favoritesSupport.GuiBaseInjector; +import fi.dy.masa.malilib.gui.GuiBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = GuiBase.class, remap = false) +public abstract class MixinGuiBase implements GuiBaseInjector { + @Inject(method = "initGui", at = @At("RETURN")) + private void handleInitGui(CallbackInfo ci) { + this.masa_gadget_mod$addFastSwitcherWidget(); + this.masa_gadget_mod$addFavoritesWidget(); + } +} diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java index 998ef78..ac6d4c4 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/fastSwitchMasaConfigGui/MixinGuiConfigBase.java @@ -1,5 +1,6 @@ package com.plusls.MasaGadget.mixin.mod_tweak.malilib.fastSwitchMasaConfigGui; +import com.plusls.MasaGadget.api.fake.mod_tweak.malilib.favoritesSupport.GuiBaseInjector; import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.api.gui.MasaGadgetDropdownList; import com.plusls.MasaGadget.impl.mod_tweak.malilib.fastSwitchMasaConfigGui.FastMasaGuiSwitcher; @@ -12,17 +13,16 @@ import fi.dy.masa.malilib.interfaces.IStringValue; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import top.hendrixshen.magiclib.api.dependency.DependencyType; import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies; import top.hendrixshen.magiclib.api.dependency.annotation.Dependency; import top.hendrixshen.magiclib.api.platform.PlatformType; import top.hendrixshen.magiclib.impl.malilib.config.gui.SelectorDropDownList; -//#if MC > 11902 -//$$ import org.spongepowered.asm.mixin.Intrinsic; +//#if MC > 12006 +//$$ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +//$$ import fi.dy.masa.malilib.gui.widgets.WidgetBase; +//$$ import org.spongepowered.asm.mixin.injection.At; //#endif //#if MC > 11904 @@ -40,7 +40,7 @@ ) @Dependencies(require = @Dependency(dependencyType = DependencyType.PLATFORM, platformType = PlatformType.FORGE_LIKE)) @Mixin(value = GuiConfigsBase.class, remap = false) -public abstract class MixinGuiConfigBase extends GuiListBase implements MasaGadgetDropdownList { +public abstract class MixinGuiConfigBase extends GuiListBase implements MasaGadgetDropdownList, GuiBaseInjector { protected MixinGuiConfigBase(int listX, int listY) { super(listX, listY); } @@ -48,17 +48,8 @@ protected MixinGuiConfigBase(int listX, int listY) { @Unique private SelectorDropDownList masa_gadget$masaModGuiList; - //#if MC > 11902 - //$$ //@Intrinsic - //$$ //@Override - //$$ //public void initGui() { - //$$ // super.initGui(); - //$$ //} - //$$ - //$$ @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) - //#endif - @Inject(method = "initGui", at = @At("RETURN")) - public void postInitGui(CallbackInfo ci) { + @Override + public void masa_gadget_mod$addFastSwitcherWidget() { if (Configs.fastSwitchMasaConfigGui.getBooleanValue()) { this.masa_gadget$masaModGuiList = new SelectorDropDownList<>( this.width - 111, 10, 100, 16, 200, 5, @@ -105,4 +96,18 @@ public void postInitGui(CallbackInfo ci) { //#endif ); } + + //#if MC > 12006 + //$$ // Force blocking malilib's intrinsic dropdown list + //$$ @WrapWithCondition( + //$$ method = "initGui", + //$$ at = @At( + //$$ value = "INVOKE", + //$$ target = "Lfi/dy/masa/malilib/gui/GuiConfigsBase;addWidget(Lfi/dy/masa/malilib/gui/widgets/WidgetBase;)Lfi/dy/masa/malilib/gui/widgets/WidgetBase;" + //$$ ) + //$$ ) + //$$ private boolean blockInherentDropdownList(GuiConfigsBase instance, WidgetBase widgetBase) { + //$$ return !Configs.fastSwitchMasaConfigGui.getBooleanValue(); + //$$ } + //#endif } diff --git a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java index ecad43e..521580a 100644 --- a/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java +++ b/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/malilib/favoritesSupport/MixinGuiConfigBase.java @@ -1,6 +1,7 @@ package com.plusls.MasaGadget.mixin.mod_tweak.malilib.favoritesSupport; import com.plusls.MasaGadget.SharedConstants; +import com.plusls.MasaGadget.api.fake.mod_tweak.malilib.favoritesSupport.GuiBaseInjector; import com.plusls.MasaGadget.game.Configs; import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesButton; import com.plusls.MasaGadget.impl.mod_tweak.malilib.favoritesSupport.MalilibFavoritesData; @@ -9,33 +10,17 @@ import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import top.hendrixshen.magiclib.api.i18n.I18n; import top.hendrixshen.magiclib.util.collect.ValueContainer; -//#if MC > 11902 -//$$ import org.spongepowered.asm.mixin.Intrinsic; -//#endif - @Mixin(value = GuiConfigsBase.class, remap = false, priority = 1100) -public abstract class MixinGuiConfigBase extends GuiListBase { +public abstract class MixinGuiConfigBase extends GuiListBase implements GuiBaseInjector { protected MixinGuiConfigBase(int listX, int listY) { super(listX, listY); } - //#if MC > 11902 - //$$ @Intrinsic - //$$ @Override - //$$ public void initGui() { - //$$ super.initGui(); - //$$ } - //$$ - //$$ @SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"}) - //#endif - @Inject(method = "initGui", at = @At("RETURN")) - public void postInitGui(CallbackInfo ci) { + @Override + public void masa_gadget_mod$addFavoritesWidget() { if (!Configs.favoritesSupport.getBooleanValue()) { return; } diff --git a/src/main/resources/masa_gadget_mod.mixins.json b/src/main/resources/masa_gadget_mod.mixins.json index f2c8ae6..4ee2d7c 100644 --- a/src/main/resources/masa_gadget_mod.mixins.json +++ b/src/main/resources/masa_gadget_mod.mixins.json @@ -20,6 +20,7 @@ "feature.cacheContainerMenu.MixinClientPacketListener", "feature.cacheContainerMenu.MixinLocalPlayer", "feature.cacheContainerMenu.MixinMultiPlayerGameMode", + "mod_tweak.common.MixinGuiBase", "mod_tweak.litematica.betterEasyPlaceMode.MixinWorldUtils", "mod_tweak.litematica.disableLitematicaEasyPlaceFailTip.MixinWorldUtils", "mod_tweak.litematica.fixCarpetAccurateProtocol.MixinBlockItem",