diff --git a/build.gradle b/build.gradle index 7d1c5e5..d7dad13 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false } architectury { diff --git a/common/build.gradle b/common/build.gradle index 21d4a73..ceedbf7 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -2,10 +2,6 @@ architectury { common(rootProject.enabled_platforms.split(",")) } -loom { - accessWidenerPath = file("src/main/resources/midnightlib.accesswidener") -} - dependencies { // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies // Do NOT use other classes from fabric loader diff --git a/MidnightConfigExample.java b/common/src/main/java/eu/midnightdust/core/config/MidnightConfigExample.java similarity index 68% rename from MidnightConfigExample.java rename to common/src/main/java/eu/midnightdust/core/config/MidnightConfigExample.java index 2975aea..83954e5 100644 --- a/MidnightConfigExample.java +++ b/common/src/main/java/eu/midnightdust/core/config/MidnightConfigExample.java @@ -13,22 +13,22 @@ import java.util.List; public class MidnightConfigExample extends MidnightConfig { - @Comment(category = "text") public static Comment text1; // Comments are rendered like an option without a button and are excluded from the config file - @Comment(category = "text", centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered! - @Comment(category = "text") public static Comment spacer1; // Comments containing the word "spacer" will just appear as a blank line - @Entry(category = "text") public static boolean showInfo = true; // Example for a boolean option - @Entry(category = "text") public static String name = "Hello World!"; // Example for a string option, which is in a category! - @Entry(category = "text") public static TestEnum testEnum = TestEnum.FABRIC; // Example for an enum option - public enum TestEnum { // Enums allow the user to cycle through predefined options + @Comment(category = "text") public static Comment text1; // Comments are rendered like an option without a button and are excluded from the config file + @Comment(category = "text", centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered! + @Comment(category = "text") public static Comment spacer1; // Comments containing the word "spacer" will just appear as a blank line + @Entry(category = "text") public static boolean showInfo = true; // Example for a boolean option + @Entry(category = "text") public static String name = "Hello World!"; // Example for a string option, which is in a category! + @Entry(category = "text") public static TestEnum testEnum = TestEnum.FABRIC; // Example for an enum option + public enum TestEnum { // Enums allow the user to cycle through predefined options QUILT, FABRIC, FORGE } - @Entry(category = "numbers") public static int fabric = 16777215; // Example for an int option - @Entry(category = "numbers") public static double world = 1.4D; // Example for a double option - @Entry(category = "numbers", min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420 - @Entry(category = "text", 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(category = "text", name = "I am an array list!") public static List arrayList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported - @Entry(category = "sliders", name = "I am an int slider.",isSlider = true, min = 0, max = 100) public static int intSlider = 35; // Int fields can also be displayed as a Slider - @Entry(category = "sliders", name = "I am a float slider!", isSlider = true, min = 0f, max = 1f, precision = 1000) public static float floatSlider = 0.24f; // And so can floats! Precision defines the amount of decimal places + @Entry(category = "numbers") public static int fabric = 16777215; // Example for an int option + @Entry(category = "numbers") public static double world = 1.4D; // Example for a double option + @Entry(category = "numbers", min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420 + @Entry(category = "text", isColor = true) public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color + @Entry(category = "text") public static List arrayList = Lists.newArrayList(); // Array String Lists are also supported + @Entry(isSlider = true, min = 0, max = 100) public static int intSlider = 35; // Int fields can also be displayed as a Slider + @Entry(isSlider = true, min = 0f, max = 1f) public static float floatSlider = 0.24f; // And so can floats! Precision defines the amount of decimal places // 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 diff --git a/common/src/main/java/eu/midnightdust/core/mixin/MixinOptionsScreen.java b/common/src/main/java/eu/midnightdust/core/mixin/MixinOptionsScreen.java new file mode 100644 index 0000000..1e37bf1 --- /dev/null +++ b/common/src/main/java/eu/midnightdust/core/mixin/MixinOptionsScreen.java @@ -0,0 +1,33 @@ +package eu.midnightdust.core.mixin; + +import eu.midnightdust.core.config.MidnightLibConfig; +import eu.midnightdust.core.screen.MidnightConfigOverviewScreen; +import eu.midnightdust.lib.util.PlatformFunctions; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.option.OptionsScreen; +import net.minecraft.client.gui.widget.TextIconButtonWidget; +import net.minecraft.text.Text; +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.Objects; + +@Mixin(OptionsScreen.class) +public class MixinOptionsScreen extends Screen { + protected MixinOptionsScreen(Text title) {super(title);} + + @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) && !PlatformFunctions.isModLoaded("modmenu"))) { + TextIconButtonWidget button = TextIconButtonWidget.builder(Text.translatable("midnightlib.overview.title"), ( + buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), true) + .texture(new Identifier("midnightlib","icon/midnightlib"), 16, 16).dimension(20, 20).build(); + //button.setPosition(this.width / 2 + 158, this.height / 6 - 17); + button.setPosition(this.width / 2 + 158, this.height / 2 - 105); + this.addDrawableChild(button); + } + } +} \ No newline at end of file diff --git a/common/src/main/java/eu/midnightdust/core/screen/MidnightConfigOverviewScreen.java b/common/src/main/java/eu/midnightdust/core/screen/MidnightConfigOverviewScreen.java index 12e5da9..9c0d520 100755 --- a/common/src/main/java/eu/midnightdust/core/screen/MidnightConfigOverviewScreen.java +++ b/common/src/main/java/eu/midnightdust/core/screen/MidnightConfigOverviewScreen.java @@ -1,19 +1,14 @@ package eu.midnightdust.core.screen; import eu.midnightdust.core.MidnightLib; -import eu.midnightdust.core.config.MidnightLibConfig; import eu.midnightdust.lib.config.MidnightConfig; -import eu.midnightdust.lib.util.PlatformFunctions; 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.screen.Screen; -import net.minecraft.client.gui.screen.option.OptionsScreen; import net.minecraft.client.gui.widget.*; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.*; -import net.minecraft.util.Identifier; import java.util.*; @@ -29,10 +24,9 @@ public class MidnightConfigOverviewScreen extends Screen { @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.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).dimensions(this.width / 2 - 100, this.height - 26, 200, 20).build()); - 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.list = new MidnightConfig.MidnightConfigListWidget(this.client, this.width, this.height - 64, 24, 25); this.addSelectableChild(this.list); List sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet()); Collections.sort(sortedMods); @@ -46,22 +40,9 @@ public class MidnightConfigOverviewScreen extends Screen { } @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - if (client != null && client.world != null) super.renderInGameBackground(context); - this.list.render(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); + this.list.render(context, mouseX, mouseY, delta); - context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF); - } - @Override public void renderBackground(DrawContext c, int x, int y, float d) {} - - public static void addButtonToOptionsScreen(Screen screen, MinecraftClient client) { - if (screen.getClass() == OptionsScreen.class && MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) - || (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && !PlatformFunctions.isModLoaded("modmenu"))) { - TextIconButtonWidget button = TextIconButtonWidget.builder(Text.translatable("midnightlib.overview.title"), ( - buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(screen)), true) - .texture(new Identifier("midnightlib","icon/midnightlib"), 16, 16).dimension(20, 20).build(); - button.setPosition(screen.width / 2 + 158, screen.height / 6 - 12); - screen.addDrawableChild(button); - } + context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF); } } \ No newline at end of file diff --git a/common/src/main/java/eu/midnightdust/lib/config/MidnightConfig.java b/common/src/main/java/eu/midnightdust/lib/config/MidnightConfig.java index 1e2e939..68392bb 100755 --- a/common/src/main/java/eu/midnightdust/lib/config/MidnightConfig.java +++ b/common/src/main/java/eu/midnightdust/lib/config/MidnightConfig.java @@ -292,7 +292,7 @@ public abstract class MidnightConfig { this.addDrawableChild(ButtonWidget.builder(ScreenTexts.CANCEL, button -> { loadValues(); Objects.requireNonNull(client).setScreen(parent); - }).dimensions(this.width / 2 - 154, this.height - 28, 150, 20).build()); + }).dimensions(this.width / 2 - 154, this.height - 26, 150, 20).build()); done = this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> { for (EntryInfo info : entries) if (info.id.equals(modid)) { @@ -302,10 +302,9 @@ public abstract class MidnightConfig { } write(modid); Objects.requireNonNull(client).setScreen(parent); - }).dimensions(this.width / 2 + 4, this.height - 28, 150, 20).build()); + }).dimensions(this.width / 2 + 4, this.height - 26, 150, 20).build()); - 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.list = new MidnightConfigListWidget(this.client, this.width, this.height - 64, 24, 25); this.addSelectableChild(this.list); fillList(); @@ -382,13 +381,11 @@ public abstract class MidnightConfig { } @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - if (client != null && client.world != null) super.renderInGameBackground(context); - this.list.render(context, mouseX, mouseY, delta); super.render(context,mouseX,mouseY,delta); + this.list.render(context, mouseX, mouseY, delta); - if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF); + if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF); } - @Override public void renderBackground(DrawContext c, int x, int y, float d) {} } @Environment(EnvType.CLIENT) public static class MidnightConfigListWidget extends ElementListWidget { @@ -404,16 +401,6 @@ public abstract class MidnightConfig { 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 { private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; diff --git a/common/src/main/resources/architectury.common.json b/common/src/main/resources/architectury.common.json index 093c5d3..9e26dfe 100644 --- a/common/src/main/resources/architectury.common.json +++ b/common/src/main/resources/architectury.common.json @@ -1,3 +1 @@ -{ - "accessWidener": "midnightlib.accesswidener" -} \ No newline at end of file +{} \ No newline at end of file diff --git a/common/src/main/resources/midnightlib.accesswidener b/common/src/main/resources/midnightlib.accesswidener deleted file mode 100644 index 561ebaa..0000000 --- a/common/src/main/resources/midnightlib.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -accessible method net/minecraft/client/gui/screen/Screen addDrawableChild (Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element; \ No newline at end of file diff --git a/common/src/main/resources/midnightlib.mixins.json b/common/src/main/resources/midnightlib.mixins.json new file mode 100644 index 0000000..20c4305 --- /dev/null +++ b/common/src/main/resources/midnightlib.mixins.json @@ -0,0 +1 @@ +{"required": true,"minVersion": "0.8","package": "eu.midnightdust.core.mixin","compatibilityLevel": "JAVA_17","client": ["MixinOptionsScreen"],"injectors": {"defaultRequire": 1}} \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index 4cfbb4b..7b64ae2 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -25,7 +25,7 @@ configurations { dependencies { modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}" - modImplementation ("com.terraformersmc:modmenu:${rootProject.mod_menu_version}") + modCompileOnly ("com.terraformersmc:modmenu:${rootProject.mod_menu_version}") common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } @@ -47,7 +47,6 @@ shadowJar { } remapJar { - injectAccessWidener = true input.set shadowJar.archiveFile dependsOn shadowJar } diff --git a/fabric/src/main/java/eu/midnightdust/fabric/core/MidnightLibFabric.java b/fabric/src/main/java/eu/midnightdust/fabric/core/MidnightLibFabric.java index f1cffed..2919334 100644 --- a/fabric/src/main/java/eu/midnightdust/fabric/core/MidnightLibFabric.java +++ b/fabric/src/main/java/eu/midnightdust/fabric/core/MidnightLibFabric.java @@ -1,21 +1,14 @@ package eu.midnightdust.fabric.core; import eu.midnightdust.core.MidnightLib; -import eu.midnightdust.core.screen.MidnightConfigOverviewScreen; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; public class MidnightLibFabric implements ClientModInitializer, DedicatedServerModInitializer { @Override @Environment(EnvType.CLIENT) - public void onInitializeClient() { - MidnightLib.onInitializeClient(); - ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> { - MidnightConfigOverviewScreen.addButtonToOptionsScreen(screen, client); - }); - } + public void onInitializeClient() {MidnightLib.onInitializeClient();} @Override @Environment(EnvType.SERVER) public void onInitializeServer() {MidnightLib.onInitializeServer();} } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 3944bac..8bc8a5e 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -32,9 +32,13 @@ }, "depends": { "fabric-resource-loader-v0": "*", - "minecraft": ">=1.20.3" + "minecraft": ">=1.20.4" }, + "mixins": [ + "midnightlib.mixins.json" + ], + "custom": { "modmenu": { "links": { @@ -46,6 +50,5 @@ }, "badges": [ "library" ] } - }, - "accessWidener": "midnightlib.accesswidener" + } } diff --git a/gradle.properties b/gradle.properties index 16e2ba3..0bd450e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ org.gradle.jvmargs=-Xmx4096M -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -enabled_platforms=fabric,neoforge +minecraft_version=24w09a +yarn_mappings=24w09a+build.11 +enabled_platforms=fabric archives_base_name=midnightlib mod_version=1.5.3 maven_group=eu.midnightdust -fabric_loader_version=0.15.1 -fabric_api_version=0.91.1+1.20.4 +fabric_loader_version=0.15.7 +fabric_api_version=0.96.7+1.20.5 neoforge_version=20.4.12-beta diff --git a/settings.gradle b/settings.gradle index d64842c..f865b79 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,6 +11,6 @@ include("common") include("fabric-like") include("fabric") //include("quilt") -include("neoforge") +//include("neoforge") rootProject.name = "midnightlib"