From f1b92fea8d59ffdf7b32ac6213de78c72b5d1238 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 5 May 2024 14:41:30 +0200 Subject: [PATCH] Move loadFullMappings to MappingDataBase, use loadMiMappings --- .../viaversion/api/data/MappingDataBase.java | 15 +++++++++++++-- .../viaversion/api/data/MappingDataLoader.java | 16 ---------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java index 3206c8d28..7dd457998 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java @@ -132,8 +132,19 @@ public class MappingDataBase implements MappingData { return MappingDataLoader.INSTANCE.loadMappings(data, key); } - protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) { - return MappingDataLoader.INSTANCE.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key); + protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) { + if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) { + return null; + } + + final List unmappedIdentifiers = identifiersFromGlobalIds(unmappedIdentifiersTag, key); + final List mappedIdentifiers = identifiersFromGlobalIds(mappedIdentifiersTag, key); + Mappings mappings = loadBiMappings(data, key); // Load as bi-mappings to keep the inverse cached + if (mappings == null) { + mappings = new IdentityMappings(unmappedIdentifiers.size(), mappedIdentifiers.size()); + } + + return new FullMappingsBase(unmappedIdentifiers, mappedIdentifiers, mappings); } protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java index 18edebf5d..75ee0a1fc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataLoader.java @@ -53,7 +53,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; public class MappingDataLoader { @@ -276,21 +275,6 @@ public class MappingDataLoader { return mappingsSupplier.create(mappings, mappedSizeTag.asInt()); } - public FullMappings loadFullMappings(final CompoundTag mappingsTag, final CompoundTag unmappedIdentifiersTag, final CompoundTag mappedIdentifiersTag, final String key) { - if (!unmappedIdentifiersTag.contains(key) || !mappedIdentifiersTag.contains(key)) { - return null; - } - - final List unmappedIdentifiers = identifiersFromGlobalIds(unmappedIdentifiersTag, key); - final List mappedIdentifiers = identifiersFromGlobalIds(mappedIdentifiersTag, key); - Mappings mappings = loadMappings(mappingsTag, key); - if (mappings == null) { - mappings = new IdentityMappings(unmappedIdentifiers.size(), mappedIdentifiers.size()); - } - - return new FullMappingsBase(unmappedIdentifiers, mappedIdentifiers, mappings); - } - public @Nullable List identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) { final Mappings mappings = loadMappings(mappingsTag, key); if (mappings == null) {