mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
MidnightLib 1.5.1 for 1.20.4
- Port to 1.20.4 - Add back fancy list background - File size optimizations - Update tooling
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
|
||||
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
|
||||
}
|
||||
|
||||
architectury {
|
||||
@@ -12,8 +12,6 @@ subprojects {
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
|
||||
// The following line declares the mojmap mappings, you may use other mappings as well
|
||||
//mappings loom.officialMojangMappings()
|
||||
// The following line declares the yarn mappings you may select this one as well.
|
||||
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
|
||||
public class MidnightLibConfig extends MidnightConfig {
|
||||
@Entry // Enable or disable the MidnightConfig overview screen button
|
||||
@Entry
|
||||
public static ConfigButton config_screen_list = PlatformFunctions.isModLoaded("modmenu") ? ConfigButton.MODMENU : ConfigButton.TRUE;
|
||||
|
||||
public enum ConfigButton {
|
||||
|
||||
@@ -4,10 +4,7 @@ import eu.midnightdust.core.MidnightLibClient;
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.Selectable;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
@@ -22,58 +19,32 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
this.parent = parent;
|
||||
}
|
||||
private final Screen parent;
|
||||
private MidnightOverviewListWidget list;
|
||||
private MidnightConfig.MidnightConfigListWidget list;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).dimensions(this.width / 2 - 100, this.height - 28, 200, 20).build());
|
||||
|
||||
this.list = new MidnightOverviewListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
|
||||
this.list = new MidnightConfig.MidnightConfigListWidget(this.client, this.width, this.height - 64, 32, 25);
|
||||
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
||||
this.addSelectableChild(this.list);
|
||||
List<String> sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet());
|
||||
Collections.sort(sortedMods);
|
||||
sortedMods.forEach((modid) -> {
|
||||
if (!MidnightLibClient.hiddenMods.contains(modid)) {
|
||||
list.addButton(ButtonWidget.builder(Text.translatable(modid +".midnightconfig.title"), (button) ->
|
||||
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid))).dimensions(this.width / 2 - 125, this.height - 28, 250, 20).build());
|
||||
list.addButton(List.of(ButtonWidget.builder(Text.translatable(modid +".midnightconfig.title"), (button) ->
|
||||
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid))).dimensions(this.width / 2 - 125, this.height - 28, 250, 20).build()), null, null);
|
||||
}
|
||||
});
|
||||
super.init();
|
||||
}
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
if (client != null && client.world != null) super.renderInGameBackground(context);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class MidnightOverviewListWidget extends ElementListWidget<OverviewButtonEntry> {
|
||||
public MidnightOverviewListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
}
|
||||
@Override
|
||||
public int getScrollbarPositionX() {return this.width-7;}
|
||||
|
||||
public void addButton(ClickableWidget button) {
|
||||
this.addEntry(OverviewButtonEntry.create(button));
|
||||
}
|
||||
@Override
|
||||
public int getRowWidth() { return 400; }
|
||||
}
|
||||
public static class OverviewButtonEntry extends ElementListWidget.Entry<OverviewButtonEntry> {
|
||||
private final ClickableWidget button;
|
||||
|
||||
private OverviewButtonEntry(ClickableWidget button) {
|
||||
this.button = button;
|
||||
}
|
||||
public static OverviewButtonEntry create(ClickableWidget button) {return new OverviewButtonEntry(button);}
|
||||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
button.setY(y);
|
||||
button.render(context, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
public List<? extends Element> children() {return List.of(button);}
|
||||
public List<? extends Selectable> selectableChildren() {return List.of(button);}
|
||||
}
|
||||
@Override public void renderBackground(DrawContext c, int x, int y, float d) {}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.midnightdust.lib.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
@@ -18,6 +19,7 @@ import net.minecraft.client.gui.tab.Tab;
|
||||
import net.minecraft.client.gui.tab.TabManager;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.OrderedText;
|
||||
@@ -42,7 +44,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** MidnightConfig v2.5.0 by TeamMidnightDust & Motschen
|
||||
/** MidnightConfig v2.5.1 by TeamMidnightDust & Motschen
|
||||
* Single class config library - feel free to copy!
|
||||
* Based on <a href="https://github.com/Minenash/TinyConfig">...</a>
|
||||
* Credits to Minenash */
|
||||
@@ -55,7 +57,7 @@ public abstract class MidnightConfig {
|
||||
|
||||
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||
|
||||
protected static class EntryInfo {
|
||||
public static class EntryInfo {
|
||||
Field field;
|
||||
Object widget;
|
||||
int width;
|
||||
@@ -111,7 +113,7 @@ public abstract class MidnightConfig {
|
||||
info.id = modid;
|
||||
|
||||
if (e != null) {
|
||||
if (!e.name().equals("")) info.name = Text.translatable(e.name());
|
||||
if (!e.name().isEmpty()) 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);
|
||||
@@ -135,7 +137,8 @@ public abstract class MidnightConfig {
|
||||
entries.add(info);
|
||||
}
|
||||
public static Tooltip getTooltip(EntryInfo info) {
|
||||
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(info.id + ".midnightconfig."+info.field.getName()+".tooltip") ? Text.translatable(info.id + ".midnightconfig."+info.field.getName()+".tooltip") : Text.empty());
|
||||
String key = info.id + ".midnightconfig."+info.field.getName()+".tooltip";
|
||||
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(key) ? Text.translatable(key) : Text.empty());
|
||||
}
|
||||
|
||||
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
|
||||
@@ -258,8 +261,6 @@ public abstract class MidnightConfig {
|
||||
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());
|
||||
if (button.active) button.setTooltip(Tooltip.of(Text.translatable("controls.reset").formatted(Formatting.RED)));
|
||||
else button.setTooltip(Tooltip.of(Text.empty()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,7 +304,7 @@ public abstract class MidnightConfig {
|
||||
Objects.requireNonNull(client).setScreen(parent);
|
||||
}).dimensions(this.width / 2 + 4, this.height - 28, 150, 20).build());
|
||||
|
||||
this.list = new MidnightConfigListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
|
||||
this.list = new MidnightConfigListWidget(this.client, this.width, this.height - 64, 32, 25);
|
||||
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
|
||||
this.addSelectableChild(this.list);
|
||||
|
||||
@@ -366,8 +367,7 @@ public abstract class MidnightConfig {
|
||||
})).dimensions(width - 185, 0, 20, 20).build();
|
||||
try {
|
||||
colorButton.setMessage(Text.literal("⬛").setStyle(Style.EMPTY.withColor(Color.decode(info.tempValue).getRGB())));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
info.colorButton = colorButton;
|
||||
colorButton.active = false;
|
||||
this.list.addButton(List.of(widget, resetButton, colorButton), name, info);
|
||||
@@ -382,20 +382,18 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context,mouseX,mouseY,delta);
|
||||
if (client != null && client.world != null) super.renderInGameBackground(context);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
super.render(context,mouseX,mouseY,delta);
|
||||
|
||||
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
}
|
||||
@Override public void renderBackground(DrawContext c, int x, int y, float d) {}
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> {
|
||||
TextRenderer textRenderer;
|
||||
|
||||
public MidnightConfigListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) {
|
||||
super(minecraftClient, i, j, k, l, m);
|
||||
this.centerListVertically = false;
|
||||
textRenderer = minecraftClient.textRenderer;
|
||||
public MidnightConfigListWidget(MinecraftClient client, int width, int height, int y, int itemHeight) {
|
||||
super(client, width, height, y, itemHeight);
|
||||
}
|
||||
@Override
|
||||
public int getScrollbarPositionX() { return this.width -7; }
|
||||
@@ -403,18 +401,25 @@ public abstract class MidnightConfig {
|
||||
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) {
|
||||
this.addEntry(new ButtonEntry(buttons, text, info));
|
||||
}
|
||||
public void clear() {
|
||||
this.clearEntries();
|
||||
}
|
||||
public void clear() { this.clearEntries(); }
|
||||
@Override
|
||||
public int getRowWidth() { return 10000; }
|
||||
@Override
|
||||
protected void renderDecorations(DrawContext c, int mouseX, int mouseY) {
|
||||
c.setShaderColor(0.25F, 0.25F, 0.25F, 1.0F);
|
||||
c.drawTexture(Screen.OPTIONS_BACKGROUND_TEXTURE, this.getX(), 0, 0.0F, 0.0F, this.width, this.getY(), 32, 32);
|
||||
c.drawTexture(Screen.OPTIONS_BACKGROUND_TEXTURE, this.getX(), this.getBottom(), 0.0F, 0.0F, this.width, this.height, 32, 32);
|
||||
c.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if (client == null || client.world == null) return;
|
||||
c.fillGradient(RenderLayer.getGuiOverlay(), this.getX(), this.getY(), this.getRight(), this.getY() + 4, -16777216, 0, 0);
|
||||
c.fillGradient(RenderLayer.getGuiOverlay(), this.getX(), this.getBottom() - 4, this.getRight(), this.getBottom(), 0, -16777216, 0);
|
||||
}
|
||||
}
|
||||
public static class ButtonEntry extends ElementListWidget.Entry<ButtonEntry> {
|
||||
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, EntryInfo info) {
|
||||
@@ -422,7 +427,6 @@ public abstract class MidnightConfig {
|
||||
this.buttons = buttons;
|
||||
this.text = text;
|
||||
this.info = info;
|
||||
children.addAll(buttons);
|
||||
}
|
||||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta); });
|
||||
@@ -437,8 +441,8 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<? extends Element> children() {return children;}
|
||||
public List<? extends Selectable> selectableChildren() {return children;}
|
||||
public List<? extends Element> children() {return Lists.newArrayList(buttons);}
|
||||
public List<? extends Selectable> selectableChildren() {return Lists.newArrayList(buttons);}
|
||||
}
|
||||
public static class MidnightSliderWidget extends SliderWidget {
|
||||
private final EntryInfo info; private final Entry e;
|
||||
|
||||
@@ -13,5 +13,5 @@ dependencies {
|
||||
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
|
||||
modImplementation ("com.terraformersmc:modmenu:${rootProject.mod_menu_version}")
|
||||
|
||||
compileClasspath(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
compileOnly(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
}
|
||||
@@ -12,7 +12,7 @@ loom {
|
||||
|
||||
configurations {
|
||||
common
|
||||
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
|
||||
shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentFabric.extendsFrom common
|
||||
@@ -25,8 +25,6 @@ dependencies {
|
||||
|
||||
common(project(path: ":common", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
|
||||
common(project(path: ":fabric-like", configuration: "namedElements")) { transitive false }
|
||||
shadowCommon(project(path: ":fabric-like", configuration: "transformProductionFabric")) { transitive false }
|
||||
}
|
||||
|
||||
processResources {
|
||||
@@ -41,17 +39,13 @@ shadowJar {
|
||||
exclude "architectury.common.json"
|
||||
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
classifier "dev-shadow"
|
||||
archiveClassifier = "dev-shadow"
|
||||
}
|
||||
|
||||
remapJar {
|
||||
injectAccessWidener = true
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
classifier null
|
||||
}
|
||||
|
||||
jar {
|
||||
classifier "dev"
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
@@ -69,7 +63,7 @@ components.java {
|
||||
publishing {
|
||||
publications {
|
||||
mavenFabric(MavenPublication) {
|
||||
artifactId = rootProject.archives_base_name + "-" + project.name
|
||||
artifactId = archives_base_name + "-" + project.name
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package eu.midnightdust.fabric.core;
|
||||
|
||||
import eu.midnightdust.core.MidnightLibClient;
|
||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
|
||||
public class MidnightLibClientFabric implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
MidnightLibClient.onInitializeClient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package eu.midnightdust.fabric.core;
|
||||
|
||||
import eu.midnightdust.core.MidnightLibClient;
|
||||
import eu.midnightdust.core.MidnightLibServer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
public class MidnightLibFabric implements ClientModInitializer, DedicatedServerModInitializer {
|
||||
@Override @Environment(EnvType.CLIENT)
|
||||
public void onInitializeClient() {
|
||||
MidnightLibClient.onInitializeClient();
|
||||
}
|
||||
@Override @Environment(EnvType.SERVER)
|
||||
public void onInitializeServer() {
|
||||
MidnightLibServer.onInitializeServer();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package eu.midnightdust.fabric.core;
|
||||
|
||||
import eu.midnightdust.core.MidnightLibServer;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
|
||||
public class MidnightLibServerFabric implements DedicatedServerModInitializer {
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
MidnightLibServer.onInitializeServer();
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,10 @@
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"eu.midnightdust.fabric.core.MidnightLibClientFabric"
|
||||
"eu.midnightdust.fabric.core.MidnightLibFabric"
|
||||
],
|
||||
"server": [
|
||||
"eu.midnightdust.fabric.core.MidnightLibServerFabric"
|
||||
"eu.midnightdust.fabric.core.MidnightLibFabric"
|
||||
],
|
||||
"modmenu": [
|
||||
"eu.midnightdust.lib.config.AutoModMenu"
|
||||
|
||||
@@ -42,17 +42,12 @@ shadowJar {
|
||||
exclude "architectury.common.json"
|
||||
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
classifier "dev-shadow"
|
||||
archiveClassifier = "dev-shadow"
|
||||
}
|
||||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
classifier null
|
||||
}
|
||||
|
||||
jar {
|
||||
classifier "dev"
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
org.gradle.jvmargs=-Xmx4096M
|
||||
|
||||
minecraft_version=1.20.2
|
||||
yarn_mappings=1.20.2+build.2
|
||||
enabled_platforms=fabric,forge
|
||||
minecraft_version=1.20.4
|
||||
yarn_mappings=1.20.4+build.1
|
||||
enabled_platforms=fabric
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.5.0
|
||||
mod_version=1.5.1
|
||||
maven_group=eu.midnightdust
|
||||
|
||||
fabric_loader_version=0.14.22
|
||||
fabric_api_version=0.88.5+1.20.2
|
||||
fabric_loader_version=0.15.0
|
||||
fabric_api_version=0.91.1+1.20.4
|
||||
|
||||
forge_version=1.20.2-48.0.13
|
||||
forge_version=1.20.3-49.0.2
|
||||
|
||||
quilt_loader_version=0.19.0-beta.18
|
||||
quilt_fabric_api_version=7.0.1+0.83.0-1.20
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -11,6 +11,6 @@ include("common")
|
||||
include("fabric-like")
|
||||
include("fabric")
|
||||
//include("quilt")
|
||||
include("forge")
|
||||
//include("forge")
|
||||
|
||||
rootProject.name = "midnightlib"
|
||||
|
||||
Reference in New Issue
Block a user