feat(minecraft): Support down to Minecraft 1.16.5 and related fixes

This commit is contained in:
2025-11-03 23:50:23 +01:00
parent 6f870ffaab
commit 837f614399
19 changed files with 225 additions and 74 deletions

View File

@@ -2,21 +2,42 @@ package de.siphalor.tweed5.coat.bridge.api;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
//- import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
//- import net.minecraft.network.chat.TextComponent;
//- import net.minecraft.network.chat.TranslatableComponent;
import org.jspecify.annotations.Nullable;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TweedCoatMappingUtils {
public static MutableComponent translatableComponentWithFallback(String translationKey, @Nullable String fallback) {
//# if MC_VERSION_NUMBER >= 11900
return Component.translatableWithFallback(translationKey, fallback == null ? "" : fallback);
// FIXME
//if (I18n.exists(translationKey)) {
// return Component.translatable(translationKey);
//} else if (fallback != null) {
// return Component.literal(fallback);
//} else {
// return Component.empty();
//}
//# else
//- if (I18n.exists(translationKey)) {
//- return new TranslatableComponent(translationKey);
//- } else if (fallback != null) {
//- return new TextComponent(fallback);
//- } else {
//- return new TextComponent("");
//- }
//# end
}
public static MutableComponent translatableComponent(String translationKey, Object... args) {
//# if MC_VERSION_NUMBER >= 11900
return Component.translatable(translationKey, args);
//# else
//- return new TranslatableComponent(translationKey, args);
//# end
}
public static MutableComponent literalComponent(String literal) {
//# if MC_VERSION_NUMBER >= 11900
return Component.literal(literal);
//# else
//- return new TextComponent(literal);
//# end
}
}

View File

@@ -16,6 +16,8 @@ import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static de.siphalor.tweed5.coat.bridge.api.TweedCoatMappingUtils.literalComponent;
@CommonsLog
public class BasicTweedCoatEntryHandler<T extends @Nullable Object> implements ConfigEntryHandler<T> {
protected final ConfigEntry<T> configEntry;
@@ -43,7 +45,7 @@ public class BasicTweedCoatEntryHandler<T extends @Nullable Object> implements C
.flatMap(entryIssues -> entryIssues.issues().stream())
.map(issue -> new Message(
mapLevel(issue.level()),
Component.literal(issue.message())
literalComponent(issue.message())
))
.collect(Collectors.toList());
}
@@ -68,7 +70,7 @@ public class BasicTweedCoatEntryHandler<T extends @Nullable Object> implements C
@Override
public Component asText(T value) {
return Component.literal(Objects.toString(value));
return literalComponent(Objects.toString(value));
}
protected T processSaveValue(T value) {

View File

@@ -12,6 +12,9 @@ import java.util.Collections;
import java.util.Objects;
import java.util.function.Function;
import static de.siphalor.tweed5.coat.bridge.api.TweedCoatMappingUtils.literalComponent;
import static de.siphalor.tweed5.coat.bridge.api.TweedCoatMappingUtils.translatableComponent;
@RequiredArgsConstructor
@CommonsLog
public class ConvertingTweedCoatEntryHandler<T extends @Nullable Object, C> implements ConfigEntryHandler<C> {
@@ -34,7 +37,7 @@ public class ConvertingTweedCoatEntryHandler<T extends @Nullable Object, C> impl
} catch (Exception e) {
return Collections.singletonList(new Message(
Message.Level.ERROR,
Component.translatable(CONVERSION_EXCEPTION_TEXT_KEY, e.getMessage())
translatableComponent(CONVERSION_EXCEPTION_TEXT_KEY, e.getMessage())
));
}
}
@@ -60,6 +63,6 @@ public class ConvertingTweedCoatEntryHandler<T extends @Nullable Object, C> impl
@Override
public Component asText(C value) {
return Component.literal(Objects.toString(value));
return literalComponent(Objects.toString(value));
}
}