Search in sources :

Example 1 with Int2ObjectOpenHashMap

use of com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap in project ViaBackwards by ViaVersion.

the class VBMappingDataLoader method loadItemMappings.

public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
    Int2ObjectMap<MappedItem> itemMapping = new Int2ObjectOpenHashMap<>(diffMapping.size(), 0.99F);
    Object2IntMap<String> newIdenfierMap = MappingDataLoader.indexedObjectToMap(newMapping);
    Object2IntMap<String> oldIdenfierMap = MappingDataLoader.indexedObjectToMap(oldMapping);
    for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
        JsonObject object = entry.getValue().getAsJsonObject();
        String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
        int mappedId = newIdenfierMap.getInt(mappedIdName);
        if (mappedId == -1) {
            if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
                ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( ");
            }
            continue;
        }
        int oldId = oldIdenfierMap.getInt(entry.getKey());
        if (oldId == -1) {
            if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
                ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( ");
            }
            continue;
        }
        String name = object.getAsJsonPrimitive("name").getAsString();
        itemMapping.put(oldId, new MappedItem(mappedId, name));
    }
    // Look for missing keys
    if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings()) {
        for (Object2IntMap.Entry<String> entry : oldIdenfierMap.object2IntEntrySet()) {
            if (!newIdenfierMap.containsKey(entry.getKey()) && !itemMapping.containsKey(entry.getIntValue())) {
                ViaBackwards.getPlatform().getLogger().warning("No item mapping for " + entry.getKey() + " :( ");
            }
        }
    }
    return itemMapping;
}
Also used : Int2ObjectOpenHashMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) Object2IntMap(com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) Object2IntMap(com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap) HashMap(java.util.HashMap) Int2ObjectMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap) Map(java.util.Map) Int2ObjectOpenHashMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap)

Aggregations

Int2ObjectMap (com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap)1 Object2IntMap (com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap)1 JsonElement (com.viaversion.viaversion.libs.gson.JsonElement)1 JsonObject (com.viaversion.viaversion.libs.gson.JsonObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1