Skip to content

Commit

Permalink
Merge pull request #104 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Jul 26, 2024
2 parents 166dbe5 + 5cafcc5 commit 490fa42
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public <E, CV extends ConfigValue<E>> ListConfig<E, CV> addList(String id, List<
}, Collections.emptyList());
}

public <E, CV extends ConfigValue<E>> ListConfig<E, CV> addList(String id, List<E> value, CV type, Consumer<List<E>> setter, E def) {
type.setDefaultValue(def);
return add(id, new ListConfig<>(type), value, setter, Collections.emptyList());
}

public EnumConfig<Tristate> addTristate(String id, Tristate value, Consumer<Tristate> setter, Tristate def) {
return addEnum(id, value, setter, Tristate.NAME_MAP, def);
}
Expand Down
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 @@ -18,12 +18,12 @@ public abstract class BaseValue<T> implements Comparable<BaseValue<T>> {
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<String> comment = new ArrayList<>(0);
protected List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.regex.Pattern;

public class StringValue extends BaseValue<String> {
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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
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,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<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 @@ -4,13 +4,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 @@ -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;
}
}
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 @@ -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"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 490fa42

Please sign in to comment.