Experimental 24w09a port

- Only the overview button position in the Options Screen is not quite right
This commit is contained in:
Martin Prokoph
2024-03-05 12:58:59 +01:00
parent 2ff92526ba
commit 2f1bfbf44e
14 changed files with 73 additions and 85 deletions

View File

@@ -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

View File

@@ -0,0 +1,67 @@
package eu.midnightdust.core.config;
import com.google.common.collect.Lists;
import eu.midnightdust.lib.config.MidnightConfig;
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:
* Every option in a MidnightConfig class has to be public and static, so we can access it from other classes.
* The config class also has to extend MidnightConfig*/
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
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", isColor = true) public static String titleColor = "#ffffff"; // The isColor property adds a preview box for a hexadecimal color
@Entry(category = "text") public static List<String> 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
/*
The .json language file for your config class could look similar to this:
{
"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.text2":"I am a centered comment (╯°□°)╯︵ ┻━┻",
"modid.midnightconfig.name":"I am a string!", // Translation for the field "name" defined in the example config
"modid.midnightconfig.name.tooltip":"I am a tooltip uwu \nI am a new line",
// When hovering over the option "showInfo",
// this text will appear as a tooltip.
// "\n" inserts a line break.
"modid.midnightconfig.fabric":"I am an int",
"modid.midnightconfig.world":"I am a double",
"modid.midnightconfig.showInfo":"I am a boolean",
"modid.midnightconfig.hello":"I am a limited int!",
"modid.midnightconfig.testEnum":"I am an enum!",
"modid.midnightconfig.enum.TestEnum.FORGE":"Slow",
"modid.midnightconfig.enum.TestEnum.FABRIC":"Fancy",
"modid.midnightconfig.enum.TestEnum.QUILT":"Fabulous",
"modid.midnightconfig.category.numbers": "Numbers",
"modid.midnightconfig.category.text": "Text",
"modid.midnightconfig.category.sliders": "Sliders"
}
To initialize the config you have to call "MidnightConfig.init("modid", MidnightConfigExample.class)" in your ModInitializer
To get an instance of the config screen you have to call "MidnightConfig.getScreen(parent, "modid");"
If you don't use the whole library and therefore not the automatic ModMenu integration, the code in your ModMenu integration class would look something like this:
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> MidnightConfig.getScreen(parent, "modid");
}
*/
}

View File

@@ -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);
}
}
}

View File

@@ -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<String> 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);
}
}

View File

@@ -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<ButtonEntry> {
@@ -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<ButtonEntry> {
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;

View File

@@ -1,3 +1 @@
{
"accessWidener": "midnightlib.accesswidener"
}
{}

View File

@@ -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;

View File

@@ -0,0 +1 @@
{"required": true,"minVersion": "0.8","package": "eu.midnightdust.core.mixin","compatibilityLevel": "JAVA_17","client": ["MixinOptionsScreen"],"injectors": {"defaultRequire": 1}}