Skip to content

Commit

Permalink
Merge pull request #762 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jan 27, 2025
2 parents 38fd345 + 753c230 commit fa14764
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2101.1.4]

### Fixed
* Fixed escaped ampersands in messages failing to parse (e.g "This \& That")
* Fixes bug introduced by previous commit (parsing unicode escape sequences; this still works as before)

## [2101.1.3]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import org.apache.commons.lang3.StringEscapeUtils;

import java.util.HashMap;
import java.util.List;
Expand All @@ -33,14 +33,12 @@ public TranslationTable() {
this.map = new HashMap<>();
}

// deprecated StringEscapeUtils, but we don't have Apache Commons Text available to us, so whatever...
@SuppressWarnings("deprecation")
public static TranslationTable fromNBT(CompoundTag tag) {
Map<String, Either<String, List<String>>> map = new HashMap<>();
tag.getAllKeys().forEach(k -> {
switch (tag.get(k)) {
case StringTag str -> map.put(k, Either.left(StringEscapeUtils.unescapeJava(str.getAsString())));
case ListTag list -> map.put(k, Either.right(list.stream().map(tag1 -> StringEscapeUtils.unescapeJava(tag1.getAsString())).toList()));
case StringTag str -> map.put(k, Either.left(str.getAsString()));
case ListTag list -> map.put(k, Either.right(list.stream().map(Tag::getAsString).toList()));
case null, default -> { }
}
});
Expand Down
10 changes: 7 additions & 3 deletions common/src/main/java/dev/ftb/mods/ftbquests/util/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.PlainTextContents;
import org.apache.commons.lang3.text.translate.UnicodeUnescaper;

import java.util.ArrayList;
import java.util.List;

public class TextUtils {
// deprecated in apache commons, but we don't have apache commons text available here
@SuppressWarnings("deprecation")
private static final UnicodeUnescaper UNESCAPER = new UnicodeUnescaper();

/**
* Parse some rich text into a Component. Use vanilla-style raw JSON if applicable, fall back to old-style FTB
* Quests rich text otherwise. (FTB Quests rich text is more concise, raw JSON is much more powerful)
Expand All @@ -25,15 +30,14 @@ public static Component parseRawText(String str, HolderLookup.Provider provider)
if (str2.startsWith("[") && str2.endsWith("]") || str2.startsWith("{") && str2.endsWith("}")) {
// could be JSON raw text, but not for definite...
try {
MutableComponent res = Component.Serializer.fromJson(str2, provider);
MutableComponent res = Component.Serializer.fromJson(UNESCAPER.translate(str2), provider);
if (res != null) {
return res;
}
} catch (JsonParseException ignored) {

}
}
return ClientTextComponentUtils.parse(str);
return ClientTextComponentUtils.parse(UNESCAPER.translate(str));
}

public static List<String> fromListTag(ListTag tag) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ maven_group=dev.ftb.mods
mod_author=FTB Team

# Build time
mod_version=2101.1.3
mod_version=2101.1.4
minecraft_version=1.21.1

# Cross env
Expand Down

0 comments on commit fa14764

Please sign in to comment.