mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
Update to 1.19.4 & Fix invalid value tooltips
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||
id "dev.architectury.loom" version "1.0-SNAPSHOT" apply false
|
||||
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
|
||||
}
|
||||
|
||||
architectury {
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
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;
|
||||
@@ -43,11 +44,11 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
super.init();
|
||||
}
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
this.list.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredTextWithShadow(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(context);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class MidnightOverviewListWidget extends ElementListWidget<OverviewButtonEntry> {
|
||||
@@ -76,9 +77,9 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
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) {
|
||||
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(matrices, mouseX, mouseY, tickDelta);
|
||||
button.render(context, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
public List<? extends Element> children() {return buttonList;}
|
||||
public List<? extends Selectable> selectableChildren() {return buttonList;}
|
||||
|
||||
@@ -80,15 +80,17 @@ public class AutoCommand {
|
||||
return 0;
|
||||
}
|
||||
|
||||
source.sendFeedback(Text.literal("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) {
|
||||
source.sendFeedback(() -> {
|
||||
try {
|
||||
source.sendFeedback(Text.literal("The value of "+entry.getName()+" is "+entry.get(null)), false);
|
||||
return 1;
|
||||
return Text.literal("The value of "+entry.getName()+" is "+entry.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
}, false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
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;
|
||||
@@ -19,8 +19,8 @@ import net.minecraft.client.gui.tab.TabManager;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.*;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -41,10 +41,9 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** MidnightConfig v2.4.0 by TeamMidnightDust & Motschen
|
||||
/** MidnightConfig v2.4.1 by TeamMidnightDust & Motschen
|
||||
* Single class config library - feel free to copy!
|
||||
|
||||
* Based on https://github.com/Minenash/TinyConfig
|
||||
* Based on <a href="https://github.com/Minenash/TinyConfig">...</a>
|
||||
* Credits to Minenash */
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -115,9 +114,8 @@ public abstract class MidnightConfig {
|
||||
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 || type == List.class) {
|
||||
textField(info, String::length, null, Math.min(e.min(), 0), Math.max(e.max(), 1), true);
|
||||
} else if (type == boolean.class) {
|
||||
else if (type == String.class || type == List.class) 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 -> 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;
|
||||
@@ -135,6 +133,9 @@ 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());
|
||||
}
|
||||
|
||||
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
|
||||
boolean isNumber = pattern != null;
|
||||
@@ -151,6 +152,7 @@ public abstract class MidnightConfig {
|
||||
info.error = inLimits? null : 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)).formatted(Formatting.RED);
|
||||
t.setTooltip(getTooltip(info));
|
||||
}
|
||||
|
||||
info.tempValue = s;
|
||||
@@ -248,9 +250,6 @@ public abstract class MidnightConfig {
|
||||
if (this.tabNavigation.trySwitchTabsWithKey(keyCode)) return true;
|
||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
public Tooltip getTooltip(EntryInfo info) {
|
||||
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(translationPrefix+info.field.getName()+".tooltip") ? Text.translatable(translationPrefix+info.field.getName()+".tooltip") : Text.empty());
|
||||
}
|
||||
public void refresh() {
|
||||
double scrollAmount = list.getScrollAmount();
|
||||
list.clear();
|
||||
@@ -269,8 +268,8 @@ public abstract class MidnightConfig {
|
||||
String name = translationPrefix + "category." + tabId;
|
||||
if (!I18n.hasTranslation(name) && tabId.equals("default"))
|
||||
name = translationPrefix + "title";
|
||||
Tab tab = new GridScreenTab(Text.translatable(name));
|
||||
if (!tabs.containsKey(name)) {
|
||||
Tab tab = new GridScreenTab(Text.translatable(name));
|
||||
e.tab = tab;
|
||||
tabs.put(name, tab);
|
||||
} else e.tab = tabs.get(name);
|
||||
@@ -374,12 +373,12 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
this.list.render(matrices, mouseX, mouseY, delta);
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(context);
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
|
||||
drawCenteredTextWithShadow(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
super.render(matrices,mouseX,mouseY,delta);
|
||||
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
super.render(context,mouseX,mouseY,delta);
|
||||
}
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
@@ -418,11 +417,17 @@ public abstract class MidnightConfig {
|
||||
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) {
|
||||
buttons.forEach(b -> { b.setY(y); b.render(matrices, mouseX, mouseY, tickDelta); });
|
||||
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); });
|
||||
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);
|
||||
if (info.centered) context.drawTextWithShadow(textRenderer, text, MinecraftClient.getInstance().getWindow().getScaledWidth() / 2 - (textRenderer.getWidth(text) / 2), y + 5, 0xFFFFFF);
|
||||
else {
|
||||
int wrappedY = y;
|
||||
for(Iterator<OrderedText> iterator = textRenderer.wrapLines(text, (buttons.size() > 1 ? buttons.get(1).getX()-24 : MinecraftClient.getInstance().getWindow().getScaledWidth() - 24)).iterator(); iterator.hasNext(); wrappedY += 9) {
|
||||
OrderedText orderedText = iterator.next();
|
||||
context.drawTextWithShadow(textRenderer, orderedText, 12, wrappedY + 5, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<? extends Element> children() {return children;}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package eu.midnightdust.lib.util;
|
||||
|
||||
public class MidnightMathUtil {
|
||||
public static boolean isEven(int i) {
|
||||
return (i | 1) > i;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.lib.util.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
@@ -26,21 +27,14 @@ public class TexturedOverlayButtonWidget extends TexturedButtonWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
int i = 66;
|
||||
if (!this.isNarratable()) {
|
||||
i += hoveredVOffset * 2;
|
||||
} else if (this.isSelected()) {
|
||||
i += hoveredVOffset;
|
||||
}
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.enableDepthTest();
|
||||
drawNineSlicedTexture(matrices, this.getX(), this.getY(), this.width, this.height, 4, 200, 20, 0, i);
|
||||
|
||||
super.renderButton(matrices, mouseX, mouseY, delta);
|
||||
context.drawNineSlicedTexture(WIDGETS_TEXTURE, this.getX(), this.getY(), this.width, this.height, 4, 200, 20, 0, i);
|
||||
super.renderButton(context, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,8 @@
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabric-models-v0": "*",
|
||||
"fabric-resource-loader-v0": "*",
|
||||
"minecraft": ">=1.19.4"
|
||||
"minecraft": ">=1.20-beta.2"
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
org.gradle.jvmargs=-Xmx4096M
|
||||
|
||||
minecraft_version=1.19.4
|
||||
yarn_mappings=1.19.4+build.1
|
||||
enabled_platforms=quilt,fabric,forge
|
||||
minecraft_version=1.20-pre2
|
||||
yarn_mappings=1.20-pre2+build.2
|
||||
enabled_platforms=fabric
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.3.0
|
||||
mod_version=1.3.1
|
||||
maven_group=eu.midnightdust
|
||||
|
||||
fabric_loader_version=0.14.19
|
||||
fabric_api_version=0.76.0+1.19.4
|
||||
fabric_api_version=0.81.2+1.20
|
||||
|
||||
forge_version=1.19.4-45.0.40
|
||||
|
||||
quilt_loader_version=0.18.6
|
||||
quilt_loader_version=0.19.0-beta.13
|
||||
quilt_fabric_api_version=6.0.0-beta.2+0.76.0-1.19.4
|
||||
mod_menu_version = 5.0.2
|
||||
@@ -10,7 +10,7 @@ pluginManagement {
|
||||
include("common")
|
||||
include("fabric-like")
|
||||
include("fabric")
|
||||
include("quilt")
|
||||
include("forge")
|
||||
//include("quilt")
|
||||
//include("forge")
|
||||
|
||||
rootProject.name = "midnightlib"
|
||||
|
||||
Reference in New Issue
Block a user