Java Code Examples for us.myles.ViaVersion.api.data.MappingDataLoader#loadData()

The following examples show how to use us.myles.ViaVersion.api.data.MappingDataLoader#loadData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingData.java    From ViaVersion with MIT License 6 votes vote down vote up
public static void init() {
    Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 mappings...");
    JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.15to1.16.json");
    JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
    JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);

    oldToNewItems.defaultReturnValue(-1);
    blockStateMappings = new Mappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
    blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"));
    MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items"));
    soundMappings = new Mappings(mapping1_15.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), diffmapping.getAsJsonObject("sounds"));

    attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");
    attributeMappings.put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements");
    attributeMappings.put("horse.jumpStrength", "minecraft:horse.jump_strength");
    attributeMappings.put("generic.followRange", "minecraft:generic.follow_range");
    attributeMappings.put("generic.knockbackResistance", "minecraft:generic.knockback_resistance");
    attributeMappings.put("generic.movementSpeed", "minecraft:generic.movement_speed");
    attributeMappings.put("generic.flyingSpeed", "minecraft:generic.flying_speed");
    attributeMappings.put("generic.attackDamage", "minecraft:generic.attack_damage");
    attributeMappings.put("generic.attackKnockback", "minecraft:generic.attack_knockback");
    attributeMappings.put("generic.attackSpeed", "minecraft:generic.attack_speed");
    attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness");
}
 
Example 2
Source File: MappingData.java    From ViaVersion with MIT License 5 votes vote down vote up
public static void init() {
    Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 mappings...");
    JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.14to1.15.json");
    JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
    JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);

    oldToNewItems.defaultReturnValue(-1);
    blockStateMappings = new Mappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
    blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
    MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
    soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
}
 
Example 3
Source File: MappingData.java    From ViaVersion with MIT License 4 votes vote down vote up
public static void init() {
    Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
    JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true);
    JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);

    oldToNewItems.defaultReturnValue(-1);
    blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
    blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
    MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
    soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));

    JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
    Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
    for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
        blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
    }

    JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
    JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
    MappingData.motionBlocking = new IntOpenHashSet(motionBlocking.size(), 1F);
    for (JsonElement blockState : motionBlocking) {
        String key = blockState.getAsString();
        Integer id = blockStateMap.get(key);
        if (id == null) {
            Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
        } else {
            MappingData.motionBlocking.add(id.intValue());
        }
    }

    if (Via.getConfig().isNonFullBlockLightFix()) {
        nonFullBlocks = new IntOpenHashSet(1611, 1F);
        for (Map.Entry<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
            final String state = blockstates.getValue().getAsString();
            if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
                nonFullBlocks.add(blockStateMappings.getNewId(Integer.parseInt(blockstates.getKey())));
        }
        nonFullBlocks.add(blockStateMappings.getNewId(8163)); // grass path
        for (int i = 3060; i <= 3067; i++) { // farmland
            nonFullBlocks.add(blockStateMappings.getNewId(i));
        }
    }
}
 
Example 4
Source File: MappingData.java    From ViaVersion with MIT License 4 votes vote down vote up
public static void init() {
    Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 mappings...");
    JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json", true);
    JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);

    oldToNewItems.defaultReturnValue(-1);
    blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
    MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
    loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
    loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));
    loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));

    loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
    enchantmentMappings = new Mappings(72, mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
    soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));

    JsonObject object = MappingDataLoader.loadFromDataDir("channelmappings-1.13.json");
    if (object != null) {
        for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
            String oldChannel = entry.getKey();
            String newChannel = entry.getValue().getAsString();
            if (!isValid1_13Channel(newChannel)) {
                Via.getPlatform().getLogger().warning("Channel '" + newChannel + "' is not a valid 1.13 plugin channel, please check your configuration!");
                continue;
            }
            channelMappings.put(oldChannel, newChannel);
        }
    }

    Map<String, String> translateData = GsonUtil.getGson().fromJson(
            new InputStreamReader(MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")),
            new TypeToken<Map<String, String>>() {
            }.getType());
    try {
        String[] lines;
        try (Reader reader = new InputStreamReader(MappingData.class.getClassLoader()
                .getResourceAsStream("mojang-translations/en_US.properties"), StandardCharsets.UTF_8)) {
            lines = CharStreams.toString(reader).split("\n");
        }
        for (String line : lines) {
            if (line.isEmpty()) continue;

            String[] keyAndTranslation = line.split("=", 2);
            if (keyAndTranslation.length != 2) continue;

            String key = keyAndTranslation[0];
            if (!translateData.containsKey(key)) {
                String translation = keyAndTranslation[1].replaceAll("%(\\d\\$)?d", "%$1s");
                mojangTranslation.put(key, translation);
            } else {
                String dataValue = translateData.get(key);
                if (dataValue != null) {
                    translateMapping.put(key, dataValue);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}