Skip to content

Commit a6fcc88

Browse files
committed
Revise #944 to avoid changing the API.
- ModMenu no longer displays a configuration icon for mods which implement the API but do not override `ModMenuApi.getModConfigScreenFactory()` (thanks `rcubedev`) - This does not change the API
1 parent 164b447 commit a6fcc88

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/main/java/com/terraformersmc/modmenu/ModMenu.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.terraformersmc.modmenu.event.ModMenuEventHandler;
1515
import com.terraformersmc.modmenu.util.EnumToLowerCaseJsonConverter;
1616
import com.terraformersmc.modmenu.util.ModMenuScreenTexts;
17+
import com.terraformersmc.modmenu.util.NullScreenFactory;
1718
import com.terraformersmc.modmenu.util.UpdateCheckerUtil;
1819
import com.terraformersmc.modmenu.util.mod.Mod;
1920
import com.terraformersmc.modmenu.util.mod.fabric.FabricDummyParentMod;
@@ -103,9 +104,11 @@ public void onInitializeClient() {
103104
String modId = metadata.getId();
104105
try {
105106
ModMenuApi api = entrypoint.getEntrypoint();
106-
var factory = api.getModConfigScreenFactory();
107-
if (factory != null) configScreenFactories.put(modId, factory);
108-
apiImplementations.add(api);
107+
ConfigScreenFactory<?> factory = api.getModConfigScreenFactory();
108+
if (!(factory instanceof NullScreenFactory<?>)) {
109+
configScreenFactories.put(modId, factory);
110+
}
111+
apiImplementations.add(api);
109112
updateCheckers.put(modId, api.getUpdateChecker());
110113
providedUpdateCheckers.putAll(api.getProvidedUpdateCheckers());
111114
api.attachModpackBadges(modpackMods::add);

src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.terraformersmc.modmenu.ModMenu;
44
import com.terraformersmc.modmenu.gui.ModsScreen;
5-
import org.jetbrains.annotations.Nullable;
5+
import com.terraformersmc.modmenu.util.NullScreenFactory;
66
import net.minecraft.client.gui.screen.Screen;
77
import net.minecraft.text.Text;
88

@@ -38,8 +38,8 @@ static Text createModsButtonText() {
3838
*
3939
* @return A factory for constructing config screen instances.
4040
*/
41-
default @Nullable ConfigScreenFactory<?> getModConfigScreenFactory() {
42-
return null;
41+
default ConfigScreenFactory<?> getModConfigScreenFactory() {
42+
return new NullScreenFactory<>();
4343
}
4444

4545
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.terraformersmc.modmenu.util;
2+
3+
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
4+
import net.minecraft.client.gui.screen.Screen;
5+
6+
/*
7+
* This class is used to detect mods which do not override the default ModMenuApi.getModConfigScreenFactory()
8+
* while still preserving the guarantee the above API method does not return null.
9+
*/
10+
public class NullScreenFactory<S extends Screen> implements ConfigScreenFactory<S> {
11+
@Override
12+
public S create(Screen parent) {
13+
return null;
14+
}
15+
}

0 commit comments

Comments
 (0)