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..cb8835dc 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,12 @@ 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 ce7ce758..43184b81 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 @@ -3,6 +3,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.*; @@ -10,6 +11,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; @@ -59,4 +62,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 dbf765af..8d3f7d76 100644 --- a/common/src/main/resources/assets/ftblibrary/lang/en_us.json +++ b/common/src/main/resources/assets/ftblibrary/lang/en_us.json @@ -93,5 +93,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" }