mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
stonecutter: support MC 1.20.1 (Fabric)
This commit is contained in:
@@ -1,34 +1,42 @@
|
|||||||
package eu.midnightdust.core.mixin;
|
package eu.midnightdust.core.mixin;
|
||||||
|
|
||||||
import eu.midnightdust.core.screen.MidnightConfigOverviewScreen;
|
import eu.midnightdust.core.screen.MidnightConfigOverviewScreen;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import java.util.Objects;
|
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.Screen;
|
||||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
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;
|
import static eu.midnightdust.core.config.MidnightLibConfig.shouldShowButton;
|
||||||
|
|
||||||
@Mixin(OptionsScreen.class)
|
@Mixin(OptionsScreen.class)
|
||||||
public abstract class MixinOptionsScreen extends Screen {
|
public abstract class MixinOptionsScreen extends Screen {
|
||||||
|
private MixinOptionsScreen(Component title) {super(title);}
|
||||||
|
//? if >= 1.20.4 {
|
||||||
@Shadow @Final private HeaderAndFooterLayout layout;
|
@Shadow @Final private HeaderAndFooterLayout layout;
|
||||||
@Unique SpriteIconButton midnightlib$button = SpriteIconButton.builder(Component.translatable("midnightlib.overview.title"), (
|
@Unique SpriteIconButton midnightlib$button = SpriteIconButton.builder(Component.translatable("midnightlib.overview.title"), (
|
||||||
buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new MidnightConfigOverviewScreen(this)), true)
|
buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new MidnightConfigOverviewScreen(this)), true)
|
||||||
.sprite(ResourceLocation.fromNamespaceAndPath(MOD_ID,"icon/"+MOD_ID), 16, 16).size(20, 20).build();
|
.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")
|
@Inject(at = @At("HEAD"), method = "init")
|
||||||
public void midnightlib$onInit(CallbackInfo ci) {
|
public void midnightlib$onInit(CallbackInfo ci) {
|
||||||
if (shouldShowButton()) {
|
if (shouldShowButton()) {
|
||||||
@@ -46,4 +54,17 @@ public abstract class MixinOptionsScreen extends Screen {
|
|||||||
public void midnightlib$setButtonPos() {
|
public void midnightlib$setButtonPos() {
|
||||||
midnightlib$button.setPosition(layout.getWidth() / 2 + 158, layout.getY() + layout.getFooterHeight() - 4);
|
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
|
@Override
|
||||||
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
|
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);
|
this.list.render(context, mouseX, mouseY, delta);
|
||||||
context.drawCenteredString(font, title, width / 2, 10, 0xFFFFFFFF);
|
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 com.google.common.collect.Lists;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
@@ -35,7 +37,13 @@ public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
|
|||||||
int scaledWidth = Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
int scaledWidth = Minecraft.getInstance().getWindow().getGuiScaledWidth();
|
||||||
|
|
||||||
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
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)
|
if (info != null)
|
||||||
title.setTooltip(info.getTooltip(false));
|
title.setTooltip(info.getTooltip(false));
|
||||||
title.setMaxWidth(!buttons.isEmpty() ? buttons.get(buttons.size() > 2 ? buttons.size() - 1 : 0).getX() - 16 : scaledWidth - 24);
|
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.setY(y + 5);
|
||||||
title.render(context, mouseX, mouseY, tickDelta);
|
title.render(context, mouseX, mouseY, tickDelta);
|
||||||
|
|
||||||
if (info.entry != null && !this.buttons.isEmpty() && this.buttons.getFirst() instanceof AbstractWidget widget) {
|
if (info.entry != null && !this.buttons.isEmpty()) {
|
||||||
int idMode = this.info.entry.idMode();
|
Optional.ofNullable(this.buttons.get(0)).ifPresent(widget -> {
|
||||||
if (idMode != -1) context.renderItem(idMode == 0 ?
|
int idMode = this.info.entry.idMode();
|
||||||
//? if >= 1.21.4 {
|
if (idMode != -1) context.renderItem(idMode == 0 ?
|
||||||
|
//? if >= 1.21.4 {
|
||||||
BuiltInRegistries.ITEM.getValue(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
BuiltInRegistries.ITEM.getValue(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
||||||
: BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
: BuiltInRegistries.BLOCK.getValue(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
||||||
//?} else {
|
//?} else {
|
||||||
/*BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
/*BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
|
||||||
: BuiltInRegistries.BLOCK.get(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
: BuiltInRegistries.BLOCK.get(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
|
||||||
*///?}
|
*///?}
|
||||||
widget.getX() + widget.getWidth() - 18, y + 2);
|
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) {
|
/*public boolean mouseClicked(double d, double e, int i) {
|
||||||
*///?}
|
*///?}
|
||||||
if (this.info != null && this.info.comment != null && !this.info.comment.url().isBlank())
|
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 {
|
//? if >= 1.21.9 {
|
||||||
return super.mouseClicked(click, doubled);
|
return super.mouseClicked(click, doubled);
|
||||||
//?} else {
|
//?} else {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package eu.midnightdust.lib.config;
|
|||||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.components.Tooltip;
|
import net.minecraft.client.gui.components.Tooltip;
|
||||||
import net.minecraft.client.gui.components.tabs.Tab;
|
import net.minecraft.client.gui.components.tabs.Tab;
|
||||||
@@ -81,8 +83,8 @@ public class EntryInfo {
|
|||||||
if (!condition.requiredModId().isEmpty() && !PlatformFunctions.isModLoaded(condition.requiredModId()))
|
if (!condition.requiredModId().isEmpty() && !PlatformFunctions.isModLoaded(condition.requiredModId()))
|
||||||
this.conditionsMet = false;
|
this.conditionsMet = false;
|
||||||
String requiredOption = condition.requiredOption().contains(":") ? condition.requiredOption() : (this.modid + ":" + condition.requiredOption());
|
String requiredOption = condition.requiredOption().contains(":") ? condition.requiredOption() : (this.modid + ":" + condition.requiredOption());
|
||||||
if (MidnightConfig.entries.get(requiredOption) instanceof EntryInfo info)
|
Optional.ofNullable(MidnightConfig.entries.get(requiredOption)).ifPresent(info -> this.conditionsMet &= List.of(condition.requiredValue()).contains(info.tempValue));
|
||||||
this.conditionsMet &= List.of(condition.requiredValue()).contains(info.tempValue);
|
|
||||||
if (!this.conditionsMet) break;
|
if (!this.conditionsMet) break;
|
||||||
}
|
}
|
||||||
if (prevConditionState != this.conditionsMet) MidnightConfig.configInstances.get(modid).reloadScreen = true;
|
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 shouldSkipClass(Class<?> clazz) { return false; }
|
||||||
public boolean shouldSkipField(FieldAttributes fieldAttributes) { return fieldAttributes.getAnnotation(Entry.class) == null; }
|
public boolean shouldSkipField(FieldAttributes fieldAttributes) { return fieldAttributes.getAnnotation(Entry.class) == null; }
|
||||||
})
|
})
|
||||||
.registerTypeAdapter(ResourceLocation.class, new TypeAdapter<ResourceLocation>() {
|
.registerTypeAdapter(ResourceLocation.class,
|
||||||
public void write(JsonWriter out, ResourceLocation id) throws IOException { out.value(id.toString()); }
|
//? if >= 1.21.6 {
|
||||||
public ResourceLocation read(JsonReader in) throws IOException { return ResourceLocation.parse(in.nextString()); }
|
new TypeAdapter<ResourceLocation>() {
|
||||||
}).setPrettyPrinting().create();
|
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
|
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 -> {
|
info.function = (BiFunction<EditBox, Button, Predicate<String>>) (t, b) -> s -> {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches()) ||
|
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;
|
Number value = 0; boolean inLimits = false; info.error = null;
|
||||||
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
|||||||
public boolean renderHeaderSeparator = true;
|
public boolean renderHeaderSeparator = true;
|
||||||
|
|
||||||
public MidnightConfigListWidget(Minecraft client, int width, int height, int y, int itemHeight) {
|
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
|
@Override
|
||||||
@@ -30,6 +34,7 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
|||||||
return this.width - 7;
|
return this.width - 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//? if >= 1.21 {
|
||||||
@Override
|
@Override
|
||||||
public void renderListSeparators(GuiGraphics context) {
|
public void renderListSeparators(GuiGraphics context) {
|
||||||
if (renderHeaderSeparator)
|
if (renderHeaderSeparator)
|
||||||
@@ -39,10 +44,11 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
|
|||||||
//? if >= 1.21.6 {
|
//? if >= 1.21.6 {
|
||||||
RenderPipelines.GUI_TEXTURED,
|
RenderPipelines.GUI_TEXTURED,
|
||||||
//?} else if >= 1.21.4 {
|
//?} 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);
|
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) {
|
public void addButton(List<AbstractWidget> buttons, Component text, EntryInfo info) {
|
||||||
this.addEntry(new ButtonEntry(buttons, text, 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.ChatFormatting;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
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.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.GridLayoutTab;
|
||||||
import net.minecraft.client.gui.components.tabs.Tab;
|
import net.minecraft.client.gui.components.tabs.Tab;
|
||||||
import net.minecraft.client.gui.components.tabs.TabManager;
|
import net.minecraft.client.gui.components.tabs.TabManager;
|
||||||
@@ -32,6 +29,10 @@ import java.util.function.Predicate;
|
|||||||
import net.minecraft.client.input.KeyEvent;
|
import net.minecraft.client.input.KeyEvent;
|
||||||
//?}
|
//?}
|
||||||
|
|
||||||
|
//? if >=1.21 {
|
||||||
|
import net.minecraft.client.gui.components.SpriteIconButton;
|
||||||
|
//?}
|
||||||
|
|
||||||
public class MidnightConfigScreen extends Screen {
|
public class MidnightConfigScreen extends Screen {
|
||||||
public MidnightConfig instance;
|
public MidnightConfig instance;
|
||||||
public final String translationPrefix, modid;
|
public final String translationPrefix, modid;
|
||||||
@@ -78,11 +79,7 @@ public class MidnightConfigScreen extends Screen {
|
|||||||
updateList();
|
updateList();
|
||||||
list.setScrollAmount(0);
|
list.setScrollAmount(0);
|
||||||
}
|
}
|
||||||
//? >= 1.21.4 {
|
scrollProgress = /*? < 1.21.4 {*/ /*list.getScrollAmount() *//*?} else {*/ list.scrollAmount() /*?}*/;
|
||||||
scrollProgress = list.scrollAmount();
|
|
||||||
//?} else {
|
|
||||||
/*scrollProgress = list.getScrollAmount();
|
|
||||||
*///?}
|
|
||||||
for (EntryInfo info : MidnightConfig.entries.values())
|
for (EntryInfo info : MidnightConfig.entries.values())
|
||||||
if (Objects.equals(modid, info.modid)) info.updateFieldValue();
|
if (Objects.equals(modid, info.modid)) info.updateFieldValue();
|
||||||
updateButtons();
|
updateButtons();
|
||||||
@@ -97,9 +94,10 @@ public class MidnightConfigScreen extends Screen {
|
|||||||
|
|
||||||
for (ButtonEntry entry : this.list.children()) {
|
for (ButtonEntry entry : this.list.children()) {
|
||||||
if (entry.buttons != null && entry.buttons.size() > 1 && entry.info.field != null) {
|
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())
|
if (widget.isFocused() || widget.isHovered())
|
||||||
widget.setTooltip(entry.info.getTooltip(true));
|
widget.setTooltip(entry.info.getTooltip(true));
|
||||||
|
});
|
||||||
if (entry.buttons.get(1) instanceof Button button)
|
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;
|
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 (!visibleButLocked) continue;
|
||||||
}
|
}
|
||||||
if (info.modid.equals(modid) && (info.tab == null || info.tab == tabManager.getCurrentTab())) {
|
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.value = info.defaultValue;
|
||||||
info.listIndex = 0;
|
info.listIndex = 0;
|
||||||
info.tempValue = info.toTemporaryValue();
|
info.tempValue = info.toTemporaryValue();
|
||||||
updateList();
|
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);
|
resetButton.setPosition(width - 205 + 150 + 25, 0);
|
||||||
|
|
||||||
if (info.function != null) {
|
if (info.function != null) {
|
||||||
@@ -225,7 +235,13 @@ public class MidnightConfigScreen extends Screen {
|
|||||||
}
|
}
|
||||||
info.actionButton = colorButton;
|
info.actionButton = colorButton;
|
||||||
} else if (e.selectionMode() > -1) {
|
} 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(() -> {
|
button -> new Thread(() -> {
|
||||||
JFileChooser fileChooser = new JFileChooser(info.tempValue);
|
JFileChooser fileChooser = new JFileChooser(info.tempValue);
|
||||||
fileChooser.setFileSelectionMode(e.selectionMode());
|
fileChooser.setFileSelectionMode(e.selectionMode());
|
||||||
@@ -238,8 +254,13 @@ public class MidnightConfigScreen extends Screen {
|
|||||||
info.setValue(fileChooser.getSelectedFile().getAbsolutePath());
|
info.setValue(fileChooser.getSelectedFile().getAbsolutePath());
|
||||||
updateList();
|
updateList();
|
||||||
}
|
}
|
||||||
}).start(), true
|
}).start()
|
||||||
).sprite(ResourceLocation.fromNamespaceAndPath("midnightlib", "icon/explorer"), 12, 12).size(20, 20).build();
|
//? 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.setTooltip(Tooltip.create(Component.translatable("midnightconfig.action.file_chooser")));
|
||||||
explorerButton.setPosition(width - 185, 0);
|
explorerButton.setPosition(width - 185, 0);
|
||||||
info.actionButton = explorerButton;
|
info.actionButton = explorerButton;
|
||||||
@@ -269,8 +290,14 @@ public class MidnightConfigScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
|
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);
|
this.list.render(context, mouseX, mouseY, delta);
|
||||||
if (tabs.size() < 2) context.drawCenteredString(font, title, width / 2, 10, 0xFFFFFFFF);
|
if (tabs.size() < 2) context.drawCenteredString(font, title, width / 2, 10, 0xFFFFFFFF);
|
||||||
|
//? if < 1.21
|
||||||
|
/*super.render(context, mouseX, mouseY, delta);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
},
|
},
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabric-resource-loader-v0": "*",
|
"fabric-resource-loader-v0": "*",
|
||||||
"minecraft": ">=1.21"
|
"minecraft": "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package eu.midnightdust.test;
|
package eu.midnightdust.test;
|
||||||
|
|
||||||
|
//? if >= 1.21.10 {
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import eu.midnightdust.lib.config.EntryInfo;
|
import eu.midnightdust.lib.config.EntryInfo;
|
||||||
@@ -97,3 +98,4 @@ public class MidnightLibExtras {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//?}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package eu.midnightdust.test.config;
|
package eu.midnightdust.test.config;
|
||||||
|
|
||||||
|
//? if >= 1.21.10 {
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import eu.midnightdust.lib.config.MidnightConfigListWidget;
|
import eu.midnightdust.lib.config.MidnightConfigListWidget;
|
||||||
import eu.midnightdust.lib.config.MidnightConfigScreen;
|
import eu.midnightdust.lib.config.MidnightConfigScreen;
|
||||||
@@ -169,5 +170,5 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
MidnightLibExtras.KeybindButton.add(Minecraft.getInstance().options.keyDrop, list, screen);
|
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 |
Reference in New Issue
Block a user