mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
Compare commits
11 Commits
v0.4.4
...
fabric-1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d5fcd7e71 | ||
|
|
c501c63d30 | ||
|
|
ac1516293c | ||
|
|
383de29f93 | ||
|
|
71c16ffbb3 | ||
|
|
76166aed49 | ||
|
|
d6e1a5e558 | ||
|
|
191120393c | ||
|
|
1be14dc3ac | ||
|
|
7e1de67a5e | ||
|
|
da4e59ef3a |
13
build.gradle
13
build.gradle
@@ -1,18 +1,15 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.8-SNAPSHOT'
|
||||
id 'fabric-loom' version '0.11-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
minecraft {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.terraformersmc.com/releases" }
|
||||
maven { url "https://jitpack.io" }
|
||||
@@ -26,7 +23,7 @@ dependencies {
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modImplementation ("com.terraformersmc:modmenu:${project.mod_menu_version}")
|
||||
modCompileOnlyApi ("com.terraformersmc:modmenu:${project.mod_menu_version}")
|
||||
}
|
||||
|
||||
processResources {
|
||||
@@ -45,7 +42,7 @@ tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
|
||||
// Minecraft 1.17 (21w19a) upwards uses Java 16.
|
||||
it.options.release = 16
|
||||
it.options.release = 17
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.17.1
|
||||
yarn_mappings=1.17.1+build.63
|
||||
loader_version=0.11.7
|
||||
minecraft_version=22w43a
|
||||
yarn_mappings=22w43a+build.4
|
||||
loader_version=0.14.10
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.4.0
|
||||
mod_version = 0.6.1+22w43a
|
||||
maven_group = eu.midnightdust
|
||||
archives_base_name = midnightlib
|
||||
|
||||
# Dependencies
|
||||
# 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
|
||||
mod_menu_version = 2.0.2
|
||||
fabric_version=0.65.1+1.19.3
|
||||
mod_menu_version = 4.0.0-beta.4
|
||||
|
||||
@@ -9,13 +9,18 @@ import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MidnightLibClient implements ClientModInitializer {
|
||||
public static List<String> hiddenMods = new ArrayList<>();
|
||||
|
||||
public static final String MOD_ID = "midnightlib";
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
MidnightConfig.init("midnightlib", MidnightLibConfig.class);
|
||||
hiddenMods.add("puzzle");
|
||||
|
||||
EntityModelLayerRegistry.registerModelLayer(WitchHatFeatureRenderer.WITCH_HAT_MODEL_LAYER, WitchHatFeatureRenderer::getTexturedModelData);
|
||||
if (MidnightLibConfig.special_hats) HatLoader.init();
|
||||
|
||||
@@ -12,7 +12,7 @@ public class MidnightLibServer implements DedicatedServerModInitializer {
|
||||
public void onInitializeServer() {
|
||||
MidnightConfig.configClass.forEach((modid, config) -> {
|
||||
for (Field field : config.getFields()) {
|
||||
if (field.isAnnotationPresent(MidnightConfig.Entry.class) && !field.isAnnotationPresent(MidnightConfig.Client.class))
|
||||
if (field.isAnnotationPresent(MidnightConfig.Entry.class) && !field.isAnnotationPresent(MidnightConfig.Client.class) && !field.isAnnotationPresent(MidnightConfig.Hidden.class))
|
||||
new AutoCommand(field, modid).register();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,10 +4,10 @@ import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
public class MidnightLibConfig extends MidnightConfig {
|
||||
@Comment public static Comment midnightlib_description;
|
||||
@Comment(centered = true) public static Comment midnightlib_description;
|
||||
@Entry // Enable or disable the MidnightConfig overview screen button
|
||||
public static ConfigButton config_screen_list = FabricLoader.getInstance().isModLoaded("modmenu") ? ConfigButton.MODMENU : ConfigButton.TRUE;
|
||||
@Comment public static Comment midnighthats_description;
|
||||
@Comment(centered = true) public static Comment midnighthats_description;
|
||||
@Entry // Enable or disable hats for contributors, friends and donors.
|
||||
public static boolean special_hats = true;
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -25,7 +24,7 @@ public class MixinOptionsScreen extends Screen {
|
||||
|
||||
@Inject(at = @At("HEAD"),method = "init")
|
||||
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"))
|
||||
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")));
|
||||
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)), Text.translatable("midnightlib.overview.title")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.midnightdust.core.screen;
|
||||
|
||||
import eu.midnightdust.core.MidnightLibClient;
|
||||
import eu.midnightdust.core.config.MidnightLibConfig;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
@@ -8,9 +10,9 @@ import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ScreenTexts;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.*;
|
||||
import java.util.*;
|
||||
|
||||
@@ -18,7 +20,7 @@ import java.util.*;
|
||||
public class MidnightConfigOverviewScreen extends Screen {
|
||||
|
||||
public MidnightConfigOverviewScreen(Screen parent) {
|
||||
super(new TranslatableText( "midnightlib.overview.title"));
|
||||
super(Text.translatable( "midnightlib.overview.title"));
|
||||
this.parent = parent;
|
||||
}
|
||||
private final Screen parent;
|
||||
@@ -26,14 +28,19 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height - 28, 200, 20, ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)));
|
||||
this.addDrawableChild(ButtonWidget.method_46430(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).method_46434(this.width / 2 - 100, this.height - 28, 200, 20).method_46431());
|
||||
|
||||
this.list = new MidnightOverviewListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
|
||||
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
||||
this.addSelectableChild(this.list);
|
||||
MidnightConfig.configClass.forEach((modid, configClass) ->
|
||||
list.addButton(new ButtonWidget(this.width / 2 - 100, this.height - 28, 200, 20, new TranslatableText(modid +".midnightconfig.title"), (button) ->
|
||||
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid)))));
|
||||
List<String> sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet());
|
||||
Collections.sort(sortedMods);
|
||||
sortedMods.forEach((modid) -> {
|
||||
if (!MidnightLibClient.hiddenMods.contains(modid)) {
|
||||
list.addButton(ButtonWidget.method_46430(Text.translatable(modid +".midnightconfig.title"), (button) ->
|
||||
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid))).method_46434(this.width / 2 - 100, this.height - 28, 200, 20).method_46431());
|
||||
}
|
||||
});
|
||||
super.init();
|
||||
}
|
||||
@Override
|
||||
@@ -71,7 +78,7 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
}
|
||||
public static OverviewButtonEntry create(ClickableWidget button) {return new OverviewButtonEntry(button);}
|
||||
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
button.y = y;
|
||||
button.method_46419(y);
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
public List<? extends Element> children() {return buttonList;}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
@@ -27,7 +27,7 @@ public class AutoCommand {
|
||||
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() {
|
||||
@@ -73,16 +73,16 @@ public class AutoCommand {
|
||||
MidnightConfig.write(modid);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
source.sendFeedback(new LiteralText("Successfully set " + entry.getName()+" to "+value), true);
|
||||
source.sendFeedback(Text.literal("Successfully set " + entry.getName()+" to "+value), true);
|
||||
return 1;
|
||||
}
|
||||
private int getValue(ServerCommandSource source) {
|
||||
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;
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
|
||||
@@ -2,12 +2,14 @@ package eu.midnightdust.lib.config;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import eu.midnightdust.core.MidnightLibClient;
|
||||
import eu.midnightdust.core.config.MidnightLibConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AutoModMenu implements ModMenuApi {
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return parent -> MidnightLibConfig.getScreen(parent,"midnightlib");
|
||||
@@ -16,7 +18,11 @@ public class AutoModMenu implements ModMenuApi {
|
||||
@Override
|
||||
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||
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 (!MidnightLibClient.hiddenMods.contains(modid))
|
||||
map.put(modid, parent -> MidnightConfig.getScreen(parent, modid));
|
||||
}
|
||||
);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,15 @@ import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.Selectable;
|
||||
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.ClickableWidget;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
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.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.awt.Color;
|
||||
@@ -42,7 +40,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** MidnightConfig v2.1.0 by TeamMidnightDust & Motschen
|
||||
/** MidnightConfig v2.2.0 by TeamMidnightDust & Motschen
|
||||
* Single class config library - feel free to copy!
|
||||
*
|
||||
* Based on https://github.com/Minenash/TinyConfig
|
||||
@@ -61,13 +59,14 @@ public abstract class MidnightConfig {
|
||||
Object widget;
|
||||
int width;
|
||||
int max;
|
||||
boolean centered;
|
||||
Map.Entry<TextFieldWidget,Text> error;
|
||||
Object defaultValue;
|
||||
Object value;
|
||||
String tempValue;
|
||||
boolean inLimits = true;
|
||||
String id;
|
||||
TranslatableText name;
|
||||
Text name;
|
||||
int index;
|
||||
ClickableWidget colorButton;
|
||||
}
|
||||
@@ -83,8 +82,9 @@ public abstract class MidnightConfig {
|
||||
|
||||
for (Field field : config.getFields()) {
|
||||
EntryInfo info = new EntryInfo();
|
||||
if ((field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class)) && !field.isAnnotationPresent(Server.class))
|
||||
if ((field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class)) && !field.isAnnotationPresent(Server.class) && !field.isAnnotationPresent(Hidden.class))
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) initClient(modid, field, info);
|
||||
if (field.isAnnotationPresent(Comment.class)) info.centered = field.getAnnotation(Comment.class).centered();
|
||||
if (field.isAnnotationPresent(Entry.class))
|
||||
try {
|
||||
info.defaultValue = field.get(null);
|
||||
@@ -98,8 +98,7 @@ public abstract class MidnightConfig {
|
||||
try {
|
||||
info.value = info.field.get(null);
|
||||
info.tempValue = info.value.toString();
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
@@ -111,7 +110,7 @@ public abstract class MidnightConfig {
|
||||
info.id = modid;
|
||||
|
||||
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);
|
||||
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);
|
||||
@@ -119,14 +118,14 @@ public abstract class MidnightConfig {
|
||||
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);
|
||||
} 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.translatable((Boolean) value ? "gui.yes" : "gui.no").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
||||
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||
info.value = !(Boolean) info.value;
|
||||
button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
} else if (type.isEnum()) {
|
||||
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 -> {
|
||||
int index = values.indexOf(info.value) + 1;
|
||||
info.value = values.get(index >= values.size() ? 0 : index);
|
||||
@@ -149,7 +148,7 @@ public abstract class MidnightConfig {
|
||||
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
||||
value = f.apply(s);
|
||||
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) :
|
||||
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
|
||||
}
|
||||
@@ -170,7 +169,7 @@ public abstract class MidnightConfig {
|
||||
if (!s.contains("#")) s = '#' + s;
|
||||
if (!HEXADECIMAL_ONLY.matcher(s).matches()) return false;
|
||||
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) {}
|
||||
}
|
||||
return true;
|
||||
@@ -191,18 +190,18 @@ public abstract class MidnightConfig {
|
||||
return new MidnightConfigScreen(parent, modid);
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static class MidnightConfigScreen extends Screen {
|
||||
public static class MidnightConfigScreen extends Screen {
|
||||
protected MidnightConfigScreen(Screen parent, String modid) {
|
||||
super(new TranslatableText(modid + ".midnightconfig." + "title"));
|
||||
super(Text.translatable(modid + ".midnightconfig." + "title"));
|
||||
this.parent = parent;
|
||||
this.modid = modid;
|
||||
this.translationPrefix = modid + ".midnightconfig.";
|
||||
}
|
||||
private final String translationPrefix;
|
||||
private final Screen parent;
|
||||
private final String modid;
|
||||
private MidnightConfigListWidget list;
|
||||
private boolean reload = false;
|
||||
public final String translationPrefix;
|
||||
public final Screen parent;
|
||||
public final String modid;
|
||||
public MidnightConfigListWidget list;
|
||||
public boolean reload = false;
|
||||
|
||||
// Real Time config update //
|
||||
@Override
|
||||
@@ -211,8 +210,18 @@ public abstract class MidnightConfig {
|
||||
for (EntryInfo info : entries) {
|
||||
try {info.field.set(null, info.value);} catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
updateResetButtons();
|
||||
}
|
||||
private void loadValues() {
|
||||
public void updateResetButtons() {
|
||||
if (this.list != null) {
|
||||
for (ButtonEntry entry : this.list.children()) {
|
||||
if (entry.buttons != null && entry.buttons.size() > 1 && entry.buttons.get(1) instanceof ButtonWidget button) {
|
||||
button.active = !Objects.equals(entry.info.value.toString(), entry.info.defaultValue.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void loadValues() {
|
||||
try { gson.fromJson(Files.newBufferedReader(path), configClass.get(modid)); }
|
||||
catch (Exception e) { write(modid); }
|
||||
|
||||
@@ -225,16 +234,16 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void init() {
|
||||
public void init() {
|
||||
super.init();
|
||||
if (!reload) loadValues();
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(this.width / 2 - 154, this.height - 28, 150, 20, ScreenTexts.CANCEL, button -> {
|
||||
this.addDrawableChild(ButtonWidget.method_46430(ScreenTexts.CANCEL, button -> {
|
||||
loadValues();
|
||||
Objects.requireNonNull(client).setScreen(parent);
|
||||
}));
|
||||
}).method_46434(this.width / 2 - 154, this.height - 28, 150, 20).method_46431());
|
||||
|
||||
ButtonWidget done = this.addDrawableChild(new ButtonWidget(this.width / 2 + 4, this.height - 28, 150, 20, ScreenTexts.DONE, (button) -> {
|
||||
ButtonWidget done = this.addDrawableChild(ButtonWidget.method_46430(ScreenTexts.DONE, (button) -> {
|
||||
for (EntryInfo info : entries)
|
||||
if (info.id.equals(modid)) {
|
||||
try {
|
||||
@@ -243,15 +252,15 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
write(modid);
|
||||
Objects.requireNonNull(client).setScreen(parent);
|
||||
}));
|
||||
}).method_46434(this.width / 2 + 4, this.height - 28, 150, 20).method_46431());
|
||||
|
||||
this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
|
||||
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
||||
this.addSelectableChild(this.list);
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.id.equals(modid)) {
|
||||
TranslatableText name = Objects.requireNonNullElseGet(info.name, () -> new TranslatableText(translationPrefix + info.field.getName()));
|
||||
ButtonWidget resetButton = new ButtonWidget(width - 205, 0, 40, 20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
|
||||
Text name = Objects.requireNonNullElseGet(info.name, () -> Text.translatable(translationPrefix + info.field.getName()));
|
||||
ButtonWidget resetButton = ButtonWidget.method_46430(Text.translatable("Reset").formatted(Formatting.RED), (button -> {
|
||||
info.value = info.defaultValue;
|
||||
info.tempValue = info.defaultValue.toString();
|
||||
info.index = 0;
|
||||
@@ -259,12 +268,12 @@ public abstract class MidnightConfig {
|
||||
this.reload = true;
|
||||
Objects.requireNonNull(client).setScreen(this);
|
||||
list.setScrollAmount(scrollAmount);
|
||||
}));
|
||||
})).method_46434(width - 205, 0, 40, 20).method_46431();
|
||||
|
||||
if (info.widget instanceof Map.Entry) {
|
||||
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()));
|
||||
this.list.addButton(List.of(new ButtonWidget(width - 160, 0,150, 20, widget.getValue().apply(info.value), widget.getKey()),resetButton), name);
|
||||
if (info.field.getType().isEnum()) widget.setValue(value -> Text.translatable(translationPrefix + "enum." + info.field.getType().getSimpleName() + "." + info.value.toString()));
|
||||
this.list.addButton(List.of(ButtonWidget.method_46430(widget.getValue().apply(info.value), widget.getKey()).method_46434(width - 160, 0,150, 20).method_46431(),resetButton), name, info);
|
||||
} else if (info.field.getType() == List.class) {
|
||||
if (!reload) info.index = 0;
|
||||
TextFieldWidget widget = new TextFieldWidget(textRenderer, width - 160, 0, 150, 20, null);
|
||||
@@ -274,8 +283,8 @@ public abstract class MidnightConfig {
|
||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget, done);
|
||||
widget.setTextPredicate(processor);
|
||||
resetButton.setWidth(20);
|
||||
resetButton.setMessage(new LiteralText("R").formatted(Formatting.RED));
|
||||
ButtonWidget cycleButton = new ButtonWidget(width - 185, 0, 20, 20, new LiteralText(String.valueOf(info.index)).formatted(Formatting.GOLD), (button -> {
|
||||
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||
ButtonWidget cycleButton = ButtonWidget.method_46430(Text.literal(String.valueOf(info.index)).formatted(Formatting.GOLD), (button -> {
|
||||
((List<String>)info.value).remove("");
|
||||
double scrollAmount = list.getScrollAmount();
|
||||
this.reload = true;
|
||||
@@ -283,8 +292,8 @@ public abstract class MidnightConfig {
|
||||
if (info.index > ((List<String>)info.value).size()) info.index = 0;
|
||||
Objects.requireNonNull(client).setScreen(this);
|
||||
list.setScrollAmount(scrollAmount);
|
||||
}));
|
||||
this.list.addButton(List.of(widget, resetButton, cycleButton), name);
|
||||
})).method_46434(width - 185, 0, 20, 20).method_46431();
|
||||
this.list.addButton(List.of(widget, resetButton, cycleButton), name, info);
|
||||
} else if (info.widget != null) {
|
||||
TextFieldWidget widget = new TextFieldWidget(textRenderer, width - 160, 0, 150, 20, null);
|
||||
widget.setMaxLength(info.width);
|
||||
@@ -293,17 +302,19 @@ public abstract class MidnightConfig {
|
||||
widget.setTextPredicate(processor);
|
||||
if (info.field.getAnnotation(Entry.class).isColor()) {
|
||||
resetButton.setWidth(20);
|
||||
resetButton.setMessage(new LiteralText("R").formatted(Formatting.RED));
|
||||
ButtonWidget colorButton = new ButtonWidget(width - 185, 0, 20, 20, new LiteralText("⬛"), (button -> {}));
|
||||
try {colorButton.setMessage(new LiteralText("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));} catch (Exception ignored) {}
|
||||
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||
ButtonWidget colorButton = ButtonWidget.method_46430(Text.literal("⬛"), (button -> {})).method_46434(width - 185, 0, 20, 20).method_46431();
|
||||
try {colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));} catch (Exception ignored) {}
|
||||
info.colorButton = colorButton;
|
||||
this.list.addButton(List.of(widget, colorButton, resetButton), name);
|
||||
colorButton.active = false;
|
||||
this.list.addButton(List.of(widget, resetButton, colorButton), name, info);
|
||||
}
|
||||
else this.list.addButton(List.of(widget, resetButton), name);
|
||||
else this.list.addButton(List.of(widget, resetButton), name, info);
|
||||
} else {
|
||||
this.list.addButton(List.of(),name);
|
||||
this.list.addButton(List.of(),name, info);
|
||||
}
|
||||
}
|
||||
updateResetButtons();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -318,14 +329,14 @@ public abstract class MidnightConfig {
|
||||
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
|
||||
ClickableWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
|
||||
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";
|
||||
|
||||
if (info.error != null && text.equals(name)) renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||
else if (I18n.hasTranslation(key) && text.equals(name)) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
for (String str : I18n.translate(key).split("\n"))
|
||||
list.add(new LiteralText(str));
|
||||
list.add(Text.literal(str));
|
||||
renderTooltip(matrices, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -346,8 +357,8 @@ public abstract class MidnightConfig {
|
||||
@Override
|
||||
public int getScrollbarPositionX() { return this.width -7; }
|
||||
|
||||
public void addButton(List<ClickableWidget> buttons, Text text) {
|
||||
this.addEntry(ButtonEntry.create(buttons, text));
|
||||
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) {
|
||||
this.addEntry(ButtonEntry.create(buttons, text, info));
|
||||
}
|
||||
@Override
|
||||
public int getRowWidth() { return 10000; }
|
||||
@@ -364,22 +375,26 @@ public abstract class MidnightConfig {
|
||||
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
public final List<ClickableWidget> buttons;
|
||||
private final Text text;
|
||||
public final EntryInfo info;
|
||||
private final List<ClickableWidget> children = new ArrayList<>();
|
||||
public static final Map<ClickableWidget, Text> buttonsWithText = new HashMap<>();
|
||||
|
||||
private ButtonEntry(List<ClickableWidget> buttons, Text text) {
|
||||
private ButtonEntry(List<ClickableWidget> buttons, Text text, EntryInfo info) {
|
||||
if (!buttons.isEmpty()) buttonsWithText.put(buttons.get(0),text);
|
||||
this.buttons = buttons;
|
||||
this.text = text;
|
||||
this.info = info;
|
||||
children.addAll(buttons);
|
||||
}
|
||||
public static ButtonEntry create(List<ClickableWidget> buttons, Text text) {
|
||||
return new ButtonEntry(buttons, text);
|
||||
public static ButtonEntry create(List<ClickableWidget> buttons, Text text, EntryInfo info) {
|
||||
return new ButtonEntry(buttons, text, info);
|
||||
}
|
||||
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); });
|
||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty()))
|
||||
DrawableHelper.drawTextWithShadow(matrices,textRenderer, text,12,y+5,0xFFFFFF);
|
||||
buttons.forEach(b -> { b.method_46419(y); b.render(matrices, mouseX, mouseY, tickDelta); });
|
||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
||||
if (info.centered) textRenderer.drawWithShadow(matrices, text, MinecraftClient.getInstance().getWindow().getScaledWidth() / 2f - (textRenderer.getWidth(text) / 2f), y + 5, 0xFFFFFF);
|
||||
else DrawableHelper.drawTextWithShadow(matrices, textRenderer, text, 12, y + 5, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
public List<? extends Element> children() {return children;}
|
||||
public List<? extends Selectable> selectableChildren() {return children;}
|
||||
@@ -393,7 +408,10 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Client {}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Server {}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Hidden {}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {
|
||||
boolean centered() default false;
|
||||
}
|
||||
|
||||
public static class HiddenAnnotationExclusionStrategy implements ExclusionStrategy {
|
||||
public boolean shouldSkipClass(Class<?> clazz) { return false; }
|
||||
|
||||
0
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
0
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
@@ -32,8 +32,8 @@ public class TexturedOverlayButtonWidget extends TexturedButtonWidget {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
this.drawTexture(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
|
||||
this.drawTexture(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
|
||||
this.drawTexture(matrices, this.method_46426(), this.method_46427(), 0, 46 + i * 20, this.width / 2, this.height);
|
||||
this.drawTexture(matrices, this.method_46426() + this.width / 2, this.method_46427(), 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
|
||||
|
||||
super.renderButton(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
BIN
src/main/resources/assets/midnightlib/icon.png
Executable file → Normal file
BIN
src/main/resources/assets/midnightlib/icon.png
Executable file → Normal file
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 2.7 KiB |
17
src/main/resources/assets/midnightlib/lang/uk_ua.json
Normal file
17
src/main/resources/assets/midnightlib/lang/uk_ua.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"midnightlib.overview.title":"Огляд MidnightConfig",
|
||||
"midnightlib.midnightconfig.title":"Конфігурація MidnightLib",
|
||||
"midnightlib.midnightconfig.midnightlib_description":"§nMidnightLib",
|
||||
"midnightlib.midnightconfig.config_screen_list":"Увімкнути список екрана конфігурації",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.TRUE":"§aTrue",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.FALSE":"§cFalse",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.MODMENU":"§bModMenu",
|
||||
"midnightlib.midnightconfig.background_texture":"Текстура фону екрана конфігурації",
|
||||
"midnightlib.midnightconfig.midnighthats_description":"§nMidnightHats",
|
||||
"midnightlib.midnightconfig.special_hats":"Увімкнути капелюхи спонсорів",
|
||||
"midnightlib.modrinth":"Modrinth",
|
||||
"midnightlib.curseforge":"CurseForge",
|
||||
"midnightlib.wiki":"Вікі",
|
||||
"modmenu.descriptionTranslation.midnightlib": "Загальна бібліотека для модів команди MidnightDust.\nНадає конфігураційний API, автоматичну інтеграцію з іншими модами, загальні утиліти та косметику.",
|
||||
"modmenu.summaryTranslation.midnightlib": "Загальна бібліотека для модів команди MidnightDust."
|
||||
}
|
||||
@@ -32,13 +32,9 @@
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
"midnightcore.mixins.json"
|
||||
"midnightlib.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabric-renderer-registries-v1": "*"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"links": {
|
||||
|
||||
Reference in New Issue
Block a user