From fc0cf1d6a9e983e1d40180a388b7be48fbdf6bed Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Wed, 24 Jul 2024 09:19:50 -0500 Subject: [PATCH 1/4] Backport 1.21 features --- .../ftblibrary/config/StringMapValue.java | 39 +++++++++++++++++++ .../ftblibrary/util/TextComponentUtils.java | 12 ++++++ .../util/client/ClientTextComponentUtils.java | 14 +++++++ .../assets/ftblibrary/lang/en_us.json | 7 +++- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/dev/ftb/mods/ftblibrary/config/StringMapValue.java diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/config/StringMapValue.java b/common/src/main/java/dev/ftb/mods/ftblibrary/config/StringMapValue.java new file mode 100644 index 00000000..75400969 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/config/StringMapValue.java @@ -0,0 +1,39 @@ +package dev.ftb.mods.ftblibrary.config; + +import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; +import dev.ftb.mods.ftblibrary.snbt.config.BaseValue; +import dev.ftb.mods.ftblibrary.snbt.config.SNBTConfig; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public class StringMapValue extends BaseValue> { + public StringMapValue(@Nullable SNBTConfig c, String n, Map def) { + super(c, n, def); + super.set(new HashMap<>(def)); + } + + @Override + public void write(SNBTCompoundTag tag) { + Map map = get(); + SNBTCompoundTag mapTag = new SNBTCompoundTag(); + + for (Map.Entry entry : map.entrySet()) { + mapTag.putString(entry.getKey(), entry.getValue()); + } + + tag.put(key, mapTag); + } + + @Override + public void read(SNBTCompoundTag tag) { + Map map = new HashMap<>(); + + for (String key : tag.getAllKeys()) { + map.put(key, tag.getString(key)); + } + + set(map); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/util/TextComponentUtils.java b/common/src/main/java/dev/ftb/mods/ftblibrary/util/TextComponentUtils.java index c5fb858f..9900b21f 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/util/TextComponentUtils.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/util/TextComponentUtils.java @@ -3,6 +3,9 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; public class TextComponentUtils { @ExpectPlatform @@ -15,4 +18,13 @@ public static Component hotkeyTooltip(String txt) { .append(Component.literal(txt).withStyle(ChatFormatting.GRAY)) .append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY)); } + + + public static Component translatedDimension(ResourceKey key) { + return translatedDimension(key.location()); + } + + public static Component translatedDimension(ResourceLocation dimId) { + return Component.translatableWithFallback(dimId.toLanguageKey("dimension"), dimId.toString()); + } } diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/util/client/ClientTextComponentUtils.java b/common/src/main/java/dev/ftb/mods/ftblibrary/util/client/ClientTextComponentUtils.java index 1ecf1554..9121d348 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/util/client/ClientTextComponentUtils.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/util/client/ClientTextComponentUtils.java @@ -4,6 +4,7 @@ import dev.ftb.mods.ftblibrary.util.CustomComponentParser; import dev.ftb.mods.ftblibrary.util.StringUtils; import dev.ftb.mods.ftblibrary.util.TextComponentParser; +import net.minecraft.client.gui.Font; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.*; @@ -11,6 +12,8 @@ import java.util.List; import java.util.function.Function; +import static net.minecraft.network.chat.CommonComponents.ELLIPSIS; + public class ClientTextComponentUtils { private static final Function DEFAULT_STRING_TO_COMPONENT = ClientTextComponentUtils::defaultStringToComponent; @@ -69,4 +72,15 @@ private static Component defaultStringToComponent(String s) { return parse(I18n.get(s)); } + + public static FormattedText ellipsize(Font font, FormattedText text, int maxWidth) { + final int strWidth = font.width(text); + final int ellipsisWidth = font.width(ELLIPSIS); + if (strWidth > maxWidth) { + return ellipsisWidth >= maxWidth ? + font.substrByWidth(text, maxWidth) : + FormattedText.composite(font.substrByWidth(text, maxWidth - ellipsisWidth), ELLIPSIS); + } + return text; + } } diff --git a/common/src/main/resources/assets/ftblibrary/lang/en_us.json b/common/src/main/resources/assets/ftblibrary/lang/en_us.json index b2a28be0..23cf3e44 100644 --- a/common/src/main/resources/assets/ftblibrary/lang/en_us.json +++ b/common/src/main/resources/assets/ftblibrary/lang/en_us.json @@ -92,5 +92,10 @@ "ftblibrary.panel.position.right": "Right", "ftblibrary.panel.position.bottom_left": "Bottom Left", "ftblibrary.panel.position.bottom": "Bottom", - "ftblibrary.panel.position.bottom_right": "Bottom Right" + "ftblibrary.panel.position.bottom_right": "Bottom Right", + "dimension.minecraft.overworld": "Overworld", + "dimension.minecraft.the_nether": "The Nether", + "dimension.minecraft.the_end": "The End", + "dimension.hyperbox.hyperbox": "Hyperbox", + "dimension.ae2.spatial_storage": "AE2 Spatial Storage" } From 4cf6d0bdbc001fa2e6d628acab1e5c89f89bee35 Mon Sep 17 00:00:00 2001 From: TexTrue <3140846162@qq.com> Date: Thu, 25 Jul 2024 18:56:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?chore:=20made=20a=20few=20config-related=20?= =?UTF-8?q?class=20fields=20protected=20=EF=BC=88backport=20from=201.21?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously they were package-private Allows more extensibility by other mods (e.g. quests) --- .../java/dev/ftb/mods/ftblibrary/snbt/config/BaseValue.java | 6 +++--- .../dev/ftb/mods/ftblibrary/snbt/config/StringValue.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/BaseValue.java b/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/BaseValue.java index 57369fcc..49bbef69 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/BaseValue.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/BaseValue.java @@ -18,12 +18,12 @@ public abstract class BaseValue implements Comparable> { public final T defaultValue; private T value; boolean excluded; - BooleanSupplier enabled = SNBTUtils.ALWAYS_TRUE; + protected BooleanSupplier enabled = SNBTUtils.ALWAYS_TRUE; protected int displayOrder = 0; - List comment = new ArrayList<>(0); + protected List comment = new ArrayList<>(0); - public BaseValue(@Nullable SNBTConfig c, String n, T def) { + protected BaseValue(@Nullable SNBTConfig c, String n, T def) { parent = c; key = n; defaultValue = def; diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/StringValue.java b/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/StringValue.java index 2d216e85..a7afe2b7 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/StringValue.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/snbt/config/StringValue.java @@ -10,9 +10,9 @@ import java.util.regex.Pattern; public class StringValue extends BaseValue { - private Pattern pattern; + protected Pattern pattern; - StringValue(SNBTConfig c, String n, String def) { + protected StringValue(SNBTConfig c, String n, String def) { super(c, n, def); } From 10ff9fe91e86426cb2d64e49277b8e20932f573c Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Thu, 25 Jul 2024 12:52:21 +0100 Subject: [PATCH 3/4] build: version -> 2001.2.4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d7049ff7..190ea322 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=ftblibrary archives_base_name=ftb-library maven_group=dev.ftb.mods -mod_version=2001.2.3 +mod_version=2001.2.4 mod_author=FTB Team minecraft_version=1.20.1 architectury_version=9.0.8 From 6ea3d567a9bad8fc93b1e492b1712a45b35973e0 Mon Sep 17 00:00:00 2001 From: TexTrue <3140846162@qq.com> Date: Thu, 25 Jul 2024 23:54:01 +0800 Subject: [PATCH 4/4] backport `ConfigGroup::addList` and add `NetworkHelper` --- .../dev/ftb/mods/ftblibrary/config/ConfigGroup.java | 5 +++++ .../dev/ftb/mods/ftblibrary/util/NetworkHelper.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/config/ConfigGroup.java b/common/src/main/java/dev/ftb/mods/ftblibrary/config/ConfigGroup.java index a1c12973..10818cc8 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/config/ConfigGroup.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/config/ConfigGroup.java @@ -209,6 +209,11 @@ public > ListConfig addList(String id, List< }, Collections.emptyList()); } + public > ListConfig addList(String id, List value, CV type, Consumer> setter, E def) { + type.setDefaultValue(def); + return add(id, new ListConfig<>(type), value, setter, Collections.emptyList()); + } + public EnumConfig addTristate(String id, Tristate value, Consumer setter, Tristate def) { return addEnum(id, value, setter, Tristate.NAME_MAP, def); } diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java b/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java new file mode 100644 index 00000000..65b6f68f --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/util/NetworkHelper.java @@ -0,0 +1,12 @@ +package dev.ftb.mods.ftblibrary.util; + +import dev.architectury.networking.NetworkManager; +import dev.architectury.networking.simple.MessageType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; + +public class NetworkHelper { + public static void sendToAll(MessageType type, MinecraftServer server, FriendlyByteBuf buffer) { + NetworkManager.sendToPlayers(server.getPlayerList().getPlayers(), type.getId(), buffer); + } +}