3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Fix identifier handling and validation (#3498)

Dieser Commit ist enthalten in:
RK_01 2023-10-23 23:58:43 +00:00 committet von GitHub
Ursprung 7cf008bb62
Commit 68a32ed2f0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
14 geänderte Dateien mit 187 neuen und 182 gelöschten Zeilen

Datei anzeigen

@ -35,14 +35,24 @@ public final class Key {
public static String stripMinecraftNamespace(final String identifier) { public static String stripMinecraftNamespace(final String identifier) {
if (identifier.startsWith("minecraft:")) { if (identifier.startsWith("minecraft:")) {
return identifier.substring(10); return identifier.substring(10);
} else if (identifier.startsWith(":")) {
return identifier.substring(1);
} }
return identifier; return identifier;
} }
public static String namespaced(final String identifier) { public static String namespaced(final String identifier) {
if (identifier.indexOf(':') == -1) { final int index = identifier.indexOf(':');
if (index == -1) {
return "minecraft:" + identifier; return "minecraft:" + identifier;
} else if (index == 0) {
return "minecraft" + identifier;
} }
return identifier; return identifier;
} }
public static boolean isValid(final String identifier) {
return identifier.matches("([0-9a-z_.-]*:)?[0-9a-z_/.-]*");
}
} }

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_11to1_10;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.util.Key;
public class BlockEntityRewriter { public class BlockEntityRewriter {
private static BiMap<String, String> oldToNewNames = HashBiMap.create(); private static BiMap<String, String> oldToNewNames = HashBiMap.create();
@ -51,7 +52,7 @@ public class BlockEntityRewriter {
} }
private static void rewrite(String oldName, String newName) { private static void rewrite(String oldName, String newName) {
oldToNewNames.put(oldName, "minecraft:" + newName); oldToNewNames.put(oldName, Key.namespaced(newName));
} }
public static BiMap<String, String> inverse() { public static BiMap<String, String> inverse() {

Datei anzeigen

@ -23,86 +23,91 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.util.Key;
public class EntityIdRewriter { public class EntityIdRewriter {
private static final BiMap<String, String> oldToNewNames = HashBiMap.create(); private static final BiMap<String, String> oldToNewNames = HashBiMap.create();
static { static {
oldToNewNames.put("AreaEffectCloud", "minecraft:area_effect_cloud"); rewrite("AreaEffectCloud", "area_effect_cloud");
oldToNewNames.put("ArmorStand", "minecraft:armor_stand"); rewrite("ArmorStand", "armor_stand");
oldToNewNames.put("Arrow", "minecraft:arrow"); rewrite("Arrow", "arrow");
oldToNewNames.put("Bat", "minecraft:bat"); rewrite("Bat", "bat");
oldToNewNames.put("Blaze", "minecraft:blaze"); rewrite("Blaze", "blaze");
oldToNewNames.put("Boat", "minecraft:boat"); rewrite("Boat", "boat");
oldToNewNames.put("CaveSpider", "minecraft:cave_spider"); rewrite("CaveSpider", "cave_spider");
oldToNewNames.put("Chicken", "minecraft:chicken"); rewrite("Chicken", "chicken");
oldToNewNames.put("Cow", "minecraft:cow"); rewrite("Cow", "cow");
oldToNewNames.put("Creeper", "minecraft:creeper"); rewrite("Creeper", "creeper");
oldToNewNames.put("Donkey", "minecraft:donkey"); rewrite("Donkey", "donkey");
oldToNewNames.put("DragonFireball", "minecraft:dragon_fireball"); rewrite("DragonFireball", "dragon_fireball");
oldToNewNames.put("ElderGuardian", "minecraft:elder_guardian"); rewrite("ElderGuardian", "elder_guardian");
oldToNewNames.put("EnderCrystal", "minecraft:ender_crystal"); rewrite("EnderCrystal", "ender_crystal");
oldToNewNames.put("EnderDragon", "minecraft:ender_dragon"); rewrite("EnderDragon", "ender_dragon");
oldToNewNames.put("Enderman", "minecraft:enderman"); rewrite("Enderman", "enderman");
oldToNewNames.put("Endermite", "minecraft:endermite"); rewrite("Endermite", "endermite");
oldToNewNames.put("EntityHorse", "minecraft:horse"); rewrite("EntityHorse", "horse");
oldToNewNames.put("EyeOfEnderSignal", "minecraft:eye_of_ender_signal"); rewrite("EyeOfEnderSignal", "eye_of_ender_signal");
oldToNewNames.put("FallingSand", "minecraft:falling_block"); rewrite("FallingSand", "falling_block");
oldToNewNames.put("Fireball", "minecraft:fireball"); rewrite("Fireball", "fireball");
oldToNewNames.put("FireworksRocketEntity", "minecraft:fireworks_rocket"); rewrite("FireworksRocketEntity", "fireworks_rocket");
oldToNewNames.put("Ghast", "minecraft:ghast"); rewrite("Ghast", "ghast");
oldToNewNames.put("Giant", "minecraft:giant"); rewrite("Giant", "giant");
oldToNewNames.put("Guardian", "minecraft:guardian"); rewrite("Guardian", "guardian");
oldToNewNames.put("Husk", "minecraft:husk"); rewrite("Husk", "husk");
oldToNewNames.put("Item", "minecraft:item"); rewrite("Item", "item");
oldToNewNames.put("ItemFrame", "minecraft:item_frame"); rewrite("ItemFrame", "item_frame");
oldToNewNames.put("LavaSlime", "minecraft:magma_cube"); rewrite("LavaSlime", "magma_cube");
oldToNewNames.put("LeashKnot", "minecraft:leash_knot"); rewrite("LeashKnot", "leash_knot");
oldToNewNames.put("MinecartChest", "minecraft:chest_minecart"); rewrite("MinecartChest", "chest_minecart");
oldToNewNames.put("MinecartCommandBlock", "minecraft:commandblock_minecart"); rewrite("MinecartCommandBlock", "commandblock_minecart");
oldToNewNames.put("MinecartFurnace", "minecraft:furnace_minecart"); rewrite("MinecartFurnace", "furnace_minecart");
oldToNewNames.put("MinecartHopper", "minecraft:hopper_minecart"); rewrite("MinecartHopper", "hopper_minecart");
oldToNewNames.put("MinecartRideable", "minecraft:minecart"); rewrite("MinecartRideable", "minecart");
oldToNewNames.put("MinecartSpawner", "minecraft:spawner_minecart"); rewrite("MinecartSpawner", "spawner_minecart");
oldToNewNames.put("MinecartTNT", "minecraft:tnt_minecart"); rewrite("MinecartTNT", "tnt_minecart");
oldToNewNames.put("Mule", "minecraft:mule"); rewrite("Mule", "mule");
oldToNewNames.put("MushroomCow", "minecraft:mooshroom"); rewrite("MushroomCow", "mooshroom");
oldToNewNames.put("Ozelot", "minecraft:ocelot"); rewrite("Ozelot", "ocelot");
oldToNewNames.put("Painting", "minecraft:painting"); rewrite("Painting", "painting");
oldToNewNames.put("Pig", "minecraft:pig"); rewrite("Pig", "pig");
oldToNewNames.put("PigZombie", "minecraft:zombie_pigman"); rewrite("PigZombie", "zombie_pigman");
oldToNewNames.put("PolarBear", "minecraft:polar_bear"); rewrite("PolarBear", "polar_bear");
oldToNewNames.put("PrimedTnt", "minecraft:tnt"); rewrite("PrimedTnt", "tnt");
oldToNewNames.put("Rabbit", "minecraft:rabbit"); rewrite("Rabbit", "rabbit");
oldToNewNames.put("Sheep", "minecraft:sheep"); rewrite("Sheep", "sheep");
oldToNewNames.put("Shulker", "minecraft:shulker"); rewrite("Shulker", "shulker");
oldToNewNames.put("ShulkerBullet", "minecraft:shulker_bullet"); rewrite("ShulkerBullet", "shulker_bullet");
oldToNewNames.put("Silverfish", "minecraft:silverfish"); rewrite("Silverfish", "silverfish");
oldToNewNames.put("Skeleton", "minecraft:skeleton"); rewrite("Skeleton", "skeleton");
oldToNewNames.put("SkeletonHorse", "minecraft:skeleton_horse"); rewrite("SkeletonHorse", "skeleton_horse");
oldToNewNames.put("Slime", "minecraft:slime"); rewrite("Slime", "slime");
oldToNewNames.put("SmallFireball", "minecraft:small_fireball"); rewrite("SmallFireball", "small_fireball");
oldToNewNames.put("Snowball", "minecraft:snowball"); rewrite("Snowball", "snowball");
oldToNewNames.put("SnowMan", "minecraft:snowman"); rewrite("SnowMan", "snowman");
oldToNewNames.put("SpectralArrow", "minecraft:spectral_arrow"); rewrite("SpectralArrow", "spectral_arrow");
oldToNewNames.put("Spider", "minecraft:spider"); rewrite("Spider", "spider");
oldToNewNames.put("Squid", "minecraft:squid"); rewrite("Squid", "squid");
oldToNewNames.put("Stray", "minecraft:stray"); rewrite("Stray", "stray");
oldToNewNames.put("ThrownEgg", "minecraft:egg"); rewrite("ThrownEgg", "egg");
oldToNewNames.put("ThrownEnderpearl", "minecraft:ender_pearl"); rewrite("ThrownEnderpearl", "ender_pearl");
oldToNewNames.put("ThrownExpBottle", "minecraft:xp_bottle"); rewrite("ThrownExpBottle", "xp_bottle");
oldToNewNames.put("ThrownPotion", "minecraft:potion"); rewrite("ThrownPotion", "potion");
oldToNewNames.put("Villager", "minecraft:villager"); rewrite("Villager", "villager");
oldToNewNames.put("VillagerGolem", "minecraft:villager_golem"); rewrite("VillagerGolem", "villager_golem");
oldToNewNames.put("Witch", "minecraft:witch"); rewrite("Witch", "witch");
oldToNewNames.put("WitherBoss", "minecraft:wither"); rewrite("WitherBoss", "wither");
oldToNewNames.put("WitherSkeleton", "minecraft:wither_skeleton"); rewrite("WitherSkeleton", "wither_skeleton");
oldToNewNames.put("WitherSkull", "minecraft:wither_skull"); rewrite("WitherSkull", "wither_skull");
oldToNewNames.put("Wolf", "minecraft:wolf"); rewrite("Wolf", "wolf");
oldToNewNames.put("XPOrb", "minecraft:xp_orb"); rewrite("XPOrb", "xp_orb");
oldToNewNames.put("Zombie", "minecraft:zombie"); rewrite("Zombie", "zombie");
oldToNewNames.put("ZombieHorse", "minecraft:zombie_horse"); rewrite("ZombieHorse", "zombie_horse");
oldToNewNames.put("ZombieVillager", "minecraft:zombie_villager"); rewrite("ZombieVillager", "zombie_villager");
}
private static void rewrite(String oldName, String newName) {
oldToNewNames.put(oldName, Key.namespaced(newName));
} }
public static void toClient(CompoundTag tag) { public static void toClient(CompoundTag tag) {

Datei anzeigen

@ -25,6 +25,7 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter; import com.viaversion.viaversion.rewriter.RecipeRewriter;
import com.viaversion.viaversion.util.Key;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> { public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> {
@ -88,7 +89,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// First id, then type // First id, then type
wrapper.passthrough(Type.STRING); // Id wrapper.passthrough(Type.STRING); // Id
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", ""); String type = Key.stripMinecraftNamespace(wrapper.passthrough(Type.STRING));
recipeRewriter.handleRecipeType(wrapper, type); recipeRewriter.handleRecipeType(wrapper, type);
} }
}); });

Datei anzeigen

@ -20,8 +20,10 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnection
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockFace; import com.viaversion.viaversion.api.minecraft.BlockFace;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -32,7 +34,7 @@ public class FireConnectionHandler extends ConnectionHandler {
private static void addWoodTypes(Set<String> set, String suffix) { private static void addWoodTypes(Set<String> set, String suffix) {
for (String woodType : WOOD_TYPES) { for (String woodType : WOOD_TYPES) {
set.add("minecraft:" + woodType + suffix); set.add(Key.namespaced(woodType + suffix));
} }
} }

Datei anzeigen

@ -17,6 +17,8 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -59,7 +61,7 @@ public class EntityNameRewriter {
private static void reg(String past, String future) { private static void reg(String past, String future) {
entityNames.put("minecraft:" + past, "minecraft:" + future); entityNames.put(Key.namespaced(past), Key.namespaced(future));
} }
public static String rewrite(String entName) { public static String rewrite(String entName) {
@ -67,7 +69,7 @@ public class EntityNameRewriter {
if (entityName != null) { if (entityName != null) {
return entityName; return entityName;
} }
entityName = entityNames.get("minecraft:" + entName); entityName = entityNames.get(Key.namespaced(entName));
if (entityName != null) { if (entityName != null) {
return entityName; return entityName;
} else } else

Datei anzeigen

@ -28,21 +28,18 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.BiMappings; import com.viaversion.viaversion.api.data.*;
import com.viaversion.viaversion.api.data.Int2IntMapBiMappings;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Int2IntBiHashMap; import com.viaversion.viaversion.util.Int2IntBiHashMap;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
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 MappingData extends MappingDataBase { public class MappingData extends MappingDataBase {
private final Map<String, int[]> blockTags = new HashMap<>(); private final Map<String, int[]> blockTags = new HashMap<>();
@ -86,7 +83,7 @@ public class MappingData extends MappingDataBase {
for (Map.Entry<String, JsonElement> entry : object.entrySet()) { for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
String oldChannel = entry.getKey(); String oldChannel = entry.getKey();
String newChannel = entry.getValue().getAsString(); String newChannel = entry.getValue().getAsString();
if (!isValid1_13Channel(newChannel)) { if (!Key.isValid(newChannel)) {
Via.getPlatform().getLogger().warning("Channel '" + newChannel + "' is not a valid 1.13 plugin channel, please check your configuration!"); Via.getPlatform().getLogger().warning("Channel '" + newChannel + "' is not a valid 1.13 plugin channel, please check your configuration!");
continue; continue;
} }
@ -156,21 +153,11 @@ public class MappingData extends MappingDataBase {
} }
public static String validateNewChannel(String newId) { public static String validateNewChannel(String newId) {
if (!isValid1_13Channel(newId)) { if (!Key.isValid(newId)) {
return null; // Not valid return null; // Not valid
} }
int separatorIndex = newId.indexOf(':');
// Vanilla parses an empty and a missing namespace as the minecraft namespace
if (separatorIndex == -1) {
return "minecraft:" + newId;
} else if (separatorIndex == 0) {
return "minecraft" + newId;
}
return newId;
}
public static boolean isValid1_13Channel(String channelId) { return Key.namespaced(newId);
return channelId.matches("([0-9a-z_.-]+:)?[0-9a-z_/.-]+");
} }
private void loadTags(Map<String, int[]> output, CompoundTag newTags) { private void loadTags(Map<String, int[]> output, CompoundTag newTags) {

Datei anzeigen

@ -19,6 +19,8 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.util.Key;
import java.util.Optional; import java.util.Optional;
public class SpawnEggRewriter { public class SpawnEggRewriter {
@ -27,54 +29,54 @@ public class SpawnEggRewriter {
static { static {
// Class yz.java in 18w14b // Class yz.java in 18w14b
// Register spawn eggs (generated with GT) // Register spawn eggs (generated with GT)
registerSpawnEgg("minecraft:bat"); registerSpawnEgg("bat");
registerSpawnEgg("minecraft:blaze"); registerSpawnEgg("blaze");
registerSpawnEgg("minecraft:cave_spider"); registerSpawnEgg("cave_spider");
registerSpawnEgg("minecraft:chicken"); registerSpawnEgg("chicken");
registerSpawnEgg("minecraft:cow"); registerSpawnEgg("cow");
registerSpawnEgg("minecraft:creeper"); registerSpawnEgg("creeper");
registerSpawnEgg("minecraft:donkey"); registerSpawnEgg("donkey");
registerSpawnEgg("minecraft:elder_guardian"); registerSpawnEgg("elder_guardian");
registerSpawnEgg("minecraft:enderman"); registerSpawnEgg("enderman");
registerSpawnEgg("minecraft:endermite"); registerSpawnEgg("endermite");
registerSpawnEgg("minecraft:evocation_illager"); registerSpawnEgg("evocation_illager");
registerSpawnEgg("minecraft:ghast"); registerSpawnEgg("ghast");
registerSpawnEgg("minecraft:guardian"); registerSpawnEgg("guardian");
registerSpawnEgg("minecraft:horse"); registerSpawnEgg("horse");
registerSpawnEgg("minecraft:husk"); registerSpawnEgg("husk");
registerSpawnEgg("minecraft:llama"); registerSpawnEgg("llama");
registerSpawnEgg("minecraft:magma_cube"); registerSpawnEgg("magma_cube");
registerSpawnEgg("minecraft:mooshroom"); registerSpawnEgg("mooshroom");
registerSpawnEgg("minecraft:mule"); registerSpawnEgg("mule");
registerSpawnEgg("minecraft:ocelot"); registerSpawnEgg("ocelot");
registerSpawnEgg("minecraft:parrot"); registerSpawnEgg("parrot");
registerSpawnEgg("minecraft:pig"); registerSpawnEgg("pig");
registerSpawnEgg("minecraft:polar_bear"); registerSpawnEgg("polar_bear");
registerSpawnEgg("minecraft:rabbit"); registerSpawnEgg("rabbit");
registerSpawnEgg("minecraft:sheep"); registerSpawnEgg("sheep");
registerSpawnEgg("minecraft:shulker"); registerSpawnEgg("shulker");
registerSpawnEgg("minecraft:silverfish"); registerSpawnEgg("silverfish");
registerSpawnEgg("minecraft:skeleton"); registerSpawnEgg("skeleton");
registerSpawnEgg("minecraft:skeleton_horse"); registerSpawnEgg("skeleton_horse");
registerSpawnEgg("minecraft:slime"); registerSpawnEgg("slime");
registerSpawnEgg("minecraft:spider"); registerSpawnEgg("spider");
registerSpawnEgg("minecraft:squid"); registerSpawnEgg("squid");
registerSpawnEgg("minecraft:stray"); registerSpawnEgg("stray");
registerSpawnEgg("minecraft:vex"); registerSpawnEgg("vex");
registerSpawnEgg("minecraft:villager"); registerSpawnEgg("villager");
registerSpawnEgg("minecraft:vindication_illager"); registerSpawnEgg("vindication_illager");
registerSpawnEgg("minecraft:witch"); registerSpawnEgg("witch");
registerSpawnEgg("minecraft:wither_skeleton"); registerSpawnEgg("wither_skeleton");
registerSpawnEgg("minecraft:wolf"); registerSpawnEgg("wolf");
registerSpawnEgg("minecraft:zombie"); registerSpawnEgg("zombie");
registerSpawnEgg("minecraft:zombie_horse"); registerSpawnEgg("zombie_horse");
registerSpawnEgg("minecraft:zombie_pigman"); registerSpawnEgg("zombie_pigman");
registerSpawnEgg("minecraft:zombie_villager"); registerSpawnEgg("zombie_villager");
} }
private static void registerSpawnEgg(String key) { private static void registerSpawnEgg(String name) {
spawnEggs.put(key, spawnEggs.size()); spawnEggs.put(Key.namespaced(name), spawnEggs.size());
} }
// Make it a non-existing block id // Make it a non-existing block id

Datei anzeigen

@ -18,13 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets; package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets;
import com.github.steveice10.opennbt.conversion.ConverterRegistry; import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.*;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -41,6 +35,8 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SoundSource; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SoundSource;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.util.Key;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -364,7 +360,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
tag.put(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing tag.put(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", ""); String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId)); String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
if (numberConverted != null) { if (numberConverted != null) {
oldId = numberConverted; oldId = numberConverted;
@ -386,7 +382,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
tag.put(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing tag.put(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(old))); // There will be data losing
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", ""); String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId)); String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
if (numberConverted != null) { if (numberConverted != null) {
oldId = numberConverted; oldId = numberConverted;
@ -629,7 +625,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
? ((String) value).replace("minecraft:", "") ? Key.stripMinecraftNamespace((String) value)
: null); : null);
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {
@ -652,7 +648,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
for (Tag oldTag : old) { for (Tag oldTag : old) {
Object value = oldTag.getValue(); Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
? ((String) value).replace("minecraft:", "") ? Key.stripMinecraftNamespace((String) value)
: null); : null);
if (newValues != null) { if (newValues != null) {
for (String newValue : newValues) { for (String newValue : newValues) {

Datei anzeigen

@ -24,6 +24,8 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
@ -32,7 +34,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
@ -44,14 +47,11 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ParticleRew
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PaintingProvider; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PaintingProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13; import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class WorldPackets { public class WorldPackets {
@ -320,7 +320,7 @@ public class WorldPackets {
public void register() { public void register() {
map(Type.STRING); map(Type.STRING);
handler(wrapper -> { handler(wrapper -> {
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", ""); String sound = Key.stripMinecraftNamespace(wrapper.get(Type.STRING, 0));
String newSoundId = NamedSoundRewriter.getNewId(sound); String newSoundId = NamedSoundRewriter.getNewId(sound);
wrapper.set(Type.STRING, 0, newSoundId); wrapper.set(Type.STRING, 0, newSoundId);
}); });
@ -445,7 +445,7 @@ public class WorldPackets {
final Tag idTag = tag.get("id"); final Tag idTag = tag.get("id");
if (idTag instanceof StringTag) { if (idTag instanceof StringTag) {
// No longer block entities // No longer block entities
final String id = ((StringTag) idTag).getValue(); final String id = Key.namespaced(((StringTag) idTag).getValue());
if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) { if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) {
iterator.remove(); iterator.remove();
} }

Datei anzeigen

@ -18,6 +18,8 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers; package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers;
import com.viaversion.viaversion.api.platform.providers.Provider; import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -56,13 +58,10 @@ public class PaintingProvider implements Provider {
} }
private void add(String motive) { private void add(String motive) {
paintings.put("minecraft:" + motive, paintings.size()); paintings.put(Key.namespaced(motive), paintings.size());
} }
public Optional<Integer> getIntByIdentifier(String motive) { public Optional<Integer> getIntByIdentifier(String motive) {
// Handle older versions return Optional.ofNullable(paintings.get(Key.namespaced(motive.toLowerCase(Locale.ROOT))));
if (!motive.startsWith("minecraft:"))
motive = "minecraft:" + motive.toLowerCase(Locale.ROOT);
return Optional.ofNullable(paintings.get(motive));
} }
} }

Datei anzeigen

@ -20,7 +20,9 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Pair;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -66,7 +68,7 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler
// Convert item to String without namespace or to Byte // Convert item to String without namespace or to Byte
if (item instanceof String) { if (item instanceof String) {
item = ((String) item).replace("minecraft:", ""); item = Key.stripMinecraftNamespace((String) item);
} else if (item instanceof Number) { } else if (item instanceof Number) {
item = ((Number) item).byteValue(); item = ((Number) item).byteValue();
} else { } else {

Datei anzeigen

@ -17,13 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets; package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.*;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers; import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
@ -38,6 +32,8 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.util.Key;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
@ -242,8 +238,8 @@ public class EntityPackets {
String key = wrapper.read(Type.STRING); String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key); String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
if (attributeIdentifier == null) { if (attributeIdentifier == null) {
attributeIdentifier = "minecraft:" + key; attributeIdentifier = Key.namespaced(key);
if (!com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) { if (!Key.isValid(attributeIdentifier)) {
if (!Via.getConfig().isSuppressConversionWarnings()) { if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Invalid attribute: " + key); Via.getPlatform().getLogger().warning("Invalid attribute: " + key);
} }

Datei anzeigen

@ -22,8 +22,10 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -177,7 +179,7 @@ public class ItemRewriter {
int data = 0; int data = 0;
if (tag != null && tag.get("Potion") instanceof StringTag) { if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion"); StringTag potion = tag.get("Potion");
String potionName = potion.getValue().replace("minecraft:", ""); String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) { if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName); data = POTION_NAME_TO_ID.get(potionName);
} }
@ -193,7 +195,7 @@ public class ItemRewriter {
item.setIdentifier(373); // Potion item.setIdentifier(373); // Potion
if (tag != null && tag.get("Potion") instanceof StringTag) { if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion"); StringTag potion = tag.get("Potion");
String potionName = potion.getValue().replace("minecraft:", ""); String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) { if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName) + 8192; data = POTION_NAME_TO_ID.get(potionName) + 8192;
} }
@ -275,7 +277,7 @@ public class ItemRewriter {
item.setData((short) (item.data() - 8192)); item.setData((short) (item.data() - 8192));
} }
String name = potionNameFromDamage(item.data()); String name = potionNameFromDamage(item.data());
StringTag potion = new StringTag("minecraft:" + name); StringTag potion = new StringTag(Key.namespaced(name));
tag.put("Potion", potion); tag.put("Potion", potion);
item.setTag(tag); item.setTag(tag);
item.setData((short) 0); item.setData((short) 0);