mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 17:25:09 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1be14dc3ac | ||
|
|
7e1de67a5e | ||
|
|
da4e59ef3a | ||
|
|
da2c76ed5f |
11
build.gradle
11
build.gradle
@@ -1,18 +1,15 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '0.8-SNAPSHOT'
|
id 'fabric-loom' version '0.11-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_16
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_16
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
archivesBaseName = project.archives_base_name
|
archivesBaseName = project.archives_base_name
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
minecraft {
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url "https://maven.terraformersmc.com/releases" }
|
maven { url "https://maven.terraformersmc.com/releases" }
|
||||||
maven { url "https://jitpack.io" }
|
maven { url "https://jitpack.io" }
|
||||||
@@ -45,7 +42,7 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
it.options.encoding = "UTF-8"
|
it.options.encoding = "UTF-8"
|
||||||
|
|
||||||
// Minecraft 1.17 (21w19a) upwards uses Java 16.
|
// Minecraft 1.17 (21w19a) upwards uses Java 16.
|
||||||
it.options.release = 16
|
it.options.release = 17
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/use
|
# check these on https://fabricmc.net/use
|
||||||
minecraft_version=1.17.1
|
minecraft_version=1.19-rc2
|
||||||
yarn_mappings=1.17.1+build.63
|
yarn_mappings=1.19-rc2+build.1
|
||||||
loader_version=0.11.7
|
loader_version=0.14.6
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.4.0
|
mod_version = 0.5.1
|
||||||
maven_group = eu.midnightdust
|
maven_group = eu.midnightdust
|
||||||
archives_base_name = midnightlib
|
archives_base_name = midnightlib
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||||
fabric_version=0.41.0+1.17
|
fabric_version=0.55.1+1.19
|
||||||
mod_menu_version = 2.0.2
|
mod_menu_version = 4.0.0-beta.4
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package eu.midnightdust.core;
|
|||||||
import eu.midnightdust.core.config.MidnightLibConfig;
|
import eu.midnightdust.core.config.MidnightLibConfig;
|
||||||
import eu.midnightdust.hats.web.HatLoader;
|
import eu.midnightdust.hats.web.HatLoader;
|
||||||
import eu.midnightdust.hats.witch.WitchHatFeatureRenderer;
|
import eu.midnightdust.hats.witch.WitchHatFeatureRenderer;
|
||||||
|
import eu.midnightdust.lib.config.AutoModMenu;
|
||||||
import eu.midnightdust.lib.config.MidnightConfig;
|
import eu.midnightdust.lib.config.MidnightConfig;
|
||||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
@@ -16,6 +17,7 @@ public class MidnightLibClient implements ClientModInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
MidnightConfig.init("midnightlib", MidnightLibConfig.class);
|
MidnightConfig.init("midnightlib", MidnightLibConfig.class);
|
||||||
|
AutoModMenu.hideFromModMenu("puzzle");
|
||||||
|
|
||||||
EntityModelLayerRegistry.registerModelLayer(WitchHatFeatureRenderer.WITCH_HAT_MODEL_LAYER, WitchHatFeatureRenderer::getTexturedModelData);
|
EntityModelLayerRegistry.registerModelLayer(WitchHatFeatureRenderer.WITCH_HAT_MODEL_LAYER, WitchHatFeatureRenderer::getTexturedModelData);
|
||||||
if (MidnightLibConfig.special_hats) HatLoader.init();
|
if (MidnightLibConfig.special_hats) HatLoader.init();
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import net.fabricmc.loader.api.FabricLoader;
|
|||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -25,7 +24,7 @@ public class MixinOptionsScreen extends Screen {
|
|||||||
|
|
||||||
@Inject(at = @At("HEAD"),method = "init")
|
@Inject(at = @At("HEAD"),method = "init")
|
||||||
private void midnightlib$init(CallbackInfo ci) {
|
private void midnightlib$init(CallbackInfo ci) {
|
||||||
if (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) || MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && FabricLoader.getInstance().isModLoaded("modmenu"))
|
if (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) || (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && !FabricLoader.getInstance().isModLoaded("modmenu")))
|
||||||
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width / 2 + 158, this.height / 6 - 12, 20, 20, 0, 0, 20, MIDNIGHTLIB_ICON_TEXTURE, 32, 64, (buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), new TranslatableText("midnightlib.overview.title")));
|
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width / 2 + 158, this.height / 6 - 12, 20, 20, 0, 0, 20, MIDNIGHTLIB_ICON_TEXTURE, 32, 64, (buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), Text.translatable("midnightlib.overview.title")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import net.minecraft.client.font.TextRenderer;
|
|||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.client.gui.Selectable;
|
import net.minecraft.client.gui.Selectable;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.ScreenTexts;
|
|
||||||
import net.minecraft.client.gui.widget.*;
|
import net.minecraft.client.gui.widget.*;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.*;
|
import net.minecraft.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ import java.util.*;
|
|||||||
public class MidnightConfigOverviewScreen extends Screen {
|
public class MidnightConfigOverviewScreen extends Screen {
|
||||||
|
|
||||||
public MidnightConfigOverviewScreen(Screen parent) {
|
public MidnightConfigOverviewScreen(Screen parent) {
|
||||||
super(new TranslatableText( "midnightlib.overview.title"));
|
super(Text.translatable( "midnightlib.overview.title"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
@@ -32,7 +32,7 @@ public class MidnightConfigOverviewScreen extends Screen {
|
|||||||
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
||||||
this.addSelectableChild(this.list);
|
this.addSelectableChild(this.list);
|
||||||
MidnightConfig.configClass.forEach((modid, configClass) ->
|
MidnightConfig.configClass.forEach((modid, configClass) ->
|
||||||
list.addButton(new ButtonWidget(this.width / 2 - 100, this.height - 28, 200, 20, new TranslatableText(modid +".midnightconfig.title"), (button) ->
|
list.addButton(new ButtonWidget(this.width / 2 - 100, this.height - 28, 200, 20, Text.translatable(modid +".midnightconfig.title"), (button) ->
|
||||||
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid)))));
|
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid)))));
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import com.mojang.brigadier.arguments.DoubleArgumentType;
|
|||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -27,7 +27,7 @@ public class AutoCommand {
|
|||||||
command();
|
command();
|
||||||
LiteralArgumentBuilder<ServerCommandSource> finalized = CommandManager.literal("midnightconfig").requires(source -> source.hasPermissionLevel(2)).then(command);
|
LiteralArgumentBuilder<ServerCommandSource> finalized = CommandManager.literal("midnightconfig").requires(source -> source.hasPermissionLevel(2)).then(command);
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(finalized));
|
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, registrationEnvironment) -> dispatcher.register(finalized));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void command() {
|
private void command() {
|
||||||
@@ -73,16 +73,16 @@ public class AutoCommand {
|
|||||||
MidnightConfig.write(modid);
|
MidnightConfig.write(modid);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
source.sendError(new LiteralText("Could not set "+entry.getName()+" to value "+value+": " + e));
|
source.sendError(Text.literal("Could not set "+entry.getName()+" to value "+value+": " + e));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.sendFeedback(new LiteralText("Successfully set " + entry.getName()+" to "+value), true);
|
source.sendFeedback(Text.literal("Successfully set " + entry.getName()+" to "+value), true);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
private int getValue(ServerCommandSource source) {
|
private int getValue(ServerCommandSource source) {
|
||||||
try {
|
try {
|
||||||
source.sendFeedback(new LiteralText("The value of "+entry.getName()+" is "+entry.get(null)), false);
|
source.sendFeedback(Text.literal("The value of "+entry.getName()+" is "+entry.get(null)), false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException ignored) {}
|
catch (IllegalAccessException ignored) {}
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
|||||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
import eu.midnightdust.core.config.MidnightLibConfig;
|
import eu.midnightdust.core.config.MidnightLibConfig;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class AutoModMenu implements ModMenuApi {
|
public class AutoModMenu implements ModMenuApi {
|
||||||
|
protected static List<String> hiddenMods = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
return parent -> MidnightLibConfig.getScreen(parent,"midnightlib");
|
return parent -> MidnightLibConfig.getScreen(parent,"midnightlib");
|
||||||
@@ -16,7 +20,14 @@ public class AutoModMenu implements ModMenuApi {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||||
HashMap<String, ConfigScreenFactory<?>> map = new HashMap<>();
|
HashMap<String, ConfigScreenFactory<?>> map = new HashMap<>();
|
||||||
MidnightConfig.configClass.forEach((modid, cClass) -> map.put(modid, parent -> MidnightConfig.getScreen(parent, modid)));
|
MidnightConfig.configClass.forEach((modid, cClass) -> {
|
||||||
|
if (!hiddenMods.contains(modid))
|
||||||
|
map.put(modid, parent -> MidnightConfig.getScreen(parent, modid));
|
||||||
|
}
|
||||||
|
);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
public static void hideFromModMenu(String hiddenMod) {
|
||||||
|
hiddenMods.add(hiddenMod);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,17 +13,15 @@ import net.minecraft.client.gui.DrawableHelper;
|
|||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.client.gui.Selectable;
|
import net.minecraft.client.gui.Selectable;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.ScreenTexts;
|
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.Style;
|
import net.minecraft.text.Style;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@@ -67,7 +65,7 @@ public abstract class MidnightConfig {
|
|||||||
String tempValue;
|
String tempValue;
|
||||||
boolean inLimits = true;
|
boolean inLimits = true;
|
||||||
String id;
|
String id;
|
||||||
TranslatableText name;
|
Text name;
|
||||||
int index;
|
int index;
|
||||||
ClickableWidget colorButton;
|
ClickableWidget colorButton;
|
||||||
}
|
}
|
||||||
@@ -111,7 +109,7 @@ public abstract class MidnightConfig {
|
|||||||
info.id = modid;
|
info.id = modid;
|
||||||
|
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
if (!e.name().equals("")) info.name = new TranslatableText(e.name());
|
if (!e.name().equals("")) info.name = Text.translatable(e.name());
|
||||||
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true);
|
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true);
|
||||||
else if (type == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false);
|
else if (type == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false);
|
||||||
else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(), false);
|
else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(), false);
|
||||||
@@ -119,14 +117,14 @@ public abstract class MidnightConfig {
|
|||||||
info.max = e.max() == Double.MAX_VALUE ? Integer.MAX_VALUE : (int) e.max();
|
info.max = e.max() == Double.MAX_VALUE ? Integer.MAX_VALUE : (int) e.max();
|
||||||
textField(info, String::length, null, Math.min(e.min(), 0), Math.max(e.max(), 1), true);
|
textField(info, String::length, null, Math.min(e.min(), 0), Math.max(e.max(), 1), true);
|
||||||
} else if (type == boolean.class) {
|
} else if (type == boolean.class) {
|
||||||
Function<Object, Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
Function<Object, Text> func = value -> Text.literal((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
||||||
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||||
info.value = !(Boolean) info.value;
|
info.value = !(Boolean) info.value;
|
||||||
button.setMessage(func.apply(info.value));
|
button.setMessage(func.apply(info.value));
|
||||||
}, func);
|
}, func);
|
||||||
} else if (type.isEnum()) {
|
} else if (type.isEnum()) {
|
||||||
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||||
Function<Object, Text> func = value -> new TranslatableText(modid + ".midnightconfig." + "enum." + type.getSimpleName() + "." + info.value.toString());
|
Function<Object, Text> func = value -> Text.translatable(modid + ".midnightconfig." + "enum." + type.getSimpleName() + "." + info.value.toString());
|
||||||
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||||
int index = values.indexOf(info.value) + 1;
|
int index = values.indexOf(info.value) + 1;
|
||||||
info.value = values.get(index >= values.size() ? 0 : index);
|
info.value = values.get(index >= values.size() ? 0 : index);
|
||||||
@@ -149,7 +147,7 @@ public abstract class MidnightConfig {
|
|||||||
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
||||||
value = f.apply(s);
|
value = f.apply(s);
|
||||||
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
|
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
|
||||||
info.error = inLimits? null : new AbstractMap.SimpleEntry<>(t, new LiteralText(value.doubleValue() < min ?
|
info.error = inLimits? null : new AbstractMap.SimpleEntry<>(t, Text.literal(value.doubleValue() < min ?
|
||||||
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
|
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
|
||||||
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
|
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
|
||||||
}
|
}
|
||||||
@@ -170,7 +168,7 @@ public abstract class MidnightConfig {
|
|||||||
if (!s.contains("#")) s = '#' + s;
|
if (!s.contains("#")) s = '#' + s;
|
||||||
if (!HEXADECIMAL_ONLY.matcher(s).matches()) return false;
|
if (!HEXADECIMAL_ONLY.matcher(s).matches()) return false;
|
||||||
try {
|
try {
|
||||||
info.colorButton.setMessage(new LiteralText("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));
|
info.colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -193,7 +191,7 @@ public abstract class MidnightConfig {
|
|||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
private static class MidnightConfigScreen extends Screen {
|
private static class MidnightConfigScreen extends Screen {
|
||||||
protected MidnightConfigScreen(Screen parent, String modid) {
|
protected MidnightConfigScreen(Screen parent, String modid) {
|
||||||
super(new TranslatableText(modid + ".midnightconfig." + "title"));
|
super(Text.translatable(modid + ".midnightconfig." + "title"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.modid = modid;
|
this.modid = modid;
|
||||||
this.translationPrefix = modid + ".midnightconfig.";
|
this.translationPrefix = modid + ".midnightconfig.";
|
||||||
@@ -250,8 +248,8 @@ public abstract class MidnightConfig {
|
|||||||
this.addSelectableChild(this.list);
|
this.addSelectableChild(this.list);
|
||||||
for (EntryInfo info : entries) {
|
for (EntryInfo info : entries) {
|
||||||
if (info.id.equals(modid)) {
|
if (info.id.equals(modid)) {
|
||||||
TranslatableText name = Objects.requireNonNullElseGet(info.name, () -> new TranslatableText(translationPrefix + info.field.getName()));
|
Text name = Objects.requireNonNullElseGet(info.name, () -> Text.translatable(translationPrefix + info.field.getName()));
|
||||||
ButtonWidget resetButton = new ButtonWidget(width - 205, 0, 40, 20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
|
ButtonWidget resetButton = new ButtonWidget(width - 205, 0, 40, 20, Text.translatable("Reset").formatted(Formatting.RED), (button -> {
|
||||||
info.value = info.defaultValue;
|
info.value = info.defaultValue;
|
||||||
info.tempValue = info.defaultValue.toString();
|
info.tempValue = info.defaultValue.toString();
|
||||||
info.index = 0;
|
info.index = 0;
|
||||||
@@ -263,7 +261,7 @@ public abstract class MidnightConfig {
|
|||||||
|
|
||||||
if (info.widget instanceof Map.Entry) {
|
if (info.widget instanceof Map.Entry) {
|
||||||
Map.Entry<ButtonWidget.PressAction, Function<Object, Text>> widget = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.widget;
|
Map.Entry<ButtonWidget.PressAction, Function<Object, Text>> widget = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.widget;
|
||||||
if (info.field.getType().isEnum()) widget.setValue(value -> new TranslatableText(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString()));
|
if (info.field.getType().isEnum()) widget.setValue(value -> Text.translatable(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString()));
|
||||||
this.list.addButton(List.of(new ButtonWidget(width - 160, 0,150, 20, widget.getValue().apply(info.value), widget.getKey()),resetButton), name);
|
this.list.addButton(List.of(new ButtonWidget(width - 160, 0,150, 20, widget.getValue().apply(info.value), widget.getKey()),resetButton), name);
|
||||||
} else if (info.field.getType() == List.class) {
|
} else if (info.field.getType() == List.class) {
|
||||||
if (!reload) info.index = 0;
|
if (!reload) info.index = 0;
|
||||||
@@ -274,8 +272,8 @@ public abstract class MidnightConfig {
|
|||||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget, done);
|
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget, done);
|
||||||
widget.setTextPredicate(processor);
|
widget.setTextPredicate(processor);
|
||||||
resetButton.setWidth(20);
|
resetButton.setWidth(20);
|
||||||
resetButton.setMessage(new LiteralText("R").formatted(Formatting.RED));
|
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||||
ButtonWidget cycleButton = new ButtonWidget(width - 185, 0, 20, 20, new LiteralText(String.valueOf(info.index)).formatted(Formatting.GOLD), (button -> {
|
ButtonWidget cycleButton = new ButtonWidget(width - 185, 0, 20, 20, Text.literal(String.valueOf(info.index)).formatted(Formatting.GOLD), (button -> {
|
||||||
((List<String>)info.value).remove("");
|
((List<String>)info.value).remove("");
|
||||||
double scrollAmount = list.getScrollAmount();
|
double scrollAmount = list.getScrollAmount();
|
||||||
this.reload = true;
|
this.reload = true;
|
||||||
@@ -293,9 +291,9 @@ public abstract class MidnightConfig {
|
|||||||
widget.setTextPredicate(processor);
|
widget.setTextPredicate(processor);
|
||||||
if (info.field.getAnnotation(Entry.class).isColor()) {
|
if (info.field.getAnnotation(Entry.class).isColor()) {
|
||||||
resetButton.setWidth(20);
|
resetButton.setWidth(20);
|
||||||
resetButton.setMessage(new LiteralText("R").formatted(Formatting.RED));
|
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||||
ButtonWidget colorButton = new ButtonWidget(width - 185, 0, 20, 20, new LiteralText("⬛"), (button -> {}));
|
ButtonWidget colorButton = new ButtonWidget(width - 185, 0, 20, 20, Text.literal("⬛"), (button -> {}));
|
||||||
try {colorButton.setMessage(new LiteralText("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));} catch (Exception ignored) {}
|
try {colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));} catch (Exception ignored) {}
|
||||||
info.colorButton = colorButton;
|
info.colorButton = colorButton;
|
||||||
this.list.addButton(List.of(widget, colorButton, resetButton), name);
|
this.list.addButton(List.of(widget, colorButton, resetButton), name);
|
||||||
}
|
}
|
||||||
@@ -318,14 +316,14 @@ public abstract class MidnightConfig {
|
|||||||
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
|
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
|
||||||
ClickableWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
|
ClickableWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
|
||||||
Text text = ButtonEntry.buttonsWithText.get(buttonWidget);
|
Text text = ButtonEntry.buttonsWithText.get(buttonWidget);
|
||||||
TranslatableText name = new TranslatableText(this.translationPrefix + info.field.getName());
|
Text name = Text.translatable(this.translationPrefix + info.field.getName());
|
||||||
String key = translationPrefix + info.field.getName() + ".tooltip";
|
String key = translationPrefix + info.field.getName() + ".tooltip";
|
||||||
|
|
||||||
if (info.error != null && text.equals(name)) renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
if (info.error != null && text.equals(name)) renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||||
else if (I18n.hasTranslation(key) && text.equals(name)) {
|
else if (I18n.hasTranslation(key) && text.equals(name)) {
|
||||||
List<Text> list = new ArrayList<>();
|
List<Text> list = new ArrayList<>();
|
||||||
for (String str : I18n.translate(key).split("\n"))
|
for (String str : I18n.translate(key).split("\n"))
|
||||||
list.add(new LiteralText(str));
|
list.add(Text.literal(str));
|
||||||
renderTooltip(matrices, list, mouseX, mouseY);
|
renderTooltip(matrices, list, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,7 +377,7 @@ public abstract class MidnightConfig {
|
|||||||
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||||
buttons.forEach(b -> { b.y = y; b.render(matrices, mouseX, mouseY, tickDelta); });
|
buttons.forEach(b -> { b.y = y; b.render(matrices, mouseX, mouseY, tickDelta); });
|
||||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty()))
|
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty()))
|
||||||
DrawableHelper.drawTextWithShadow(matrices,textRenderer, text,12,y+5,0xFFFFFF);
|
DrawableHelper.drawTextWithShadow(matrices,textRenderer, text,12,y+5,0xFFFFFF);
|
||||||
}
|
}
|
||||||
public List<? extends Element> children() {return children;}
|
public List<? extends Element> children() {return children;}
|
||||||
public List<? extends Selectable> selectableChildren() {return children;}
|
public List<? extends Selectable> selectableChildren() {return children;}
|
||||||
|
|||||||
17
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
17
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
@@ -1,5 +1,7 @@
|
|||||||
package eu.midnightdust.lib.config;
|
package eu.midnightdust.lib.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** MidnightConfig documentation & examples:
|
/** MidnightConfig documentation & examples:
|
||||||
* Thanks for choosing MidnightConfig - the fancy, tiny and lightweight config library.
|
* Thanks for choosing MidnightConfig - the fancy, tiny and lightweight config library.
|
||||||
* If you want to use the lib in your mod, here are some examples and hints:
|
* If you want to use the lib in your mod, here are some examples and hints:
|
||||||
@@ -12,14 +14,15 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
@Entry public static int fabric = 16777215; // Example for a int option
|
@Entry public static int fabric = 16777215; // Example for a int option
|
||||||
@Entry public static double world = 1.4D; // Example for a double option
|
@Entry public static double world = 1.4D; // Example for a double option
|
||||||
@Entry public static boolean showInfo = true; // Example for a boolean option
|
@Entry public static boolean showInfo = true; // Example for a boolean option
|
||||||
@Entry public static String name = "Hi"; // Example for a string option
|
@Entry public static String name = "Hello World!"; // Example for a string option
|
||||||
@Entry public static TestEnum testEnum = TestEnum.FABRIC; // Example for a enum option
|
@Entry public static TestEnum testEnum = TestEnum.FABRIC; // Example for a enum option
|
||||||
public static enum TestEnum { // Enums allow the user to cycle through predefined options
|
public enum TestEnum { // Enums allow the user to cycle through predefined options
|
||||||
QUILT, FABRIC
|
QUILT, FABRIC
|
||||||
}
|
}
|
||||||
@Entry(min=10,max=30) public static int hello = 15675965; // - The entered number has to be larger than 10 and smaller than 30
|
@Entry(min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420
|
||||||
@Entry(width = 7, min = 7, isColor = true) public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color
|
@Entry(width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color
|
||||||
@Entry public static List<String> blurExclusions = Mod.defaultExclusions; // Array String Lists are also supported
|
@Entry(name = "I am an array list!") public static List<String> arrayList = List.of("String1", "String2"); // Array String Lists are also supported
|
||||||
|
// The name field can be used to specify a custom translation string or plain text
|
||||||
|
|
||||||
public static int imposter = 16777215; // - Entries without an @Entry or @Comment annotation are ignored
|
public static int imposter = 16777215; // - Entries without an @Entry or @Comment annotation are ignored
|
||||||
|
|
||||||
@@ -28,9 +31,9 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
{
|
{
|
||||||
"modid.midnightconfig.title":"I am a title", // "*.midnightconfig.title" defines the title of the screen
|
"modid.midnightconfig.title":"I am a title", // "*.midnightconfig.title" defines the title of the screen
|
||||||
"modid.midnightconfig.text1":"I am a comment *u*", // Translation for the comment "text1" defined in the example config
|
"modid.midnightconfig.text1":"I am a comment *u*", // Translation for the comment "text1" defined in the example config
|
||||||
"modid.midnightconfig.name":"Pet Name", // Translation for the field "name" defined in the example config
|
"modid.midnightconfig.name":"I am a string!", // Translation for the field "name" defined in the example config
|
||||||
|
|
||||||
"modid.midnightconfig.name.tooltip":"Name your Pet! \n I am a new line uwu",
|
"modid.midnightconfig.name.tooltip":"uwu \n I am a new line",
|
||||||
// When hovering over the option "showInfo",
|
// When hovering over the option "showInfo",
|
||||||
// this text will appear as a tooltip.
|
// this text will appear as a tooltip.
|
||||||
// "\n" inserts a line break.
|
// "\n" inserts a line break.
|
||||||
|
|||||||
@@ -32,13 +32,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"midnightcore.mixins.json"
|
"midnightlib.mixins.json"
|
||||||
],
|
],
|
||||||
|
|
||||||
"depends": {
|
|
||||||
"fabric-renderer-registries-v1": "*"
|
|
||||||
},
|
|
||||||
|
|
||||||
"custom": {
|
"custom": {
|
||||||
"modmenu": {
|
"modmenu": {
|
||||||
"links": {
|
"links": {
|
||||||
|
|||||||
Reference in New Issue
Block a user