Skip to content

Commit

Permalink
Remove unused, hardcode go bye bye
Browse files Browse the repository at this point in the history
* Deprecated some API usages
* Make the mod localizable (does not necessarily require Halplibe)
* Bump mod version to 2.0.1
  • Loading branch information
Flamarine committed Sep 28, 2023
1 parent 225d039 commit a542a5d
Show file tree
Hide file tree
Showing 34 changed files with 412 additions and 71 deletions.
23 changes: 17 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.quiltmc.loom" version "1.+"
id "babric-loom" version "1.1.+"
id 'java'
}

Expand All @@ -8,14 +8,14 @@ archivesBaseName = project.mod_name
version = project.mod_version

loom {
clientOnlyMinecraftJar()
//serverOnlyMinecraftJar()
gluedMinecraftJar()
noIntermediateMappings()
customMinecraftManifest.set("https://github.com/MartinSVK12/bta-manifest-repo/releases/download/v${project.bta_version}/${project.bta_version}.json")
customMinecraftManifest.set("https://github.com/Turnip-Labs/bta-manifest-repo/releases/download/v${project.bta_version}/${project.bta_version}.json")
}

repositories {
mavenCentral()
maven { url = "https://jitpack.io" }
maven {
name = 'Babric'
url = 'https://maven.glass-launcher.net/babric'
Expand Down Expand Up @@ -63,17 +63,28 @@ dependencies {
mappings loom.layered {}

modRuntimeOnly "objects:client:43db9b498cb67058d2e12d394e6507722e71bb45" // https://piston-data.mojang.com/v1/objects/43db9b498cb67058d2e12d394e6507722e71bb45/client.jar
modImplementation("quilt-loader:quilt-loader:${project.loader_version}")
modImplementation "fabric-loader:fabric-loader:${project.loader_version}"

// Helper library for translations
modImplementation "com.github.Turnip-Labs:bta-halplibe:${project.halplibe_version}"

implementation include("org.apache.commons:commons-lang3:3.12.0")

implementation include("com.google.guava:guava:28.0-jre")
implementation include(group: 'com.google.code.gson', name: 'gson', version: '2.8.6')
implementation include("com.google.code.gson:gson:2.8.6")

modImplementation "org.slf4j:slf4j-api:1.8.0-beta4"
modImplementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ org.gradle.jvmargs=-Xmx1G
# Also makes builds more reliable and less likely to randomly fail.
org.gradle.daemon=false

mod_version=2.0.0
mod_version=2.0.1
mod_group=io.github.turniplabs
mod_name=modmenu-bta

# yarn_mappings=df0e26c
bta_version=1.7.7.0
loader_version=0.20.0-beta.3-bta
bta_version=1.7.7.0_02
loader_version=0.14.19-babric.1-bta
halplibe_version=2.3.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
34 changes: 26 additions & 8 deletions src/main/java/io/github/prospector/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@
import io.github.prospector.modmenu.config.ModMenuConfigManager;
import io.github.prospector.modmenu.util.HardcodedUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;
import net.fabricmc.loader.api.metadata.ModEnvironment;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.options.GuiOptionsPageGeneral;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.NumberFormat;
import java.util.*;
import java.util.function.Function;

public class ModMenu implements ClientModInitializer {
public static final String MOD_ID = "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();

private static final Map<String, Runnable> LEGACY_CONFIG_SCREEN_TASKS = new HashMap<>();
Expand All @@ -34,7 +39,6 @@ public class ModMenu implements ClientModInitializer {
public static final Map<String, Map<String, Map.Entry<Integer, Integer>>> CUSTOM_BADGE_MODS = new HashMap<>();
public static final LinkedListMultimap<ModContainer, ModContainer> PARENT_MAP = LinkedListMultimap.create();
private static ImmutableMap<String, Function<GuiScreen, ? extends GuiScreen>> configScreenFactories = ImmutableMap.of();
private static int libraryCount = 0;

public static boolean hasConfigScreenFactory(String modid) {
return configScreenFactories.containsKey(modid);
Expand Down Expand Up @@ -64,20 +68,22 @@ public static void addLibraryMod(String modid) {
LIBRARY_MODS.add(modid);
}

@SuppressWarnings("RedundantCollectionOperation")
@Override
public void onInitializeClient() {
ModMenuConfigManager.initializeConfig();
ImmutableMap.Builder<String, Function<GuiScreen, ? extends GuiScreen>> factories = ImmutableMap.builder();
FabricLoader.getInstance().getEntrypoints("modmenu", ModMenuApi.class).forEach(api -> {
FabricLoader.getInstance().getEntrypointContainers("modmenu", ModMenuApi.class).forEach(entrypoint -> {
ModMenuApi api = entrypoint.getEntrypoint();
ModContainer mod = entrypoint.getProvider();
try {
api.getClass().getDeclaredMethod("getConfigScreenFactory"); // Make sure the method is implemented
factories.put(api.getModId(), api.getConfigScreenFactory());
} catch (NoSuchMethodException ignored) {
}
factories.put(mod.getMetadata().getId(), api.getConfigScreenFactory());
} catch (NoSuchMethodException ignored) {}
api.attachCustomBadges((name, outlineColor, fillColor) -> {
Map<String, Map.Entry<Integer, Integer>> map = new HashMap<>();
map.put(name, new AbstractMap.SimpleEntry<>(outlineColor, fillColor));
CUSTOM_BADGE_MODS.put(api.getModId(), map);
CUSTOM_BADGE_MODS.put(mod.getMetadata().getId(), map);
});
});
factories.put("minecraft", (screenBase -> new GuiOptionsPageGeneral(screenBase, ((Minecraft) FabricLoader.getInstance().getGameInstance()).gameSettings)));
Expand All @@ -87,21 +93,34 @@ public void onInitializeClient() {
for (ModContainer mod : mods) {
ModMetadata metadata = mod.getMetadata();
String id = metadata.getId();
// API badges
if (metadata.containsCustomValue("modmenu:api") && metadata.getCustomValue("modmenu:api").getAsBoolean()) {
addLibraryMod(id);
}
if (metadata.containsCustomValue("modmenu:clientsideOnly") && metadata.getCustomValue("modmenu:clientsideOnly").getAsBoolean()) {

// Client side badges
if (metadata.getEnvironment().equals(ModEnvironment.CLIENT)) {
CLIENTSIDE_MODS.add(id);
}
if (metadata.containsCustomValue("modmenu:clientsideOnly") && metadata.getCustomValue("modmenu:clientsideOnly").getAsBoolean()) {
LOGGER.warn("Found mod with id \"{}\" using deprecated value \"modmenu:clientsideOnly\"!", metadata.getId());
if (!(CLIENTSIDE_MODS.contains(id))) CLIENTSIDE_MODS.add(id);
}

// Deprecated badges
if (metadata.containsCustomValue("modmenu:deprecated") && metadata.getCustomValue("modmenu:deprecated").getAsBoolean()) {
DEPRECATED_MODS.add(id);
}

// Patchwork (unused)
if (metadata.containsCustomValue("patchwork:source") && metadata.getCustomValue("patchwork:source").getAsObject() != null) {
CustomValue.CvObject object = metadata.getCustomValue("patchwork:source").getAsObject();
if ("forge".equals(object.get("loader").getAsString())) {
PATCHWORK_FORGE_MODS.add(id);
}
}

// Parent mods
if (metadata.containsCustomValue("modmenu:parent")) {
String parentId = metadata.getCustomValue("modmenu:parent").getAsString();
if (parentId != null) {
Expand All @@ -112,7 +131,6 @@ public void onInitializeClient() {
HardcodedUtil.hardcodeModuleMetadata(mod, metadata, id);
}
}
libraryCount = LIBRARY_MODS.size();
}

public static String getFormattedModCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ static void addConfigOverride(String modid, Runnable action) {

/**
* Used to determine the owner of this API implementation.
* Will be deprecated and removed once Fabric has support
* for providing ownership information about entry points.
*
* @deprecated This method is deprecated as Fabric Loader
* itself provides provider info for entrypoints.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.1.0")
String getModId();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.github.prospector.modmenu.util.HardcodedUtil;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.core.lang.I18n;

import java.util.Comparator;

Expand All @@ -29,23 +30,23 @@ public Sorting getSorting() {
}

public enum Sorting {
ASCENDING(Comparator.comparing(modContainer -> HardcodedUtil.formatFabricModuleName(modContainer.getMetadata().getName())), "A-Z"),
DECENDING(ASCENDING.getComparator().reversed(), "Z-A");
ASCENDING(Comparator.comparing(modContainer -> HardcodedUtil.formatFabricModuleName(modContainer.getMetadata().getName())), "modmenu.sorting.ascending"),
DECENDING(ASCENDING.getComparator().reversed(), "modmenu.sorting.decending");

final Comparator<ModContainer> comparator;
final String name;
final String key;

Sorting(Comparator<ModContainer> comparator, String name) {
Sorting(Comparator<ModContainer> comparator, String key) {
this.comparator = comparator;
this.name = name;
this.key = key;
}

public Comparator<ModContainer> getComparator() {
return comparator;
}

public String getName() {
return name;
return I18n.getInstance().translateKey(key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.loader.api.metadata.Person;
import net.minecraft.client.Minecraft;
import net.minecraft.client.render.FontRenderer;
import net.minecraft.core.lang.I18n;

import java.util.Collection;

Expand Down Expand Up @@ -37,6 +38,7 @@ protected int getScrollbarPosition() {

@Override
public void render(int mouseX, int mouseY, float delta) {
I18n i18n = I18n.getInstance();
ModListEntry selectedEntry = parent.getSelectedEntry();
if (selectedEntry != lastSelected) {
lastSelected = selectedEntry;
Expand All @@ -57,21 +59,21 @@ public void render(int mouseX, int mouseY, float delta) {
}
if (!authors.isEmpty()) {
if (!children().isEmpty()) children().add(new DescriptionEntry(""));
children().add(new DescriptionEntry("Authors:"));
children().add(new DescriptionEntry(i18n.translateKey("modmenu.authors")));
for (Person person : authors) {
children().add(new DescriptionEntry(" " + person.getName()));
}
}
if (!contributors.isEmpty()) {
if (!children().isEmpty()) children().add(new DescriptionEntry(""));
children().add(new DescriptionEntry("Contributors:"));
children().add(new DescriptionEntry(i18n.translateKey("modmenu.contributors")));
for (Person person : contributors) {
children().add(new DescriptionEntry(" " + person.getName()));
}
}
if (!licenses.isEmpty()) {
if (!children().isEmpty()) children().add(new DescriptionEntry(""));
children().add(new DescriptionEntry("Licenses:"));
children().add(new DescriptionEntry(i18n.translateKey("modmenu.licenses")));
for (String license : licenses) {
children().add(new DescriptionEntry(" " + license));
}
Expand Down
Loading

0 comments on commit a542a5d

Please sign in to comment.