Skip to content

Commit

Permalink
Merge pull request #105 from FTBTeam/1.20.4/dev
Browse files Browse the repository at this point in the history
1.20.4/dev
  • Loading branch information
desht authored Jul 26, 2024
2 parents 01bba51 + b25a28c commit 49af252
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<Map<String, String>> {
public StringMapValue(@Nullable SNBTConfig c, String n, Map<String, String> def) {
super(c, n, def);
super.set(new HashMap<>(def));
}

@Override
public void write(SNBTCompoundTag tag) {
Map<String, String> map = get();
SNBTCompoundTag mapTag = new SNBTCompoundTag();

for (Map.Entry<String, String> entry : map.entrySet()) {
mapTag.putString(entry.getKey(), entry.getValue());
}

tag.put(key, mapTag);
}

@Override
public void read(SNBTCompoundTag tag) {
Map<String, String> map = new HashMap<>();

for (String key : tag.getAllKeys()) {
map.put(key, tag.getString(key));
}

set(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Level> key) {
return translatedDimension(key.location());
}

public static Component translatedDimension(ResourceLocation dimId) {
return Component.translatableWithFallback(dimId.toLanguageKey("dimension"), dimId.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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.*;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static net.minecraft.network.chat.CommonComponents.ELLIPSIS;

public class ClientTextComponentUtils {
private static final Function<String, Component> DEFAULT_STRING_TO_COMPONENT = ClientTextComponentUtils::defaultStringToComponent;

Expand Down Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion common/src/main/resources/assets/ftblibrary/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 49af252

Please sign in to comment.