Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream Sync for Minecraft b1.8 #16

Merged
merged 23 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d8e5db5
Use different User Agent than upstream
LostLuma Apr 23, 2024
508f82b
Updated Norwegian Bokmål translations (no_no.json) (#656)
Bloodaxe95 Nov 29, 2023
eca7302
Update zh_cn.json (#655)
ioococ Nov 29, 2023
b3d7798
Update be_by.json (#654)
Gazmanovich Nov 29, 2023
7b613c3
Update be_by.json (#696)
Gazmanovich Mar 6, 2024
54d76d7
Update twitter name
Prospector Mar 8, 2024
85c6a2f
Delay handling API implementations until it's first needed
Prospector Mar 8, 2024
5783e2d
Add support for custom update checking logic (#708)
Prospector Apr 18, 2024
4480dac
Fix disable update checks config not working for individual mods (#703)
LostLuma Apr 18, 2024
cdb982f
Add option to choose which update channel to receive notifications fo…
LostLuma Apr 22, 2024
67a3ce3
Group mod credits by role instead of bunching them together (#706)
LostLuma Apr 22, 2024
4aab058
Fix user agent stripping not working (#707)
LostLuma Apr 22, 2024
70d0f2f
Add provided update checkers, loader update checkers (#711)
LostLuma Apr 22, 2024
6f47a8c
Fix update checker not being called when screen is closed in a way ot…
Prospector Apr 22, 2024
8bb025e
Fix credits role translation keys not being lowercased
LostLuma Apr 23, 2024
f66f12a
Remove sorting of individual contributors (#726)
LostLuma Jun 15, 2024
5de0d7f
Update zh_cn.json (#733)
EastCation Jun 15, 2024
b14d4e3
Updated Tatar Translation! (#715)
Amirhan-Taipovjan-Greatest-I Jun 15, 2024
50fe257
Update pl_pl.json (#717)
mt1006 Jun 15, 2024
c256e7b
Update be_by.json (#728)
Gazmanovich Jun 15, 2024
05940f6
Skip unknown badge keys (#720)
haykam821 Jun 15, 2024
0304375
Fix update checker promoting downgrades, other followup improvements …
LostLuma Jun 15, 2024
2fdb327
Change loader update checker download link to Ornithe website
LostLuma Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions src/main/java/com/terraformersmc/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.google.gson.GsonBuilder;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import com.terraformersmc.modmenu.api.UpdateChecker;
import com.terraformersmc.modmenu.config.ModMenuConfig;
import com.terraformersmc.modmenu.config.ModMenuConfig.GameMenuButtonStyle;
import com.terraformersmc.modmenu.config.ModMenuConfig.TitleMenuButtonStyle;
import com.terraformersmc.modmenu.config.ModMenuConfigManager;
import com.terraformersmc.modmenu.event.ModMenuEventHandler;
import com.terraformersmc.modmenu.util.ModrinthUtil;
import com.terraformersmc.modmenu.util.TranslationUtil;
import com.terraformersmc.modmenu.util.GlUtil;
import com.terraformersmc.modmenu.util.TranslationUtil;
import com.terraformersmc.modmenu.util.UpdateCheckerUtil;
import com.terraformersmc.modmenu.util.mod.Mod;
import com.terraformersmc.modmenu.util.mod.fabric.FabricDummyParentMod;
import com.terraformersmc.modmenu.util.mod.fabric.FabricMod;
Expand All @@ -31,7 +34,7 @@

public class ModMenu implements ClientModInitializer {
public static final String MOD_ID = "modmenu";
public static final String GITHUB_REF = "TerraformersMC/ModMenu";
public static final String GITHUB_REF = "OrnitheMC/ModMenu";
public static final Logger LOGGER = LogManager.getLogger("Mod Menu");
public static final Gson GSON = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().create();
public static final Gson GSON_MINIFIED = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
Expand All @@ -40,17 +43,19 @@ public class ModMenu implements ClientModInitializer {
public static final Map<String, Mod> ROOT_MODS = new HashMap<>();
public static final LinkedListMultimap<Mod, Mod> PARENT_MAP = LinkedListMultimap.create();

private static Map<String, ConfigScreenFactory<?>> configScreenFactories = new HashMap<>();
private static List<Map<String, ConfigScreenFactory<?>>> delayedScreenFactoryProviders = new ArrayList<>();
private static final Map<String, ConfigScreenFactory<?>> configScreenFactories = new HashMap<>();
private static final List<ModMenuApi> apiImplementations = new ArrayList<>();

private static int cachedDisplayedModCount = -1;
public static boolean runningQuilt = FabricLoader.getInstance().isModLoaded("quilt_loader");
public static boolean devEnvironment = FabricLoader.getInstance().isDevelopmentEnvironment();

public static Screen getConfigScreen(String modid, Screen menuScreen) {
if(!delayedScreenFactoryProviders.isEmpty()) {
delayedScreenFactoryProviders.forEach(map -> map.forEach(configScreenFactories::putIfAbsent));
delayedScreenFactoryProviders.clear();
for (ModMenuApi api : apiImplementations) {
Map<String, ConfigScreenFactory<?>> factoryProviders = api.getProvidedConfigScreenFactories();
if (!factoryProviders.isEmpty()) {
factoryProviders.forEach(configScreenFactories::putIfAbsent);
}
}
if (ModMenuConfig.HIDDEN_CONFIGS.getValue().contains(modid)) {
return null;
Expand All @@ -66,13 +71,18 @@ public static Screen getConfigScreen(String modid, Screen menuScreen) {
public void initClient() {
ModMenuConfigManager.initializeConfig();
Set<String> modpackMods = new HashSet<>();
Map<String, UpdateChecker> updateCheckers = new HashMap<>();
Map<String, UpdateChecker> providedUpdateCheckers = new HashMap<>();

FabricLoader.getInstance().getEntrypointContainers("modmenu", ModMenuApi.class).forEach(entrypoint -> {
ModMetadata metadata = entrypoint.getProvider().getMetadata();
String modId = metadata.getId();
try {
ModMenuApi api = entrypoint.getEntrypoint();
configScreenFactories.put(modId, api.getModConfigScreenFactory());
delayedScreenFactoryProviders.add(api.getProvidedConfigScreenFactories());
apiImplementations.add(api);
updateCheckers.put(modId, api.getUpdateChecker());
providedUpdateCheckers.putAll(api.getProvidedUpdateCheckers());
api.attachModpackBadges(modpackMods::add);
} catch (Throwable e) {
LOGGER.error("Mod {} provides a broken implementation of ModMenuApi", modId, e);
Expand All @@ -89,10 +99,17 @@ public void initClient() {
mod = new FabricMod(modContainer, modpackMods);
}

UpdateChecker updateChecker = updateCheckers.get(mod.getId());

if (updateChecker == null) {
updateChecker = providedUpdateCheckers.get(mod.getId());
}

MODS.put(mod.getId(), mod);
mod.setUpdateChecker(updateChecker);
}

ModrinthUtil.checkForUpdates();
checkForUpdates();

Map<String, Mod> dummyParents = new HashMap<>();

Expand Down Expand Up @@ -120,6 +137,10 @@ public static void clearModCountCache() {
cachedDisplayedModCount = -1;
}

public static void checkForUpdates() {
UpdateCheckerUtil.checkForUpdates();
}

public static boolean areModUpdatesAvailable() {
if (!ModMenuConfig.UPDATE_CHECKER.getValue()) {
return false;
Expand All @@ -134,7 +155,7 @@ public static boolean areModUpdatesAvailable() {
continue;
}

if (mod.getModrinthData() != null || mod.getChildHasUpdate()) {
if (mod.hasUpdate() || mod.getChildHasUpdate()) {
return true; // At least one currently visible mod has an update
}
}
Expand All @@ -146,9 +167,9 @@ public static String getDisplayedModCount() {
if (cachedDisplayedModCount == -1) {
// listen, if you have >= 2^32 mods then that's on you
cachedDisplayedModCount = Math.toIntExact(MODS.values().stream().filter(mod ->
(ModMenuConfig.COUNT_CHILDREN.getValue() || mod.getParent() == null) &&
(ModMenuConfig.COUNT_LIBRARIES.getValue() || !mod.getBadges().contains(Mod.Badge.LIBRARY)) &&
(ModMenuConfig.COUNT_HIDDEN_MODS.getValue() || !mod.isHidden())
(ModMenuConfig.COUNT_CHILDREN.getValue() || mod.getParent() == null) &&
(ModMenuConfig.COUNT_LIBRARIES.getValue() || !mod.getBadges().contains(Mod.Badge.LIBRARY)) &&
(ModMenuConfig.COUNT_HIDDEN_MODS.getValue() || !mod.isHidden())
).count());
}
return NumberFormat.getInstance().format(cachedDisplayedModCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import com.google.common.collect.ImmutableMap;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import com.terraformersmc.modmenu.api.UpdateChecker;
import com.terraformersmc.modmenu.gui.ModMenuOptionsScreen;
import com.terraformersmc.modmenu.mixin.AccessorMinecraft;

import com.terraformersmc.modmenu.util.mod.fabric.FabricLoaderUpdateChecker;
import com.terraformersmc.modmenu.util.mod.quilt.QuiltLoaderUpdateChecker;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.options.OptionsScreen;

import java.util.Map;

public class ModMenuModMenuCompat implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return ModMenuOptionsScreen::new;
Expand All @@ -21,4 +25,13 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
return ImmutableMap.of("minecraft", parent -> new OptionsScreen(parent, AccessorMinecraft.getInstance().options));
}

@Override
public Map<String, UpdateChecker> getProvidedUpdateCheckers() {
if (ModMenu.runningQuilt) {
return ImmutableMap.of("quilt_loader", new QuiltLoaderUpdateChecker());
} else {
return ImmutableMap.of("fabricloader", new FabricLoaderUpdateChecker());
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/terraformersmc/modmenu/api/ModMenuApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ default ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> null;
}

/**
* Used for mods that have their own update checking logic.
* By returning your own {@link UpdateChecker} instance, you can override ModMenus built-in update checking logic.
*
* @return An {@link UpdateChecker} or <code>null</code> if ModMenu should handle update checking.
*/
default UpdateChecker getUpdateChecker() {
return null;
}

/**
* Used to provide config screen factories for other mods. This takes second
* priority to a mod's own config screen factory provider. For example, if
Expand All @@ -58,6 +68,16 @@ default Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
return ImmutableMap.of();
}

/**
* Used to provide update checkers for other mods. A mod registering its own
* update checker will take priority over any provided ones should both exist.
*
* @return a map of mod ids to update checkers.
*/
default Map<String, UpdateChecker> getProvidedUpdateCheckers() {
return ImmutableMap.of();
}

/**
* Used to mark mods with a badge indicating that they are
* provided by a modpack.
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/terraformersmc/modmenu/api/UpdateChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.terraformersmc.modmenu.api;

import com.terraformersmc.modmenu.config.ModMenuConfig;

/**
* Supported update channels, in ascending order by stability.
*/
public enum UpdateChannel {
ALPHA,
BETA,
RELEASE;

/**
* @return the user's preferred update channel.
*/
public static UpdateChannel getUserPreference() {
return ModMenuConfig.UPDATE_CHANNEL.getValue();
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/terraformersmc/modmenu/api/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.terraformersmc.modmenu.api;

public interface UpdateChecker {
/**
* Gets called when ModMenu is checking for updates.
* This is done in a separate thread, so this call can/should be blocking.
*
* <p>Your update checker should aim to return an update on the same or a more stable channel than the user's preference which you can get via {@link UpdateChannel#getUserPreference()}.</p>
*
* @return The update info
*/
UpdateInfo checkForUpdates();
}
28 changes: 28 additions & 0 deletions src/main/java/com/terraformersmc/modmenu/api/UpdateInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.terraformersmc.modmenu.api;

import org.jetbrains.annotations.Nullable;

public interface UpdateInfo {
/**
* @return If an update for the mod is available.
*/
boolean isUpdateAvailable();

/**
* @return The message that is getting displayed when an update is available or <code>null</code> to let ModMenu handle displaying the message.
*/
@Nullable
default String getUpdateMessage() {
return null;
}

/**
* @return The URL to the mod download.
*/
String getDownloadLink();

/**
* @return The update channel this update is available for.
*/
UpdateChannel getUpdateChannel();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.terraformersmc.modmenu.config;

import com.google.gson.annotations.SerializedName;
import com.terraformersmc.modmenu.api.UpdateChannel;
import com.terraformersmc.modmenu.config.option.BooleanConfigOption;
import com.terraformersmc.modmenu.config.option.ConfigOption;
import com.terraformersmc.modmenu.config.option.EnumConfigOption;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class ModMenuConfig {
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption("disable_update_checker", new HashSet<>());
public static final BooleanConfigOption UPDATE_CHECKER = new BooleanConfigOption("update_checker", true);
public static final BooleanConfigOption BUTTON_UPDATE_BADGE = new BooleanConfigOption("button_update_badge", true);
public static final EnumConfigOption<UpdateChannel> UPDATE_CHANNEL = new EnumConfigOption<>("update_channel", UpdateChannel.RELEASE);
public static final BooleanConfigOption QUICK_CONFIGURE = new BooleanConfigOption("quick_configure", true);

public static ConfigOption[] asOptions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terraformersmc.modmenu.gui;

import com.terraformersmc.modmenu.ModMenu;
import com.terraformersmc.modmenu.config.ModMenuConfig;
import com.terraformersmc.modmenu.config.ModMenuConfigManager;
import com.terraformersmc.modmenu.gui.widget.ConfigOptionListWidget;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void mouseClicked(int mouseX, int mouseY, int button) {
public void buttonClicked(ButtonWidget button) {
switch (button.id) {
case DONE:
ModMenu.checkForUpdates();
ModMenuConfigManager.save();
ModMenuOptionsScreen.this.minecraft.openScreen(ModMenuOptionsScreen.this.previous);
break;
Expand All @@ -64,6 +66,7 @@ public void buttonClicked(ButtonWidget button) {

@Override
public void removed() {
ModMenu.checkForUpdates();
ModMenuConfigManager.save();
}
}
Loading
Loading