us.myles.ViaVersion.api.data.MappingDataLoader Java Examples
The following examples show how to use
us.myles.ViaVersion.api.data.MappingDataLoader.
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: ViaFabric.java From ViaFabric with MIT License | 6 votes |
@Override public void onInitialize() { Via.init(ViaManager.builder() .injector(new VRInjector()) .loader(new VRLoader()) .commandHandler(new VRCommandHandler()) .platform(new VRPlatform()).build()); FabricLoader.getInstance().getModContainer("viabackwards").ifPresent(mod -> MappingDataLoader.enableMappingsCache()); Via.getManager().init(); FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion"))); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver"))); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric"))); config = new VRConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric") .resolve("viafabric.yml").toFile()); }
Example #2
Source File: VelocityPlugin.java From ViaVersion with MIT License | 6 votes |
@Subscribe public void onProxyInit(ProxyInitializeEvent e) { PROXY = proxy; VelocityCommandHandler commandHandler = new VelocityCommandHandler(); PROXY.getCommandManager().register(commandHandler, "viaver", "vvvelocity", "viaversion"); api = new VelocityViaAPI(); conf = new VelocityViaConfig(configDir.toFile()); logger = new LoggerWrapper(loggerslf4j); connectionManager = new ViaConnectionManager(); Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .loader(new VelocityViaLoader()) .injector(new VelocityViaInjector()).build()); if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) { MappingDataLoader.enableMappingsCache(); } }
Example #3
Source File: MappingData.java From ViaVersion with MIT License | 6 votes |
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 #4
Source File: BungeePlugin.java From ViaVersion with MIT License | 5 votes |
@Override public void onEnable() { if (ProxyServer.getInstance().getPluginManager().getPlugin("ViaBackwards") != null) { MappingDataLoader.enableMappingsCache(); } // Inject Via.getManager().init(); }
Example #5
Source File: VBItemMappings.java From ViaBackwards with MIT License | 5 votes |
public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) { Map<Integer, MappedItem> itemMapping = new HashMap<>(); for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) { JsonObject object = entry.getValue().getAsJsonObject(); String mappedIdName = object.getAsJsonPrimitive("id").getAsString(); Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newMapping, mappedIdName); if (value == null) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( "); } continue; } Map.Entry<String, JsonElement> oldEntry = MappingDataLoader.findValue(oldMapping, entry.getKey()); if (oldEntry == null) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( "); } continue; } int id = Integer.parseInt(oldEntry.getKey()); int mappedId = Integer.parseInt(value.getKey()); String name = object.getAsJsonPrimitive("name").getAsString(); itemMapping.put(id, new MappedItem(mappedId, name)); } this.itemMapping = new Int2ObjectOpenHashMap<>(itemMapping, 1F); }
Example #6
Source File: VBMappingDataLoader.java From ViaBackwards with MIT License | 5 votes |
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) { int i = -1; for (JsonElement oldIdentifier : oldIdentifiers) { i++; String key = oldIdentifier.getAsString(); Integer index = MappingDataLoader.findIndex(newIdentifiers, key); if (index == null) { // Search in diff mappings if (diffIdentifiers != null) { JsonPrimitive diffValue = diffIdentifiers.getAsJsonPrimitive(key); if (diffValue == null) { if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("No diff key for " + key + " :( "); } continue; } String mappedName = diffValue.getAsString(); if (mappedName.isEmpty()) continue; // "empty" remaps index = MappingDataLoader.findIndex(newIdentifiers, mappedName); } if (index == null) { if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("No key for " + key + " :( "); } continue; } } output[i] = index.shortValue(); } }
Example #7
Source File: VBMappingDataLoader.java From ViaBackwards with MIT License | 5 votes |
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { String key = entry.getValue().getAsString(); Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newIdentifiers, key); if (value == null) { if (diffIdentifiers != null) { // Search in diff mappings JsonPrimitive diffValueJson = diffIdentifiers.getAsJsonPrimitive(key); String diffValue = diffValueJson != null ? diffValueJson.getAsString() : null; int dataIndex; if (diffValue == null && (dataIndex = key.indexOf('[')) != -1 && (diffValueJson = diffIdentifiers.getAsJsonPrimitive(key.substring(0, dataIndex))) != null) { // Check for wildcard mappings diffValue = diffValueJson.getAsString(); // Keep original properties if value ends with [ if (diffValue.endsWith("[")) { diffValue += key.substring(dataIndex + 1); } } if (diffValue != null) { value = MappingDataLoader.findValue(newIdentifiers, diffValue); } } if (value == null) { // Nothing found :( if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } continue; } } output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); } }
Example #8
Source File: BackwardsMappings.java From ViaBackwards with MIT License | 5 votes |
public static void init() { ViaBackwards.getPlatform().getLogger().info("Loading 1.14 -> 1.13.2 mappings..."); JsonObject mapping1_13_2 = MappingDataLoader.getMappingsCache().get("mapping-1.13.2.json"); JsonObject mapping1_14 = MappingDataLoader.getMappingsCache().get("mapping-1.14.json"); JsonObject mapping1_13_2to1_14 = VBMappingDataLoader.loadFromDataDir("mapping-1.13.2to1.14.json"); blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates")); blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false); itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items")); soundMappings = new VBSoundMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds")); }
Example #9
Source File: BackwardsMappings.java From ViaBackwards with MIT License | 5 votes |
public static void init() { ViaBackwards.getPlatform().getLogger().info("Loading 1.15 -> 1.14.4 mappings..."); JsonObject mapping1_14 = MappingDataLoader.getMappingsCache().get("mapping-1.14.json"); JsonObject mapping1_15 = MappingDataLoader.getMappingsCache().get("mapping-1.15.json"); JsonObject mapping1_14to1_15 = VBMappingDataLoader.loadFromDataDir("mapping-1.14.4to1.15.json"); blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates")); blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false); itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items")); soundMappings = new VBSoundMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds")); }
Example #10
Source File: BackwardsMappings.java From ViaBackwards with MIT License | 5 votes |
public static void init() { ViaBackwards.getPlatform().getLogger().info("Loading 1.16 -> 1.15.2 mappings..."); JsonObject mapping1_15 = MappingDataLoader.getMappingsCache().get("mapping-1.15.json"); JsonObject mapping1_16 = MappingDataLoader.getMappingsCache().get("mapping-1.16.json"); JsonObject mapping1_15to1_16 = VBMappingDataLoader.loadFromDataDir("mapping-1.15to1.16.json"); blockStateMappings = new VBMappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), mapping1_15to1_16.getAsJsonObject("blockstates")); blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false); itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items")); soundMappings = new VBSoundMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds")); for (Map.Entry<String, String> entry : MappingData.attributeMappings.entrySet()) { attributeMappings.put(entry.getValue(), entry.getKey()); } }
Example #11
Source File: PistonHandler.java From ViaBackwards with MIT License | 5 votes |
public PistonHandler() { if (Via.getConfig().isServersideBlockConnections()) { Map<String, Integer> keyToId; try { Field field = ConnectionData.class.getDeclaredField("keyToId"); field.setAccessible(true); keyToId = (Map<String, Integer>) field.get(null); } catch (IllegalAccessException | NoSuchFieldException e) { e.printStackTrace(); return; } for (Map.Entry<String, Integer> entry : keyToId.entrySet()) { if (!entry.getKey().contains("piston")) continue; addEntries(entry.getKey(), entry.getValue()); } } else { JsonObject mappings = MappingDataLoader.getMappingsCache().get("mapping-1.13.json").getAsJsonObject("blocks"); for (Map.Entry<String, JsonElement> blockState : mappings.entrySet()) { String key = blockState.getValue().getAsString(); if (!key.contains("piston")) continue; addEntries(key, Integer.parseInt(blockState.getKey())); } } }
Example #12
Source File: BackwardsMappings.java From ViaBackwards with MIT License | 5 votes |
private static void mapIdentifiers(short[] output, JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) { for (Map.Entry<String, JsonElement> entry : newIdentifiers.entrySet()) { String key = entry.getValue().getAsString(); Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(oldIdentifiers, key); short hardId = -1; if (value == null) { JsonPrimitive replacement = mapping.getAsJsonPrimitive(key); int propertyIndex; if (replacement == null && (propertyIndex = key.indexOf('[')) != -1) { replacement = mapping.getAsJsonPrimitive(key.substring(0, propertyIndex)); } if (replacement != null) { if (replacement.getAsString().startsWith("id:")) { String id = replacement.getAsString().replace("id:", ""); hardId = Short.parseShort(id); value = MappingDataLoader.findValue(oldIdentifiers, oldIdentifiers.getAsJsonPrimitive(id).getAsString()); } else { value = MappingDataLoader.findValue(oldIdentifiers, replacement.getAsString()); } } if (value == null) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (replacement != null) { ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + "/" + replacement.getAsString() + " :( "); } else { ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } } continue; } } output[Integer.parseInt(entry.getKey())] = hardId != -1 ? hardId : Short.parseShort(value.getKey()); } }
Example #13
Source File: MappingData.java From ViaVersion with MIT License | 5 votes |
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 #14
Source File: ProtocolRegistry.java From ViaVersion with MIT License | 5 votes |
private static void shutdownLoaderExecutor() { mappingsLoaded = true; mappingLoaderExecutor.shutdown(); mappingLoaderExecutor = null; mappingLoaderFutures.clear(); mappingLoaderFutures = null; if (MappingDataLoader.isCacheJsonMappings()) { MappingDataLoader.getMappingsCache().clear(); } }
Example #15
Source File: SpongePlugin.java From ViaVersion with MIT License | 5 votes |
@Listener public void onServerStart(GameAboutToStartServerEvent event) { if (game.getPluginManager().getPlugin("ViaBackwards").isPresent()) { MappingDataLoader.enableMappingsCache(); } // Inject! logger.info("ViaVersion is injecting!"); Via.getManager().init(); }
Example #16
Source File: MappingData.java From ViaVersion with MIT License | 4 votes |
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(); } }
Example #17
Source File: MappingData.java From ViaVersion with MIT License | 4 votes |
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)); } } }