mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
Compare commits
21 Commits
v0.2.8
...
fabric-1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f70460ff65 | ||
|
|
c63cf9c515 | ||
|
|
38396c1886 | ||
|
|
ac1516293c | ||
|
|
383de29f93 | ||
|
|
71c16ffbb3 | ||
|
|
76166aed49 | ||
|
|
d6e1a5e558 | ||
|
|
191120393c | ||
|
|
1be14dc3ac | ||
|
|
7e1de67a5e | ||
|
|
da4e59ef3a | ||
|
|
da2c76ed5f | ||
|
|
8c1c00f6e2 | ||
|
|
5183b54285 | ||
|
|
a9190f2a0d | ||
|
|
794586362d | ||
|
|
1bdbde0af6 | ||
|
|
c1815c25d8 | ||
|
|
5dc707a6d8 | ||
|
|
78dcb1e988 |
11
build.gradle
11
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" }
|
||||
@@ -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=1.19-rc2
|
||||
yarn_mappings=1.19-rc2+build.1
|
||||
loader_version=0.14.6
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.2.8
|
||||
mod_version = 0.6.2
|
||||
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.55.1+1.19
|
||||
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))
|
||||
if (field.isAnnotationPresent(MidnightConfig.Entry.class) && !field.isAnnotationPresent(MidnightConfig.Client.class) && !field.isAnnotationPresent(MidnightConfig.Hidden.class))
|
||||
new AutoCommand(field, modid).register();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,12 +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;
|
||||
@Entry // Change the texture of the background in MidnightConfig
|
||||
public static String background_texture = "minecraft:textures/block/deepslate.png";
|
||||
@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;
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package eu.midnightdust.core.mixin;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import eu.midnightdust.core.config.MidnightLibConfig;
|
||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Mixin(EntryListWidget.class)
|
||||
public abstract class MixinEntryListWidget {
|
||||
|
||||
@Inject(at = @At(value = "INVOKE",target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderTexture(ILnet/minecraft/util/Identifier;)V",shift = At.Shift.AFTER), method = "render", cancellable = true)
|
||||
private void custom_background(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||
if (!MidnightLibConfig.background_texture.equals("") && this.getClass().toString().toLowerCase(Locale.ROOT).contains("midnight"))
|
||||
RenderSystem.setShaderTexture(0, Identifier.tryParse(MidnightLibConfig.background_texture));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -31,19 +33,21 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
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(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))));
|
||||
}
|
||||
});
|
||||
super.init();
|
||||
}
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
this.list.render(matrices, mouseX, mouseY, delta);
|
||||
|
||||
int stringWidth = title.getString().length() + 47;
|
||||
renderTooltip(matrices, title, width/2 - stringWidth, 27);
|
||||
//drawCenteredText(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
drawCenteredText(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
@@ -56,7 +60,7 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
textRenderer = minecraftClient.textRenderer;
|
||||
}
|
||||
@Override
|
||||
public int getScrollbarPositionX() { return this.width -7; }
|
||||
public int getScrollbarPositionX() {return this.width -7;}
|
||||
|
||||
public void addButton(ClickableWidget button) {
|
||||
this.addEntry(OverviewButtonEntry.create(button));
|
||||
@@ -65,26 +69,19 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
public int getRowWidth() { return 400; }
|
||||
}
|
||||
public static class OverviewButtonEntry extends ElementListWidget.Entry<OverviewButtonEntry> {
|
||||
private final List<ClickableWidget> buttons = new ArrayList<>();
|
||||
private final ClickableWidget button;
|
||||
private final List<ClickableWidget> buttonList = new ArrayList<>();
|
||||
|
||||
private OverviewButtonEntry(ClickableWidget button) {
|
||||
this.buttons.add(button);
|
||||
}
|
||||
public static OverviewButtonEntry create(ClickableWidget button) {
|
||||
return new OverviewButtonEntry(button);
|
||||
this.button = button;
|
||||
this.buttonList.add(button);
|
||||
}
|
||||
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) {
|
||||
this.buttons.forEach((button) -> {
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
});
|
||||
}
|
||||
public List<? extends Element> children() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public List<? extends Selectable> selectableChildren() {
|
||||
return buttons;
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
public List<? extends Element> children() {return buttonList;}
|
||||
public List<? extends Selectable> selectableChildren() {return buttonList;}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,6 @@ import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -17,8 +14,9 @@ import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class HatLoader {
|
||||
public static final Logger logger = LogManager.getLogger("MidnightLib");
|
||||
public static final System.Logger logger = System.getLogger("MidnightLib");
|
||||
private final static String HATS_URL = "https://raw.githubusercontent.com/TeamMidnightDust/MidnightHats/master/hats.json";
|
||||
public static final Type HAT_TYPE = new TypeToken<Map<UUID, PlayerHatData>>(){}.getType();
|
||||
public static Map<UUID, PlayerHatData> PLAYER_HATS;
|
||||
@@ -30,19 +28,19 @@ public class HatLoader {
|
||||
try (Reader reader = new InputStreamReader(new URL(HATS_URL).openStream())) {
|
||||
return GSON.<Map<UUID, PlayerHatData>>fromJson(reader, HAT_TYPE);
|
||||
} catch (MalformedURLException error) {
|
||||
logger.log(Level.ERROR, "Unable to load player hats because of connection problems: " + error.getMessage());
|
||||
logger.log(System.Logger.Level.ERROR, "Unable to load player hats because of connection problems: " + error.getMessage());
|
||||
} catch (IOException error) {
|
||||
logger.log(Level.ERROR, "Unable to load player hats because of an I/O Exception: " + error.getMessage());
|
||||
logger.log(System.Logger.Level.ERROR, "Unable to load player hats because of an I/O Exception: " + error.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}).thenAcceptAsync(playerData -> {
|
||||
if (playerData != null) {
|
||||
PLAYER_HATS = playerData;
|
||||
logger.log(Level.INFO, "Player hats successfully loaded!");
|
||||
System.out.println("(MidnightLib) Player hats successfully loaded!");
|
||||
} else {
|
||||
PLAYER_HATS = Collections.emptyMap();
|
||||
logger.log(Level.WARN, "A problem with the database occurred, the hats could not be initialized.");
|
||||
logger.log(System.Logger.Level.WARNING, "A problem with the database occurred, the hats could not be initialized.");
|
||||
}
|
||||
}, MinecraftClient.getInstance());
|
||||
}
|
||||
|
||||
@@ -68,15 +68,14 @@ public class WitchHatFeatureRenderer<T extends LivingEntity, M extends EntityMod
|
||||
if (uuid.equals(MOTSCHEN)) {
|
||||
return MOTSCHEN_COLOR;
|
||||
} else if (HatLoader.PLAYER_HATS != null && HatLoader.PLAYER_HATS.containsKey(uuid)) {
|
||||
switch (HatLoader.PLAYER_HATS.get(uuid).getHatType()) {
|
||||
case "adopter": return ADOPTER_COLOR;
|
||||
case "contributer": // old name
|
||||
case "modder": return MODDER_COLOR;
|
||||
case "friend": return FRIEND_COLOR;
|
||||
case "donator": // old name
|
||||
case "donor": return DONOR_COLOR;
|
||||
case "social": return SOCIAL_COLOR;
|
||||
}
|
||||
return switch (HatLoader.PLAYER_HATS.get(uuid).getHatType()) {
|
||||
case "adopter" -> ADOPTER_COLOR;
|
||||
case "contributer", "modder" -> MODDER_COLOR;
|
||||
case "friend" -> FRIEND_COLOR;
|
||||
case "donator", "donor" -> DONOR_COLOR;
|
||||
case "social" -> SOCIAL_COLOR;
|
||||
default -> MidnightColorUtil.hex2Rgb(HatLoader.PLAYER_HATS.get(uuid).getHatType());
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -25,9 +25,9 @@ public class AutoCommand {
|
||||
public void register() {
|
||||
command = CommandManager.literal(modid);
|
||||
command();
|
||||
LiteralArgumentBuilder<ServerCommandSource> finalized = CommandManager.literal("midnightconfig").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() {
|
||||
@@ -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,18 +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.gui.widget.*;
|
||||
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;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -34,14 +31,15 @@ import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** MidnightConfig v1.0.8 by TeamMidnightDust & Motschen
|
||||
/** MidnightConfig v2.3.0 by TeamMidnightDust & Motschen
|
||||
* Single class config library - feel free to copy!
|
||||
*
|
||||
|
||||
* Based on https://github.com/Minenash/TinyConfig
|
||||
* Credits to Minenash */
|
||||
|
||||
@@ -49,6 +47,7 @@ import java.util.regex.Pattern;
|
||||
public abstract class MidnightConfig {
|
||||
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
|
||||
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||
private static final Pattern HEXADECIMAL_ONLY = Pattern.compile("(-?[#0-9a-fA-F]*)");
|
||||
|
||||
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||
|
||||
@@ -57,13 +56,16 @@ 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;
|
||||
}
|
||||
|
||||
public static final Map<String,Class<?>> configClass = new HashMap<>();
|
||||
@@ -77,8 +79,9 @@ public abstract class MidnightConfig {
|
||||
|
||||
for (Field field : config.getFields()) {
|
||||
EntryInfo info = new EntryInfo();
|
||||
if (field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.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);
|
||||
@@ -92,8 +95,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)
|
||||
@@ -105,21 +107,22 @@ public abstract class MidnightConfig {
|
||||
info.id = modid;
|
||||
|
||||
if (e != null) {
|
||||
if (!e.name().equals("")) info.name = new TranslatableText(e.name());
|
||||
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true);
|
||||
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);
|
||||
else if (type == String.class) {
|
||||
else if (type == String.class || type == List.class) {
|
||||
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);
|
||||
@@ -138,13 +141,11 @@ public abstract class MidnightConfig {
|
||||
|
||||
Number value = 0;
|
||||
boolean inLimits = false;
|
||||
System.out.println(((isNumber ^ s.isEmpty())));
|
||||
System.out.println(!s.equals("-") && !s.equals("."));
|
||||
info.error = null;
|
||||
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)));
|
||||
}
|
||||
@@ -154,9 +155,20 @@ public abstract class MidnightConfig {
|
||||
info.inLimits = inLimits;
|
||||
b.active = entries.stream().allMatch(e -> e.inLimits);
|
||||
|
||||
if (inLimits)
|
||||
if (inLimits && info.field.getType() != List.class)
|
||||
info.value = isNumber? value : s;
|
||||
else if (inLimits) {
|
||||
if (((List<String>) info.value).size() == info.index) ((List<String>) info.value).add("");
|
||||
((List<String>) info.value).set(info.index, Arrays.stream(info.tempValue.replace("[", "").replace("]", "").split(", ")).toList().get(0));
|
||||
}
|
||||
|
||||
if (info.field.getAnnotation(Entry.class).isColor()) {
|
||||
if (!s.contains("#")) s = '#' + s;
|
||||
if (!HEXADECIMAL_ONLY.matcher(s).matches()) return false;
|
||||
try {
|
||||
info.colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@@ -175,29 +187,38 @@ 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
|
||||
public void tick() {
|
||||
super.tick();
|
||||
for (EntryInfo info : entries)
|
||||
try { info.field.set(null, info.value); }
|
||||
catch (IllegalAccessException ignored) {}
|
||||
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); }
|
||||
|
||||
@@ -206,12 +227,11 @@ public abstract class MidnightConfig {
|
||||
try {
|
||||
info.value = info.field.get(null);
|
||||
info.tempValue = info.value.toString();
|
||||
} catch (IllegalAccessException ignored) {
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void init() {
|
||||
public void init() {
|
||||
super.init();
|
||||
if (!reload) loadValues();
|
||||
|
||||
@@ -236,10 +256,11 @@ public abstract class MidnightConfig {
|
||||
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 - 155, 0, 40, 20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
|
||||
Text name = Objects.requireNonNullElseGet(info.name, () -> Text.translatable(translationPrefix + info.field.getName()));
|
||||
ButtonWidget resetButton = new ButtonWidget(width - 205, 0, 40, 20, Text.literal("Reset").formatted(Formatting.RED), (button -> {
|
||||
info.value = info.defaultValue;
|
||||
info.tempValue = info.value.toString();
|
||||
info.tempValue = info.defaultValue.toString();
|
||||
info.index = 0;
|
||||
double scrollAmount = list.getScrollAmount();
|
||||
this.reload = true;
|
||||
Objects.requireNonNull(client).setScreen(this);
|
||||
@@ -248,20 +269,53 @@ public abstract class MidnightConfig {
|
||||
|
||||
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(new ButtonWidget(width - 110, 0,100, 20, widget.getValue().apply(info.value), widget.getKey()),resetButton,name);
|
||||
} else if (info.widget != null) {
|
||||
TextFieldWidget widget = new TextFieldWidget(textRenderer, width - 110, 0, 100, 20, null);
|
||||
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, info);
|
||||
} else if (info.field.getType() == List.class) {
|
||||
if (!reload) info.index = 0;
|
||||
TextFieldWidget widget = new TextFieldWidget(textRenderer, width - 160, 0, 150, 20, Text.empty());
|
||||
widget.setMaxLength(info.width);
|
||||
widget.setText(info.tempValue);
|
||||
if (info.index < ((List<String>)info.value).size()) widget.setText((String.valueOf(((List<String>)info.value).get(info.index))));
|
||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget, done);
|
||||
widget.setTextPredicate(processor);
|
||||
this.list.addButton(widget, resetButton, name);
|
||||
resetButton.setWidth(20);
|
||||
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||
ButtonWidget cycleButton = new ButtonWidget(width - 185, 0, 20, 20, Text.literal(String.valueOf(info.index)).formatted(Formatting.GOLD), (button -> {
|
||||
((List<String>)info.value).remove("");
|
||||
double scrollAmount = list.getScrollAmount();
|
||||
this.reload = true;
|
||||
info.index = info.index + 1;
|
||||
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, info);
|
||||
} else if (info.widget != null) {
|
||||
ClickableWidget widget;
|
||||
Entry e = info.field.getAnnotation(Entry.class);
|
||||
if (e.isSlider()) widget = new MidnightSliderWidget(width - 160, 0, 150, 20, Text.of(info.tempValue), (Double.parseDouble(info.tempValue)-e.min()) / (e.max() - e.min()), info);
|
||||
else widget = new TextFieldWidget(textRenderer, width - 160, 0, 150, 20, null, Text.of(info.tempValue));
|
||||
if (widget instanceof TextFieldWidget textField) {
|
||||
textField.setMaxLength(info.width);
|
||||
textField.setText(info.tempValue);
|
||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(textField, done);
|
||||
textField.setTextPredicate(processor);
|
||||
}
|
||||
if (e.isColor()) {
|
||||
resetButton.setWidth(20);
|
||||
resetButton.setMessage(Text.literal("R").formatted(Formatting.RED));
|
||||
ButtonWidget colorButton = new ButtonWidget(width - 185, 0, 20, 20, Text.literal("⬛"), (button -> {}));
|
||||
try {colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));} catch (Exception ignored) {}
|
||||
info.colorButton = colorButton;
|
||||
colorButton.active = false;
|
||||
this.list.addButton(List.of(widget, resetButton, colorButton), name, info);
|
||||
}
|
||||
else this.list.addButton(List.of(widget, resetButton), name, info);
|
||||
} else {
|
||||
ButtonWidget dummy = new ButtonWidget(-10, 0, 0, 0, Text.of(""), null);
|
||||
this.list.addButton(dummy,dummy,name);
|
||||
this.list.addButton(List.of(),name, info);
|
||||
}
|
||||
}
|
||||
updateResetButtons();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -269,24 +323,21 @@ public abstract class MidnightConfig {
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
this.list.render(matrices, mouseX, mouseY, delta);
|
||||
|
||||
int stringWidth = (int) (title.getString().length() * 2.75f);
|
||||
renderTooltip(matrices, title, width/2 - stringWidth, 27);
|
||||
//drawCenteredText(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
drawCenteredText(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
|
||||
for (EntryInfo info : entries) {
|
||||
if (info.id.equals(modid)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -307,17 +358,15 @@ public abstract class MidnightConfig {
|
||||
@Override
|
||||
public int getScrollbarPositionX() { return this.width -7; }
|
||||
|
||||
public void addButton(ClickableWidget button, ClickableWidget resetButton, Text text) {
|
||||
this.addEntry(ButtonEntry.create(button, text, resetButton));
|
||||
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) {
|
||||
this.addEntry(new ButtonEntry(buttons, text, info));
|
||||
}
|
||||
@Override
|
||||
public int getRowWidth() { return 10000; }
|
||||
public Optional<ClickableWidget> getHoveredButton(double mouseX, double mouseY) {
|
||||
for (ButtonEntry buttonEntry : this.children()) {
|
||||
for (ClickableWidget ClickableWidget : buttonEntry.buttons) {
|
||||
if (ClickableWidget.isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(ClickableWidget);
|
||||
}
|
||||
if (!buttonEntry.buttons.isEmpty() && buttonEntry.buttons.get(0).isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(buttonEntry.buttons.get(0));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
@@ -325,51 +374,65 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
public static class ButtonEntry extends ElementListWidget.Entry<ButtonEntry> {
|
||||
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
private final List<ClickableWidget> buttons = new ArrayList<>();
|
||||
private final List<ClickableWidget> resetButtons = new ArrayList<>();
|
||||
private final List<Text> texts = new ArrayList<>();
|
||||
private final List<ClickableWidget> buttonsWithResetButtons = new ArrayList<>();
|
||||
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(ClickableWidget button, Text text, ClickableWidget resetButton) {
|
||||
buttonsWithText.put(button,text);
|
||||
this.buttons.add(button);
|
||||
this.resetButtons.add(resetButton);
|
||||
this.texts.add(text);
|
||||
this.buttonsWithResetButtons.add(button);
|
||||
this.buttonsWithResetButtons.add(resetButton);
|
||||
}
|
||||
public static ButtonEntry create(ClickableWidget button, Text text, ClickableWidget resetButton) {
|
||||
return new ButtonEntry(button, text, resetButton);
|
||||
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 void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
this.buttons.forEach(button -> {
|
||||
button.y = y;
|
||||
button.render(matrices, mouseX, mouseY, tickDelta);
|
||||
});
|
||||
this.texts.forEach(text -> DrawableHelper.drawTextWithShadow(matrices,textRenderer, text,12,y+5,0xFFFFFF));
|
||||
this.resetButtons.forEach((button) -> {
|
||||
button.y = y;
|
||||
button.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 (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 buttonsWithResetButtons;
|
||||
public List<? extends Element> children() {return children;}
|
||||
public List<? extends Selectable> selectableChildren() {return children;}
|
||||
}
|
||||
private static class MidnightSliderWidget extends SliderWidget {
|
||||
private final EntryInfo info; private final Entry e;
|
||||
public MidnightSliderWidget(int x, int y, int width, int height, Text text, double value, EntryInfo info) {
|
||||
super(x, y, width, height, text, value);
|
||||
this.e = info.field.getAnnotation(Entry.class);
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public List<? extends Selectable> selectableChildren() {
|
||||
return buttonsWithResetButtons;
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
this.setMessage(Text.of(info.tempValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
if (info.field.getType() == int.class) info.value = ((Number) (e.min() + value * (e.max() - e.min()))).intValue();
|
||||
else if (info.field.getType() == double.class) info.value = Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision();
|
||||
else if (info.field.getType() == float.class) info.value = Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision();
|
||||
info.tempValue = String.valueOf(info.value);
|
||||
}
|
||||
}
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Entry {
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Entry {
|
||||
int width() default 100;
|
||||
double min() default Double.MIN_NORMAL;
|
||||
double max() default Double.MAX_VALUE;
|
||||
String name() default "";
|
||||
boolean isColor() default false;
|
||||
boolean isSlider() default false;
|
||||
int precision() default 100;
|
||||
}
|
||||
@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 Hidden {}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {
|
||||
boolean centered() default false;
|
||||
}
|
||||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment {}
|
||||
|
||||
public static class HiddenAnnotationExclusionStrategy implements ExclusionStrategy {
|
||||
public boolean shouldSkipClass(Class<?> clazz) { return false; }
|
||||
@@ -377,4 +440,4 @@ public abstract class MidnightConfig {
|
||||
return fieldAttributes.getAnnotation(Entry.class) == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
16
src/main/java/eu/midnightdust/lib/config/MidnightConfigExample.java
Executable file → Normal file
@@ -1,5 +1,7 @@
|
||||
package eu.midnightdust.lib.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** MidnightConfig documentation & examples:
|
||||
* 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:
|
||||
@@ -12,13 +14,15 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
@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 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
|
||||
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
|
||||
}
|
||||
@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, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color
|
||||
@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
|
||||
|
||||
@@ -27,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.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",
|
||||
// this text will appear as a tooltip.
|
||||
// "\n" inserts a line break.
|
||||
|
||||
@@ -10,15 +10,14 @@ public class MidnightColorUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* @credit https://stackoverflow.com/questions/4129666/how-to-convert-hex-to-rgb-using-java
|
||||
* @param colorStr e.g. "FFFFFF"
|
||||
* @param colorStr e.g. "FFFFFF" or "#FFFFFF"
|
||||
* @return Color as RGB
|
||||
*/
|
||||
public static Color hex2Rgb(String colorStr) {
|
||||
return new Color(
|
||||
Integer.valueOf( colorStr.substring( 0, 2 ), 16 ),
|
||||
Integer.valueOf( colorStr.substring( 2, 4 ), 16 ),
|
||||
Integer.valueOf( colorStr.substring( 4, 6 ), 16 ));
|
||||
try {
|
||||
return Color.decode("#" + colorStr.replace("#", ""));
|
||||
} catch (Exception ignored) {}
|
||||
return Color.BLACK;
|
||||
}
|
||||
|
||||
public static Color radialRainbow(float saturation, float brightness) {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package eu.midnightdust.lib.util.render.entity;
|
||||
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.entity.feature.EyesFeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class EmissiveOverlayRenderer<T extends LivingEntity> extends EyesFeatureRenderer<T, EntityModel<T>> {
|
||||
private final RenderLayer SKIN;
|
||||
|
||||
public EmissiveOverlayRenderer(FeatureRendererContext<T, EntityModel<T>> featureRendererContext, Identifier texture) {
|
||||
super(featureRendererContext);
|
||||
SKIN = RenderLayer.getEyes(texture);
|
||||
}
|
||||
public RenderLayer getEyesTexture() {
|
||||
return SKIN;
|
||||
}
|
||||
}
|
||||
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 |
@@ -3,8 +3,8 @@
|
||||
"midnightlib.midnightconfig.title":"MidnightLib Config",
|
||||
"midnightlib.midnightconfig.midnightlib_description":"§nMidnightLib",
|
||||
"midnightlib.midnightconfig.config_screen_list":"Enable Config Screen List",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.TRUE":"§aTrue",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.FALSE":"§cFalse",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.TRUE":"§aYes",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.FALSE":"§cNo",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.MODMENU":"§bModMenu",
|
||||
"midnightlib.midnightconfig.background_texture":"Texture of config screen backgrounds",
|
||||
"midnightlib.midnightconfig.midnighthats_description":"§nMidnightHats",
|
||||
|
||||
17
src/main/resources/assets/midnightlib/lang/pt_br.json
Normal file
17
src/main/resources/assets/midnightlib/lang/pt_br.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"midnightlib.overview.title":"Visão geral do MidnightConfig",
|
||||
"midnightlib.midnightconfig.title":"Configuração MidnightLib",
|
||||
"midnightlib.midnightconfig.midnightlib_description":"§nMidnightLib",
|
||||
"midnightlib.midnightconfig.config_screen_list":"Ativar lista de telas de configuração",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.TRUE":"§aVerdadeiro",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.FALSE":"§cFalso",
|
||||
"midnightlib.midnightconfig.enum.ConfigButton.MODMENU":"§bModMenu",
|
||||
"midnightlib.midnightconfig.background_texture":"Textura dos fundos da tela de configuração",
|
||||
"midnightlib.midnightconfig.midnighthats_description":"§nMidnightHats",
|
||||
"midnightlib.midnightconfig.special_hats":"Ativar chapéus de torcedor",
|
||||
"midnightlib.modrinth":"Modrinth",
|
||||
"midnightlib.curseforge":"CurseForge",
|
||||
"midnightlib.wiki":"Wiki",
|
||||
"modmenu.descriptionTranslation.midnightlib": "Biblioteca comum para mods do Team MidnightDust.\nFornece uma API de configuração, integração automática com outros mods, utilitários comuns e cosméticos.",
|
||||
"modmenu.summaryTranslation.midnightlib": "Biblioteca comum para mods do Team MidnightDust."
|
||||
}
|
||||
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."
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 672 B After Width: | Height: | Size: 293 B |
@@ -32,13 +32,9 @@
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
"midnightcore.mixins.json"
|
||||
"midnightlib.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabric-renderer-registries-v1": "*"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"links": {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"client": [
|
||||
"MixinOptionsScreen",
|
||||
"MixinEntryListWidget",
|
||||
"MixinPlayerEntityRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
Reference in New Issue
Block a user