This commit is contained in:
Nassim Jahnke 2023-02-20 17:33:53 +01:00
parent 1b54d10d91
commit fa4cfeb7e9
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
6 changed files with 16 additions and 5 deletions

View File

@ -32,7 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform { public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
public BukkitPlugin() { public BukkitPlugin() {
// MappingDataLoader caching is enabled in ViaVersion on versions that construct the plugin on load // This is the only place we can enable this before ViaVersion is loaded and registers protocols
MappingDataLoader.enableMappingsCache(); MappingDataLoader.enableMappingsCache();
} }

View File

@ -22,7 +22,7 @@ import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.api.ViaBackwardsConfig; import com.viaversion.viabackwards.api.ViaBackwardsConfig;
import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
public class ViaBackwards { public final class ViaBackwards {
private static ViaBackwardsPlatform platform; private static ViaBackwardsPlatform platform;
private static ViaBackwardsConfig config; private static ViaBackwardsConfig config;

View File

@ -82,6 +82,7 @@ public interface ViaBackwardsPlatform {
getLogger().info("Loading translations..."); getLogger().info("Loading translations...");
TranslatableRewriter.loadTranslatables(); TranslatableRewriter.loadTranslatables();
getLogger().info("Registering protocols...");
final ProtocolManager protocolManager = Via.getManager().getProtocolManager(); final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10); protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10);

View File

@ -29,11 +29,12 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public class TranslatableRewriter<C extends ClientboundPacketType> extends ComponentRewriter<C> { public class TranslatableRewriter<C extends ClientboundPacketType> extends ComponentRewriter<C> {
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>(); private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
protected final Map<String, String> newTranslatables; private final Map<String, String> newTranslatables;
public static void loadTranslatables() { public static void loadTranslatables() {
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("translation-mappings.json"); JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("translation-mappings.json");
@ -111,9 +112,13 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
@Override @Override
protected void handleTranslate(JsonObject root, String translate) { protected void handleTranslate(JsonObject root, String translate) {
String newTranslate = newTranslatables.get(translate); String newTranslate = mappedTranslationKey(translate);
if (newTranslate != null) { if (newTranslate != null) {
root.addProperty("translate", newTranslate); root.addProperty("translate", newTranslate);
} }
} }
public @Nullable String mappedTranslationKey(final String translationKey) {
return newTranslatables.get(translationKey);
}
} }

View File

@ -64,7 +64,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<ClientboundPackets1_13>(this) { TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<ClientboundPackets1_13>(this) {
@Override @Override
protected void handleTranslate(JsonObject root, String translate) { protected void handleTranslate(JsonObject root, String translate) {
String newTranslate = newTranslatables.get(translate); String newTranslate = mappedTranslationKey(translate);
if (newTranslate != null || (newTranslate = getMappingData().getTranslateMappings().get(translate)) != null) { if (newTranslate != null || (newTranslate = getMappingData().getTranslateMappings().get(translate)) != null) {
root.addProperty("translate", newTranslate); root.addProperty("translate", newTranslate);
} }

View File

@ -130,6 +130,11 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
}); });
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType, Types1_19_3.META_TYPES.optionalComponentType); registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType, Types1_19_3.META_TYPES.optionalComponentType);
filter().filterFamily(Entity1_19_4Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
});
filter().type(Entity1_19_4Types.TEXT_DISPLAY).index(22).handler(((event, meta) -> { filter().type(Entity1_19_4Types.TEXT_DISPLAY).index(22).handler(((event, meta) -> {
// Send as custom display name // Send as custom display name
event.setIndex(2); event.setIndex(2);