Skip to content

Commit

Permalink
Ported the 2.1.0 update for 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MehradN committed Jul 3, 2023
1 parent e629533 commit 778a6ac
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 47 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# MehradConfig
[![JitPack](https://jitpack.io/v/MehradN/MehradConfig.svg)](https://jitpack.io/#MehradN/MehradConfig)

A simple looking, instance based config library for minecraft.

I made this library to use it in my own mods. Feel free to use it, as it is fully documented and examples are available in the [testmod directory](https://github.com/MehradN/MehradConfig/tree/master/src/testmod).
I made this library to use it in my own mods. Feel free to use it, as it is [fully documented](https://jitpack.io/com/github/MehradN/MehradConfig/latest/javadoc/) and examples are available in the [testmod directory](https://github.com/MehradN/MehradConfig/tree/master/src/testmod).

You can use it in your mods with [JitPack](https://jitpack.io/#MehradN/MehradConfig).
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tasks.withType(JavaCompile).configureEach {

java {
withSourcesJar()
withJavadocJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
parchment_version=1.19.3:2023.03.12
parchment_version=1.19.4:2023.06.26
loader_version=0.14.21

# Mod Properties
mod_version=1.0.0
mod_version=1.1.0
maven_group=ir.mehradn
archives_base_name=mehrad-config

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ir.mehradn.mehradconfig.entrypoint;

import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import java.util.HashMap;
import java.util.Map;

/**
* This class is used for registering your config screen builders for ModMenu.
*
* @see #register
*/
public class ModMenuConfigScreen {
static final Map<String, ConfigScreenBuilder> modMenuScreenBuilders = new HashMap<>();

/**
* Registers a config screen builder to build screens for ModMenu. The screen will be created by {@link ConfigScreenBuilder#buildAndLoad}.
* This method by itself won't register your config, and you need to call {@link ModMenuConfig#register} before this in the main entrypoint of
* your mod.
*
* @param modId the mod id of your mod
* @param configScreenBuilder the config screen builder to build the screen with
*/
public static void register(String modId, ConfigScreenBuilder configScreenBuilder) {
modMenuScreenBuilders.put(modId, configScreenBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import ir.mehradn.mehradconfig.MehradConfig;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

@Environment(EnvType.CLIENT)
public class ModMenuEntrypoint implements ModMenuApi {
private static final ConfigScreenBuilder DEFAULT = new ConfigScreenBuilder().setScreenType(ConfigScreenBuilder.DefaultScreens.COMPACT);

@Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
Map<String, ConfigScreenFactory<?>> factories = new HashMap<>();
for (Map.Entry<String, ModMenuSupport.ConfigScreenLoader> entry : ModMenuSupport.screenBuilders.entrySet())
factories.put(entry.getKey(), (parent) -> entry.getValue().build(parent));
for (String modId : ModMenuConfig.modMenuConfigs.keySet()) {
factories.put(modId, (parent) -> {
Supplier<MehradConfig> configConstructor = ModMenuConfig.modMenuConfigs.get(modId);
ConfigScreenBuilder configScreenBuilder = ModMenuConfigScreen.modMenuScreenBuilders.getOrDefault(modId, DEFAULT);
return configScreenBuilder.buildAndLoad(configConstructor, parent);
});
}
return factories;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public BooleanWidget(int x, int y, int width, int height,
((Widget)this.widget).setReport(this::reportValueChange);
}

@Environment(EnvType.CLIENT)
private static class Widget extends AbstractButton {
private final ConfigEntry<Boolean> entry;
private final TextProvider textProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected void onValueChanged() {
* @see ConfigEntry#getTranslatedTitle
* @see ConfigEntry#getTranslatedValue
*/
@Environment(EnvType.CLIENT)
public interface TextProvider {
/**
* The returned text should be based on the current value of the entry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public EnumWidget(int x, int y, int width, int height,
((Widget<?>)this.widget).setReport(this::reportValueChange);
}

@Environment(EnvType.CLIENT)
private static class Widget <T extends Enum<T>> extends AbstractButton {
private final Class<T> enumClass;
private final ConfigEntry<T> entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.client.gui.components.AbstractSliderButton;

/**
* SliderNumberWidget is a widget for displaying and updating integer config entries in gui using an slider.
* SliderNumberWidget is a widget for displaying and updating integer config entries in gui using a slider.
* It works for config entries that have a constant min and max.
*/
@Environment(EnvType.CLIENT)
Expand All @@ -29,6 +29,7 @@ public void reportValueChange() {
((Widget)this.widget).updateSlider();
}

@Environment(EnvType.CLIENT)
private static class Widget extends AbstractSliderButton {
private final int min;
private final int max;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ir.mehradn.mehradconfig.entrypoint;

import ir.mehradn.mehradconfig.MehradConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
* This class is used for registering your configs for ModMenu.
*
* @see #register
*/
public final class ModMenuConfig {
static final Map<String, Supplier<MehradConfig>> modMenuConfigs = new HashMap<>();

/**
* Registers a config constructor for ModMenu. The screen will by default use the compact default screen type.
* Checkout {@code ModMenuConfigScreen} for customizing the config screen.
*
* @param modId the mod id of your mod
* @param configConstructor a constructor for the type of the config to load, modify and save
*/
public static void register(String modId, Supplier<MehradConfig> configConstructor) {
modMenuConfigs.put(modId, configConstructor);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
},
"depends": {
"java": ">=17",
"minecraft": "~1.19",
"minecraft": "~1.19.4",
"fabricloader": ">=0.14.21",
"fabric-api": ">=0.83.0+1.19.4"
"fabric-api": "*"
},
"custom": {
"modmenu": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ir.mehradn.mehradconfigtest;

import ir.mehradn.mehradconfig.entrypoint.ModMenuSupport;
import ir.mehradn.mehradconfig.entrypoint.ModMenuConfig;
import ir.mehradn.mehradconfig.entrypoint.ModMenuConfigScreen;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import ir.mehradn.mehradconfigtest.config.TestConfig;
import net.fabricmc.api.ModInitializer;
Expand All @@ -25,6 +26,7 @@ public void onInitialize() {
//.setOnSave((minecraft, thisScreen, parentScreen) -> { LOGGER.info("SAVED!"); minecraft.setScreen(parentScreen); })
//.setOnCancel((minecraft, thisScreen, parentScreen) -> { LOGGER.info("CANCELED!"); minecraft.setScreen(parentScreen); })
;
ModMenuSupport.register(MOD_ID, TestConfig::new, builder);
ModMenuConfig.register(MOD_ID, TestConfig::new);
ModMenuConfigScreen.register(MOD_ID, builder);
}
}
4 changes: 2 additions & 2 deletions src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
},
"depends": {
"java": ">=17",
"minecraft": "~1.19",
"minecraft": "~1.19.4",
"fabricloader": ">=0.14.21",
"fabric-api": ">=0.83.0+1.19.4",
"fabric-api": "*",
"mehrad-config": "*"
}
}

0 comments on commit 778a6ac

Please sign in to comment.