mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 09:05:08 +01:00
Compare commits
3 Commits
60a34c63a3
...
e660509fee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e660509fee | ||
|
|
625b820cf0 | ||
|
|
fa5119ab04 |
@@ -59,8 +59,7 @@ loom {
|
||||
}
|
||||
if (loader == "forge") {
|
||||
forge.mixinConfigs(
|
||||
"template-common.mixins.json",
|
||||
"template-forge.mixins.json",
|
||||
"midnightlib.mixins.json",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,25 @@ import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
@Mod("midnightlib")
|
||||
public class MidnightLib {
|
||||
*///?} else if forge {
|
||||
/*import java.util.ConcurrentModificationException;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.IExtensionPoint;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.NetworkConstants;
|
||||
|
||||
@Mod("midnightlib")
|
||||
public class MidnightLib {
|
||||
*///?}
|
||||
@@ -126,4 +145,37 @@ public class MidnightLib {
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
|
||||
//? if forge {
|
||||
/*public MidnightLib() {
|
||||
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (remote, server) -> true));
|
||||
if (PlatformFunctions.isClientEnv()) this.onInitializeClient();
|
||||
}
|
||||
|
||||
public static List<LiteralArgumentBuilder<CommandSourceStack>> commands = new ArrayList<>();
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "midnightlib", bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
public static class MidnightLibBusEvents {
|
||||
@SubscribeEvent
|
||||
public static void onPostInit(FMLClientSetupEvent event) {
|
||||
ModList.get().forEachModContainer((modid, modContainer) -> {
|
||||
if (MidnightConfig.configInstances.containsKey(modid) && !MidnightLib.hiddenMods.contains(modid)) {
|
||||
modContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((minecraftClient, screen) -> MidnightConfig.getScreen(screen, modid)));
|
||||
}
|
||||
});
|
||||
MidnightLib.registerAutoCommand();
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "midnightlib")
|
||||
public static class MidnightLibEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
try {
|
||||
commands.forEach(command -> event.getDispatcher().register(command));
|
||||
}
|
||||
catch (ConcurrentModificationException ignored) {}
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MidnightLibConfig extends MidnightConfig {
|
||||
public static final boolean HAS_MODMENU = PlatformFunctions.isModLoaded("modmenu") || Objects.equals(PlatformFunctions.getPlatformName(), "neoforge");
|
||||
public static final boolean HAS_MODMENU = PlatformFunctions.isModLoaded("modmenu") || !Objects.equals(PlatformFunctions.getPlatformName(), "fabric");
|
||||
|
||||
@Entry public static ConfigButton config_screen_list = HAS_MODMENU ? ConfigButton.MODMENU : ConfigButton.TRUE;
|
||||
|
||||
|
||||
@@ -1,34 +1,42 @@
|
||||
package eu.midnightdust.core.mixin;
|
||||
|
||||
import eu.midnightdust.core.screen.MidnightConfigOverviewScreen;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
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;
|
||||
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import static eu.midnightdust.core.MidnightLib.MOD_ID;
|
||||
//? if >= 1.21 {
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
||||
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
||||
import static eu.midnightdust.core.MidnightLib.MOD_ID;
|
||||
//?} else {
|
||||
/*import net.minecraft.client.gui.components.TextAndImageButton;
|
||||
import net.minecraft.client.gui.screens.OptionsScreen;
|
||||
*///?}
|
||||
|
||||
import static eu.midnightdust.core.config.MidnightLibConfig.shouldShowButton;
|
||||
|
||||
@Mixin(OptionsScreen.class)
|
||||
public abstract class MixinOptionsScreen extends Screen {
|
||||
private MixinOptionsScreen(Component title) {super(title);}
|
||||
//? if >= 1.20.4 {
|
||||
@Shadow @Final private HeaderAndFooterLayout layout;
|
||||
@Unique SpriteIconButton midnightlib$button = SpriteIconButton.builder(Component.translatable("midnightlib.overview.title"), (
|
||||
buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new MidnightConfigOverviewScreen(this)), true)
|
||||
.sprite(ResourceLocation.fromNamespaceAndPath(MOD_ID,"icon/"+MOD_ID), 16, 16).size(20, 20).build();
|
||||
|
||||
private MixinOptionsScreen(Component title) {super(title);}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "init")
|
||||
public void midnightlib$onInit(CallbackInfo ci) {
|
||||
if (shouldShowButton()) {
|
||||
@@ -46,4 +54,17 @@ public abstract class MixinOptionsScreen extends Screen {
|
||||
public void midnightlib$setButtonPos() {
|
||||
midnightlib$button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
|
||||
}
|
||||
//?} else {
|
||||
/*@Unique TextAndImageButton midnightlib$button = TextAndImageButton.builder(Component.translatable("midnightlib.overview.title"), new ResourceLocation("midnightlib", "icon/midnightlib.png"),
|
||||
button -> Objects.requireNonNull(minecraft).setScreen(new MidnightConfigOverviewScreen(this))).textureSize(16, 16).usedTextureSize(16, 16).offset(0, 2).build();
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "init")
|
||||
private void midnightlib$init(CallbackInfo ci) {
|
||||
if (shouldShowButton()){
|
||||
midnightlib$button.setWidth(20);
|
||||
midnightlib$button.setPosition(this.width / 2 + 158, this.height / 6 - 12);
|
||||
this.addRenderableWidget(midnightlib$button);
|
||||
}
|
||||
}
|
||||
*///?}
|
||||
}
|
||||
@@ -38,8 +38,14 @@ public class MidnightConfigOverviewScreen extends Screen {
|
||||
}
|
||||
@Override
|
||||
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
//? if >= 1.21 {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
//?} else {
|
||||
/*super.renderBackground(context);
|
||||
*///?}
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
context.drawCenteredString(font, title, width / 2, 10, 0xFFFFFFFF);
|
||||
//? if < 1.21
|
||||
/*super.render(context, mouseX, mouseY, delta);*/
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package eu.midnightdust.lib.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
@@ -35,7 +37,13 @@ public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
|
||||
int scaledWidth = Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
||||
|
||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
||||
title = new MultiLineTextWidget(12, 0, Component.translationArg(text), textRenderer).setCentered(centered);
|
||||
title = new MultiLineTextWidget(12, 0,
|
||||
//? if >= 1.21 {
|
||||
Component.translationArg(text)
|
||||
//?} else {
|
||||
/*text.copy()
|
||||
*///?}
|
||||
, textRenderer).setCentered(centered);
|
||||
if (info != null)
|
||||
title.setTooltip(info.getTooltip(false));
|
||||
title.setMaxWidth(!buttons.isEmpty() ? buttons.get(buttons.size() > 2 ? buttons.size() - 1 : 0).getX() - 16 : scaledWidth - 24);
|
||||
@@ -58,17 +66,19 @@ public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
|
||||
title.setY(y + 5);
|
||||
title.render(context, mouseX, mouseY, tickDelta);
|
||||
|
||||
if (info.entry != null && !this.buttons.isEmpty() && this.buttons.getFirst() instanceof AbstractWidget widget) {
|
||||
int idMode = this.info.entry.idMode();
|
||||
if (idMode != -1) context.renderItem(idMode == 0 ?
|
||||
//? if >= 1.21.4 {
|
||||
if (info.entry != null && !this.buttons.isEmpty()) {
|
||||
Optional.ofNullable(this.buttons.get(0)).ifPresent(widget -> {
|
||||
int idMode = this.info.entry.idMode();
|
||||
if (idMode != -1) context.renderItem(idMode == 0 ?
|
||||
//? if >= 1.21.4 {
|
||||
BuiltInRegistries.ITEM.getValue(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
||||
: BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
||||
//?} else {
|
||||
/*BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
||||
: BuiltInRegistries.BLOCK.get(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
||||
*///?}
|
||||
widget.getX() + widget.getWidth() - 18, y + 2);
|
||||
/*BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
||||
: BuiltInRegistries.BLOCK.get(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
||||
*///?}
|
||||
widget.getX() + widget.getWidth() - 18, y + 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +90,11 @@ public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
|
||||
/*public boolean mouseClicked(double d, double e, int i) {
|
||||
*///?}
|
||||
if (this.info != null && this.info.comment != null && !this.info.comment.url().isBlank())
|
||||
ConfirmLinkScreen.confirmLinkNow(Minecraft.getInstance().screen, this.info.comment.url(), true);
|
||||
//? if >= 1.21 {
|
||||
ConfirmLinkScreen.confirmLinkNow(Minecraft.getInstance().screen, this.info.comment.url(), true);
|
||||
//?} else {
|
||||
/*ConfirmLinkScreen.confirmLinkNow(this.info.comment.url(), Minecraft.getInstance().screen, true);
|
||||
*///?}
|
||||
//? if >= 1.21.9 {
|
||||
return super.mouseClicked(click, doubled);
|
||||
//?} else {
|
||||
|
||||
@@ -3,6 +3,8 @@ package eu.midnightdust.lib.config;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
import net.minecraft.client.gui.components.tabs.Tab;
|
||||
@@ -81,8 +83,8 @@ public class EntryInfo {
|
||||
if (!condition.requiredModId().isEmpty() && !PlatformFunctions.isModLoaded(condition.requiredModId()))
|
||||
this.conditionsMet = false;
|
||||
String requiredOption = condition.requiredOption().contains(":") ? condition.requiredOption() : (this.modid + ":" + condition.requiredOption());
|
||||
if (MidnightConfig.entries.get(requiredOption) instanceof EntryInfo info)
|
||||
this.conditionsMet &= List.of(condition.requiredValue()).contains(info.tempValue);
|
||||
Optional.ofNullable(MidnightConfig.entries.get(requiredOption)).ifPresent(info -> this.conditionsMet &= List.of(condition.requiredValue()).contains(info.tempValue));
|
||||
|
||||
if (!this.conditionsMet) break;
|
||||
}
|
||||
if (prevConditionState != this.conditionsMet) MidnightConfig.configInstances.get(modid).reloadScreen = true;
|
||||
|
||||
@@ -45,10 +45,16 @@ public abstract class MidnightConfig {
|
||||
public boolean shouldSkipClass(Class<?> clazz) { return false; }
|
||||
public boolean shouldSkipField(FieldAttributes fieldAttributes) { return fieldAttributes.getAnnotation(Entry.class) == null; }
|
||||
})
|
||||
.registerTypeAdapter(ResourceLocation.class, new TypeAdapter<ResourceLocation>() {
|
||||
public void write(JsonWriter out, ResourceLocation id) throws IOException { out.value(id.toString()); }
|
||||
public ResourceLocation read(JsonReader in) throws IOException { return ResourceLocation.parse(in.nextString()); }
|
||||
}).setPrettyPrinting().create();
|
||||
.registerTypeAdapter(ResourceLocation.class,
|
||||
//? if >= 1.21.4 {
|
||||
new TypeAdapter<ResourceLocation>() {
|
||||
public void write(JsonWriter out, ResourceLocation id) throws IOException { out.value(id.toString()); }
|
||||
public ResourceLocation read(JsonReader in) throws IOException { return ResourceLocation.parse(in.nextString()); }
|
||||
}
|
||||
//?} else {
|
||||
/*new ResourceLocation.Serializer()
|
||||
*///?}
|
||||
).setPrettyPrinting().create();
|
||||
|
||||
protected static final LinkedHashMap<String, EntryInfo> entries = new LinkedHashMap<>(); // modid:fieldName -> EntryInfo
|
||||
|
||||
@@ -124,7 +130,13 @@ public abstract class MidnightConfig {
|
||||
info.function = (BiFunction<EditBox, Button, Predicate<String>>) (t, b) -> s -> {
|
||||
s = s.trim();
|
||||
if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches()) ||
|
||||
(info.dataType == ResourceLocation.class && ResourceLocation.read(s).isError())) return false;
|
||||
(info.dataType == ResourceLocation.class && ResourceLocation.read(s)
|
||||
//? if >= 1.21 {
|
||||
.isError()
|
||||
//?} else {
|
||||
/*.error().isPresent()
|
||||
*///?}
|
||||
)) return false;
|
||||
|
||||
Number value = 0; boolean inLimits = false; info.error = null;
|
||||
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
||||
|
||||
@@ -18,7 +18,11 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
||||
public boolean renderHeaderSeparator = true;
|
||||
|
||||
public MidnightConfigListWidget(Minecraft client, int width, int height, int y, int itemHeight) {
|
||||
super(client, width, height, y, itemHeight);
|
||||
//? if >= 1.21 {
|
||||
super(client, width, height, y, itemHeight);
|
||||
//?} else {
|
||||
/*super(client, width, height, y, height + y, itemHeight);
|
||||
*///?}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,6 +34,7 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
||||
return this.width - 7;
|
||||
}
|
||||
|
||||
//? if >= 1.21 {
|
||||
@Override
|
||||
public void renderListSeparators(GuiGraphics context) {
|
||||
if (renderHeaderSeparator)
|
||||
@@ -39,10 +44,11 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
||||
//? if >= 1.21.6 {
|
||||
RenderPipelines.GUI_TEXTURED,
|
||||
//?} else if >= 1.21.4 {
|
||||
//RenderType::guiTextured,
|
||||
//?}
|
||||
/*RenderType::guiTextured,
|
||||
*///?}
|
||||
this.minecraft.level == null ? Screen.FOOTER_SEPARATOR : Screen.INWORLD_FOOTER_SEPARATOR, this.getX(), this.getBottom(), 0, 0, this.getWidth(), 2, 32, 2);
|
||||
}
|
||||
//?}
|
||||
|
||||
public void addButton(List<AbstractWidget> buttons, Component text, EntryInfo info) {
|
||||
this.addEntry(new ButtonEntry(buttons, text, info));
|
||||
|
||||
@@ -4,11 +4,8 @@ import com.google.common.collect.Lists;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.*;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
import net.minecraft.client.gui.components.tabs.GridLayoutTab;
|
||||
import net.minecraft.client.gui.components.tabs.Tab;
|
||||
import net.minecraft.client.gui.components.tabs.TabManager;
|
||||
@@ -32,6 +29,10 @@ import java.util.function.Predicate;
|
||||
import net.minecraft.client.input.KeyEvent;
|
||||
//?}
|
||||
|
||||
//? if >=1.21 {
|
||||
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||
//?}
|
||||
|
||||
public class MidnightConfigScreen extends Screen {
|
||||
public MidnightConfig instance;
|
||||
public final String translationPrefix, modid;
|
||||
@@ -78,11 +79,7 @@ public class MidnightConfigScreen extends Screen {
|
||||
updateList();
|
||||
list.setScrollAmount(0);
|
||||
}
|
||||
//? >= 1.21.4 {
|
||||
scrollProgress = list.scrollAmount();
|
||||
//?} else {
|
||||
/*scrollProgress = list.getScrollAmount();
|
||||
*///?}
|
||||
scrollProgress = /*? < 1.21.4 {*/ /*list.getScrollAmount() *//*?} else {*/ list.scrollAmount() /*?}*/;
|
||||
for (EntryInfo info : MidnightConfig.entries.values())
|
||||
if (Objects.equals(modid, info.modid)) info.updateFieldValue();
|
||||
updateButtons();
|
||||
@@ -97,9 +94,10 @@ public class MidnightConfigScreen extends Screen {
|
||||
|
||||
for (ButtonEntry entry : this.list.children()) {
|
||||
if (entry.buttons != null && entry.buttons.size() > 1 && entry.info.field != null) {
|
||||
if (entry.buttons.get(0) instanceof AbstractWidget widget)
|
||||
Optional.ofNullable(entry.buttons.get(0)).ifPresent(widget -> {
|
||||
if (widget.isFocused() || widget.isHovered())
|
||||
widget.setTooltip(entry.info.getTooltip(true));
|
||||
});
|
||||
if (entry.buttons.get(1) instanceof Button button)
|
||||
button.active = !Objects.equals(String.valueOf(entry.info.value), String.valueOf(entry.info.defaultValue)) && entry.info.conditionsMet;
|
||||
}
|
||||
@@ -169,12 +167,24 @@ public class MidnightConfigScreen extends Screen {
|
||||
if (!visibleButLocked) continue;
|
||||
}
|
||||
if (info.modid.equals(modid) && (info.tab == null || info.tab == tabManager.getCurrentTab())) {
|
||||
SpriteIconButton resetButton = SpriteIconButton.builder(Component.translatable("controls.reset"), (button -> {
|
||||
//? if >= 1.21 {
|
||||
SpriteIconButton resetButton = SpriteIconButton.builder(Component.translatable("controls.reset"),
|
||||
//?} else {
|
||||
/*TextAndImageButton resetButton = TextAndImageButton.builder(Component.translatable("controls.reset"), new ResourceLocation("midnightlib", "icon/reset.png"),
|
||||
*///?}
|
||||
(button -> {
|
||||
info.value = info.defaultValue;
|
||||
info.listIndex = 0;
|
||||
info.tempValue = info.toTemporaryValue();
|
||||
updateList();
|
||||
}), true).sprite(ResourceLocation.fromNamespaceAndPath("midnightlib", "icon/reset"), 12, 12).size(20, 20).build();
|
||||
})
|
||||
//? if >= 1.21 {
|
||||
, true).sprite(ResourceLocation.fromNamespaceAndPath("midnightlib", "icon/reset"), 12, 12).size(20, 20).build();
|
||||
//?} else {
|
||||
/*).textureSize(12, 12).usedTextureSize(12, 12).offset(0, 4).build();
|
||||
resetButton.setWidth(20);
|
||||
*///?}
|
||||
|
||||
resetButton.setPosition(width - 205 + 150 + 25, 0);
|
||||
|
||||
if (info.function != null) {
|
||||
@@ -225,7 +235,13 @@ public class MidnightConfigScreen extends Screen {
|
||||
}
|
||||
info.actionButton = colorButton;
|
||||
} else if (e.selectionMode() > -1) {
|
||||
Button explorerButton = SpriteIconButton.builder(Component.empty(),
|
||||
|
||||
Button explorerButton =
|
||||
//? if >= 1.21 {
|
||||
SpriteIconButton.builder(Component.empty(),
|
||||
//?} else {
|
||||
/*TextAndImageButton.builder(Component.empty(), new ResourceLocation("midnightlib", "icon/explorer.png"),
|
||||
*///?}
|
||||
button -> new Thread(() -> {
|
||||
JFileChooser fileChooser = new JFileChooser(info.tempValue);
|
||||
fileChooser.setFileSelectionMode(e.selectionMode());
|
||||
@@ -238,8 +254,13 @@ public class MidnightConfigScreen extends Screen {
|
||||
info.setValue(fileChooser.getSelectedFile().getAbsolutePath());
|
||||
updateList();
|
||||
}
|
||||
}).start(), true
|
||||
).sprite(ResourceLocation.fromNamespaceAndPath("midnightlib", "icon/explorer"), 12, 12).size(20, 20).build();
|
||||
}).start()
|
||||
//? if >= 1.21 {
|
||||
, true).sprite(ResourceLocation.fromNamespaceAndPath("midnightlib", "icon/explorer"), 12, 12).size(20, 20)
|
||||
//?} else {
|
||||
/*).textureSize(12, 12).usedTextureSize(12, 12).offset(0, 4)
|
||||
*///?}
|
||||
.build();
|
||||
explorerButton.setTooltip(Tooltip.create(Component.translatable("midnightconfig.action.file_chooser")));
|
||||
explorerButton.setPosition(width - 185, 0);
|
||||
info.actionButton = explorerButton;
|
||||
@@ -269,8 +290,14 @@ public class MidnightConfigScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
//? if >= 1.21 {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
//?} else {
|
||||
/*super.renderBackground(context);
|
||||
*///?}
|
||||
this.list.render(context, mouseX, mouseY, delta);
|
||||
if (tabs.size() < 2) context.drawCenteredString(font, title, width / 2, 10, 0xFFFFFFFF);
|
||||
//? if < 1.21
|
||||
/*super.render(context, mouseX, mouseY, delta);*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ package eu.midnightdust.lib.util;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import eu.midnightdust.core.MidnightLib;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
//? if fabric {
|
||||
import net.fabricmc.api.EnvType;
|
||||
@@ -55,6 +59,20 @@ public class PlatformFunctions {
|
||||
MidnightLib.commands.add(command);
|
||||
}
|
||||
*///?} else if forge {
|
||||
//
|
||||
//?}
|
||||
/*public static String getPlatformName() {
|
||||
return "forge";
|
||||
}
|
||||
public static Path getConfigDirectory() {
|
||||
return FMLPaths.CONFIGDIR.get();
|
||||
}
|
||||
public static boolean isClientEnv() {
|
||||
return FMLEnvironment.dist.isClient();
|
||||
}
|
||||
public static boolean isModLoaded(String modid) {
|
||||
return ModList.get().isLoaded(modid);
|
||||
}
|
||||
public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> command) {
|
||||
MidnightLib.commands.add(command);
|
||||
}
|
||||
*///?}
|
||||
}
|
||||
|
||||
31
src/main/resources/META-INF/mods.toml
Normal file
31
src/main/resources/META-INF/mods.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[43,)"
|
||||
#issueTrackerURL = ""
|
||||
license = "MIT License"
|
||||
|
||||
[[mods]]
|
||||
modId = "midnightlib"
|
||||
version = "${version}"
|
||||
displayName = "${name}"
|
||||
logoFile = "midnightlib.png"
|
||||
authors = "TeamMidnightDust, Motschen"
|
||||
description = '''
|
||||
Lightweight config library with config screens and commands.
|
||||
'''
|
||||
|
||||
[[mixins]]
|
||||
config = "midnightlib.mixins.json"
|
||||
|
||||
[[dependencies.midnightlib]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[43,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.midnightlib]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.20,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
@@ -34,7 +34,7 @@
|
||||
},
|
||||
"depends": {
|
||||
"fabric-resource-loader-v0": "*",
|
||||
"minecraft": ">=1.21"
|
||||
"minecraft": "*"
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.midnightdust.test;
|
||||
|
||||
//? if >= 1.21.10 {
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import eu.midnightdust.lib.config.EntryInfo;
|
||||
@@ -97,3 +98,4 @@ public class MidnightLibExtras {
|
||||
}
|
||||
}
|
||||
}
|
||||
//?}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.midnightdust.test.config;
|
||||
|
||||
//? if >= 1.21.10 {
|
||||
import com.google.common.collect.Lists;
|
||||
import eu.midnightdust.lib.config.MidnightConfigListWidget;
|
||||
import eu.midnightdust.lib.config.MidnightConfigScreen;
|
||||
@@ -169,5 +170,5 @@ public class MidnightConfigExample extends MidnightConfig {
|
||||
MidnightLibExtras.KeybindButton.add(Minecraft.getInstance().options.keyDrop, list, screen);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//?}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 136 B |
Binary file not shown.
|
After Width: | Height: | Size: 136 B |
Binary file not shown.
|
After Width: | Height: | Size: 114 B |
Binary file not shown.
|
After Width: | Height: | Size: 136 B |
Binary file not shown.
|
After Width: | Height: | Size: 136 B |
Binary file not shown.
|
After Width: | Height: | Size: 114 B |
6
versions/1.20.1-forge/src/main/resources/pack.mcmeta
Normal file
6
versions/1.20.1-forge/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "MidnightLib",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user