mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 01:15:08 +01:00
Merge pull request #85 from TeamMidnightDust/architectury-1.21.4
backport: 1.6.8 for 1.21.1
This commit is contained in:
@@ -25,7 +25,7 @@ public class MidnightLib {
|
||||
try { if (!IS_SYSTEM_MAC) {
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}} catch (Exception e) { LOGGER.error("Error setting system look and feel", e); }
|
||||
}} catch (Exception | Error e) { LOGGER.error("Error setting system look and feel", e); }
|
||||
MidnightLibConfig.init(MOD_ID, MidnightLibConfig.class);
|
||||
}
|
||||
public static void registerAutoCommand() {
|
||||
|
||||
@@ -37,14 +37,11 @@ public abstract class MixinOptionsScreen extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "initTabNavigation")
|
||||
@Inject(at = @At("TAIL"), method = "refreshWidgetPositions")
|
||||
public void midnightlib$onResize(CallbackInfo ci) {
|
||||
if (shouldShowButton()) this.midnightlib$setButtonPos();
|
||||
}
|
||||
|
||||
|
||||
@Unique
|
||||
public void midnightlib$setButtonPos() {
|
||||
midnightlib$button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.Te
|
||||
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tab.GridScreenTab; 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.registry.Registries;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
@@ -133,7 +134,10 @@ public abstract class MidnightConfig {
|
||||
}, func);
|
||||
} else if (info.dataType.isEnum()) {
|
||||
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||
Function<Object, Text> func = value -> Text.translatable(modid + ".midnightconfig." + "enum." + info.dataType.getSimpleName() + "." + info.toTemporaryValue());
|
||||
Function<Object, Text> func = value -> {
|
||||
String translationKey = modid + ".midnightconfig.enum." + info.dataType.getSimpleName() + "." + info.toTemporaryValue();
|
||||
return I18n.hasTranslation(translationKey) ? Text.translatable(translationKey) : Text.literal(info.toTemporaryValue());
|
||||
};
|
||||
info.function = 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); button.setMessage(func.apply(info.value));
|
||||
@@ -145,11 +149,11 @@ public abstract class MidnightConfig {
|
||||
if (requiredModLoaded) entries.add(info);
|
||||
}
|
||||
public static Class<?> getUnderlyingType(Field field) {
|
||||
if (field.getType() == List.class) {
|
||||
Class<?> listType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
try { return (Class<?>) listType.getField("TYPE").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { return listType; }
|
||||
} else return field.getType();
|
||||
Class<?> rawType = field.getType();
|
||||
if (field.getType() == List.class)
|
||||
rawType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
try { return (Class<?>) rawType.getField("TYPE").get(null); // Tries to get primitive types from non-primitives (e.g. Boolean -> boolean)
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { return rawType; }
|
||||
}
|
||||
public static Tooltip getTooltip(EntryInfo info, boolean isButton) {
|
||||
String key = info.modid + ".midnightconfig."+info.field.getName()+(!isButton ? ".label" : "" )+".tooltip";
|
||||
@@ -250,9 +254,9 @@ public abstract class MidnightConfig {
|
||||
if (prevTab != null && prevTab != tabManager.getCurrentTab()) {
|
||||
prevTab = tabManager.getCurrentTab();
|
||||
this.list.clear(); fillList();
|
||||
list.setScrollAmount(0);
|
||||
list.setScrollY(0);
|
||||
}
|
||||
scrollProgress = list.getScrollAmount();
|
||||
scrollProgress = list.getScrollY();
|
||||
for (EntryInfo info : entries) try {info.field.set(null, info.value);} catch (IllegalAccessException ignored) {}
|
||||
updateButtons();
|
||||
}
|
||||
@@ -394,7 +398,7 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
this.list.addButton(widgets, name, info);
|
||||
} else this.list.addButton(List.of(), name, info);
|
||||
} list.setScrollAmount(scrollProgress);
|
||||
} list.setScrollY(scrollProgress);
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
@@ -422,7 +426,7 @@ public abstract class MidnightConfig {
|
||||
protected void drawHeaderAndFooterSeparators(DrawContext context) {
|
||||
if (renderHeaderSeparator) super.drawHeaderAndFooterSeparators(context);
|
||||
else { RenderSystem.enableBlend();
|
||||
context.drawTexture(this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0.0F, 0.0F, this.getWidth(), 2, 32, 2);
|
||||
context.drawTexture(RenderLayer::getGuiTextured, this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0.0F, 0.0F, this.getWidth(), 2, 32, 2);
|
||||
RenderSystem.disableBlend(); }
|
||||
}
|
||||
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { this.addEntry(new ButtonEntry(buttons, text, info)); }
|
||||
@@ -475,8 +479,8 @@ public abstract class MidnightConfig {
|
||||
@Override
|
||||
public void applyValue() {
|
||||
if (info.dataType == int.class) info.setValue(((Number) (e.min() + value * (e.max() - e.min()))).intValue());
|
||||
else if (info.field.getType() == double.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision());
|
||||
else if (info.field.getType() == float.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision());
|
||||
else if (info.dataType == double.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision());
|
||||
else if (info.dataType == float.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ configurations {
|
||||
compileClasspath.extendsFrom common
|
||||
runtimeClasspath.extendsFrom common
|
||||
developmentFabric.extendsFrom common
|
||||
archivesBaseName = rootProject.archives_base_name + "-fabric"
|
||||
version = rootProject.mod_version + "+" + rootProject.minecraft_version
|
||||
archivesBaseName = rootProject.archives_base_name
|
||||
version = rootProject.mod_version + "-" + project.name + "+" + rootProject.minecraft_version
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -95,7 +95,7 @@ unifiedPublishing {
|
||||
modrinth {
|
||||
token = MODRINTH_TOKEN
|
||||
id = rootProject.modrinth_id
|
||||
version = "$rootProject.version-$project.name"
|
||||
version = rootProject.mod_version + "+" + rootProject.minecraft_version + "-" + project.name
|
||||
gameVersions.addAll project.minecraft_version
|
||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
org.gradle.jvmargs=-Xmx4096M
|
||||
|
||||
minecraft_version=1.21
|
||||
supported_versions=1.21.1
|
||||
yarn_mappings=1.21+build.1
|
||||
minecraft_version=1.21.4
|
||||
supported_versions=
|
||||
yarn_mappings=1.21.4+build.1
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.6.7+1.21.1
|
||||
mod_version=1.6.8
|
||||
maven_group=eu.midnightdust
|
||||
release_type=release
|
||||
curseforge_id=488090
|
||||
modrinth_id=codAaoxh
|
||||
|
||||
fabric_loader_version=0.16.10
|
||||
fabric_api_version=0.115.0+1.21.1
|
||||
fabric_loader_version=0.16.9
|
||||
fabric_api_version=0.110.5+1.21.4
|
||||
|
||||
neoforge_version=21.0.167
|
||||
neoforge_version=21.4.3-beta
|
||||
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
||||
|
||||
quilt_loader_version=0.19.0-beta.18
|
||||
|
||||
@@ -35,8 +35,8 @@ configurations {
|
||||
canBeResolved = true
|
||||
canBeConsumed = false
|
||||
}
|
||||
archivesBaseName = rootProject.archives_base_name + "-neoforge"
|
||||
version = rootProject.mod_version + "+" + rootProject.minecraft_version
|
||||
archivesBaseName = rootProject.archives_base_name
|
||||
version = rootProject.mod_version + "-" + project.name + "+" + rootProject.minecraft_version
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -99,7 +99,7 @@ unifiedPublishing {
|
||||
modrinth {
|
||||
token = MODRINTH_TOKEN
|
||||
id = rootProject.modrinth_id
|
||||
version = "$rootProject.version-$project.name"
|
||||
version = rootProject.mod_version + "+" + rootProject.minecraft_version + "-" + project.name
|
||||
gameVersions.addAll project.minecraft_version
|
||||
if (project.supported_versions != "") gameVersions.addAll project.supported_versions
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class MidnightLibNeoForge {
|
||||
|
||||
public MidnightLibNeoForge() {
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) MidnightLib.onInitializeClient();
|
||||
MidnightLib.registerAutoCommand();
|
||||
}
|
||||
|
||||
@EventBusSubscriber(modid = "midnightlib", bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
@@ -36,6 +35,7 @@ public class MidnightLibNeoForge {
|
||||
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (minecraftClient, screen) -> MidnightConfig.getScreen(screen, modid));
|
||||
}
|
||||
});
|
||||
MidnightLib.registerAutoCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
@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, name="I am a (non-primitive) Boolean") public static Boolean nonPrimitive = true; // Example for a non-primative boolean option
|
||||
@Entry(category = TEXT) public static String name = "Hello World!"; // Example for a string option, which is in a category!
|
||||
@Entry(category = TEXT, width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a color chooser for a hexadecimal color
|
||||
@Entry(category = TEXT, idMode = 0) public static Identifier id = Identifier.ofVanilla("diamond"); // Example for an identifier with matching items displayed next to it!
|
||||
@@ -34,6 +35,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
@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 = 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 = SLIDERS, name = "I am a non-primitive double slider!", isSlider = true, min = 0d, max = 4d, precision = 10000) public static Double nonPrimitiveDoubleSlider = 3.76d; // Even works for non-primitive fields
|
||||
// The name field can be used to specify a custom translation string or plain text
|
||||
@Entry(category = LISTS, name = "I am a string list!") public static List<String> stringList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
|
||||
@Entry(category = LISTS, isColor = true, name = "I am a color list!") public static List<String> colorList = Lists.newArrayList("#ac5f99", "#11aa44"); // Lists also support colors
|
||||
|
||||
Reference in New Issue
Block a user