stonecutter: cleaner versioned code

This commit is contained in:
Martin Prokoph
2025-11-20 20:09:52 +01:00
parent d78bcb89bb
commit 0cf6dde5ef
6 changed files with 12 additions and 43 deletions

View File

@@ -112,7 +112,6 @@ public class MidnightLib {
/*? if neoforge {*/
/*public static List<LiteralArgumentBuilder<CommandSourceStack>> commands = new ArrayList<>();
public MidnightLib() {

View File

@@ -7,22 +7,17 @@ public class MidnightLibConfig extends MidnightConfig {
//? if fabric {
@Entry public static ConfigButton config_screen_list = PlatformFunctions.isModLoaded("modmenu") ? ConfigButton.MODMENU : ConfigButton.TRUE;
public enum ConfigButton {
TRUE, FALSE, MODMENU
}
public static boolean shouldShowButton() {
return config_screen_list.equals(ConfigButton.TRUE) || (config_screen_list.equals(ConfigButton.MODMENU) && !PlatformFunctions.isModLoaded("modmenu"));
}
//?} else {
/*@Entry public static ConfigButton config_screen_list = ConfigButton.FALSE;
public enum ConfigButton {
TRUE, FALSE
}
public static boolean shouldShowButton() {
return config_screen_list.equals(ConfigButton.TRUE);
}
*///?}
public enum ConfigButton {
TRUE, FALSE /*? if fabric {*/, MODMENU /*?}*/
}
}

View File

@@ -17,7 +17,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
//? if >= 1.21.9 {
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.input.MouseButtonEvent;
//?}
public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry> {
@@ -37,13 +37,7 @@ 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,
//? if >= 1.21 {
Component.translationArg(text)
//?} else {
/*text.copy()
*///?}
, textRenderer).setCentered(centered);
title = new MultiLineTextWidget(12, 0, 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);
@@ -70,13 +64,8 @@ public class ButtonEntry extends ContainerObjectSelectionList.Entry<ButtonEntry>
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(),
*///?}
BuiltInRegistries.ITEM./*? if >= 1.21.4 {*/ getValue /*?} else {*/ /*get*/ /*?}*/(ResourceLocation.tryParse(this.info.tempValue)).getDefaultInstance()
: BuiltInRegistries.BLOCK./*? if >= 1.21.4 {*/ getValue /*?} else {*/ /*get*/ /*?}*/(ResourceLocation.tryParse(this.info.tempValue)).asItem().getDefaultInstance(),
widget.getX() + widget.getWidth() - 18, y + 2);
});
}

View File

@@ -130,13 +130,7 @@ 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)
//? if >= 1.21 {
.isError()
//?} else {
/*.error().isPresent()
*///?}
)) 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(".")) {

View File

@@ -18,19 +18,11 @@ public class MidnightConfigListWidget extends ContainerObjectSelectionList<Butto
public boolean renderHeaderSeparator = true;
public MidnightConfigListWidget(Minecraft client, int width, int height, int y, int itemHeight) {
//? if >= 1.21 {
super(client, width, height, y, itemHeight);
//?} else {
/*super(client, width, height, y, height + y, itemHeight);
*///?}
super(client, width, height, y, /*? if < 1.21 {*/ /*height + y,*/ /*?}*/ itemHeight);
}
@Override
//? if >= 1.21.4 {
public int scrollBarX() {
//?} else {
/*public int getScrollbarPosition() {
*///?}
public int /*? if >= 1.21.4 {*/ scrollBarX() /*?} else {*/ /*getScrollbarPosition()*/ /*?}*/ {
return this.width - 7;
}

View File

@@ -30,7 +30,7 @@ import net.minecraft.client.input.KeyEvent;
//?}
//? if >=1.21 {
import net.minecraft.client.gui.components.SpriteIconButton;
import net.minecraft.client.gui.components.SpriteIconButton;
//?}
public class MidnightConfigScreen extends Screen {
@@ -79,7 +79,7 @@ public class MidnightConfigScreen extends Screen {
updateList();
list.setScrollAmount(0);
}
scrollProgress = /*? < 1.21.4 {*/ /*list.getScrollAmount() *//*?} else {*/ list.scrollAmount() /*?}*/;
scrollProgress = /*? if < 1.21.4 {*/ /*list.getScrollAmount() *//*?} else {*/ list.scrollAmount() /*?}*/;
for (EntryInfo info : MidnightConfig.entries.values())
if (Objects.equals(modid, info.modid)) info.updateFieldValue();
updateButtons();