Skip to content

Commit

Permalink
Fix compatibility with latest malilib (Related to plusls#144)
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Jan 2, 2025
1 parent 897c8dc commit f91845d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -40,25 +40,16 @@
)
@Dependencies(require = @Dependency(dependencyType = DependencyType.PLATFORM, platformType = PlatformType.FORGE_LIKE))
@Mixin(value = GuiConfigsBase.class, remap = false)
public abstract class MixinGuiConfigBase extends GuiListBase<GuiConfigsBase.ConfigOptionWrapper, WidgetConfigOption, WidgetListConfigOptions> implements MasaGadgetDropdownList {
public abstract class MixinGuiConfigBase extends GuiListBase<GuiConfigsBase.ConfigOptionWrapper, WidgetConfigOption, WidgetListConfigOptions> implements MasaGadgetDropdownList, GuiBaseInjector {
protected MixinGuiConfigBase(int listX, int listY) {
super(listX, listY);
}

@Unique
private SelectorDropDownList<IStringValue> 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,
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<GuiConfigsBase.ConfigOptionWrapper, WidgetConfigOption, WidgetListConfigOptions> {
public abstract class MixinGuiConfigBase extends GuiListBase<GuiConfigsBase.ConfigOptionWrapper, WidgetConfigOption, WidgetListConfigOptions> 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;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/masa_gadget_mod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f91845d

Please sign in to comment.