feat(minecraft): Support down to Minecraft 1.16.5 and related fixes
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static de.siphalor.tweed5.coat.bridge.api.TweedCoatMappingUtils.translatableComponent;
|
||||
|
||||
@CustomLog
|
||||
public class TweedCoatBridgeTestMod implements ClientModInitializer {
|
||||
public static final String MOD_ID = "tweed5_coat_bridge_testmod";
|
||||
@@ -52,13 +54,25 @@ public class TweedCoatBridgeTestMod implements ClientModInitializer {
|
||||
|
||||
config = configContainerHelper.loadAndUpdateInConfigDirectory(() -> DEFAULT_CONFIG_VALUE);
|
||||
|
||||
KeyBindingHelper.registerKeyBinding(new ScreenKeyBinding(MOD_ID + ".config", 84, KeyMapping.Category.MISC));
|
||||
KeyBindingHelper.registerKeyBinding(new ScreenKeyBinding(
|
||||
MOD_ID + ".config",
|
||||
GLFW.GLFW_KEY_T,
|
||||
//# if MC_VERSION_NUMBER >= 12109
|
||||
KeyMapping.Category.MISC
|
||||
//# else
|
||||
//- "key.categories.misc"
|
||||
//# end
|
||||
));
|
||||
|
||||
log.info("Current config: " + config);
|
||||
}
|
||||
|
||||
private class ScreenKeyBinding extends KeyMapping implements PriorityKeyBinding {
|
||||
//# if MC_VERSION_NUMBER >= 12109
|
||||
public ScreenKeyBinding(String name, int key, Category category) {
|
||||
//# else
|
||||
//- public ScreenKeyBinding(String name, int key, String category) {
|
||||
//# end
|
||||
super(name, key, category);
|
||||
}
|
||||
|
||||
@@ -71,7 +85,7 @@ public class TweedCoatBridgeTestMod implements ClientModInitializer {
|
||||
ConfigScreen configScreen = configCoatBridgeExtension.createConfigScreen(
|
||||
ConfigScreenCreateParams.<TweedCoatBridgeTestModConfig>builder()
|
||||
.translationKeyPrefix(MOD_ID + ".config")
|
||||
.title(Component.translatable(MOD_ID + ".title"))
|
||||
.title(translatableComponent(MOD_ID + ".title"))
|
||||
.rootEntry(configContainer.rootEntry())
|
||||
.currentValue(config)
|
||||
.defaultValue(DEFAULT_CONFIG_VALUE)
|
||||
|
||||
Reference in New Issue
Block a user