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) {
if (identifier.startsWith("minecraft:")) {
return identifier.substring(10);
} else if (identifier.startsWith(":")) {
return identifier.substring(1);
}
return identifier;
}
public static String namespaced(final String identifier) {
if (identifier.indexOf(':') == -1) {
final int index = identifier.indexOf(':');
if (index == -1) {
return "minecraft:" + identifier;
} else if (index == 0) {
return "minecraft" + 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.HashBiMap;
import com.viaversion.viaversion.util.Key;
public class BlockEntityRewriter {
private static BiMap<String, String> oldToNewNames = HashBiMap.create();
@ -51,7 +52,7 @@ public class BlockEntityRewriter {
}
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() {

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

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.minecraft.BlockFace;
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.IntSet;
import java.util.HashSet;
import java.util.Set;
@ -32,7 +34,7 @@ public class FireConnectionHandler extends ConnectionHandler {
private static void addWoodTypes(Set<String> set, String suffix) {
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;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap;
import java.util.Map;
@ -59,7 +61,7 @@ public class EntityNameRewriter {
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) {
@ -67,7 +69,7 @@ public class EntityNameRewriter {
if (entityName != null) {
return entityName;
}
entityName = entityNames.get("minecraft:" + entName);
entityName = entityNames.get(Key.namespaced(entName));
if (entityName != null) {
return entityName;
} else

Datei anzeigen

@ -28,21 +28,18 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.BiMappings;
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.api.data.*;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Int2IntBiHashMap;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappingData extends MappingDataBase {
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()) {
String oldChannel = entry.getKey();
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!");
continue;
}
@ -156,21 +153,11 @@ public class MappingData extends MappingDataBase {
}
public static String validateNewChannel(String newId) {
if (!isValid1_13Channel(newId)) {
if (!Key.isValid(newId)) {
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 channelId.matches("([0-9a-z_.-]+:)?[0-9a-z_/.-]+");
return Key.namespaced(newId);
}
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.HashBiMap;
import com.viaversion.viaversion.util.Key;
import java.util.Optional;
public class SpawnEggRewriter {
@ -27,54 +29,54 @@ public class SpawnEggRewriter {
static {
// Class yz.java in 18w14b
// Register spawn eggs (generated with GT)
registerSpawnEgg("minecraft:bat");
registerSpawnEgg("minecraft:blaze");
registerSpawnEgg("minecraft:cave_spider");
registerSpawnEgg("minecraft:chicken");
registerSpawnEgg("minecraft:cow");
registerSpawnEgg("minecraft:creeper");
registerSpawnEgg("minecraft:donkey");
registerSpawnEgg("minecraft:elder_guardian");
registerSpawnEgg("minecraft:enderman");
registerSpawnEgg("minecraft:endermite");
registerSpawnEgg("minecraft:evocation_illager");
registerSpawnEgg("minecraft:ghast");
registerSpawnEgg("minecraft:guardian");
registerSpawnEgg("minecraft:horse");
registerSpawnEgg("minecraft:husk");
registerSpawnEgg("minecraft:llama");
registerSpawnEgg("minecraft:magma_cube");
registerSpawnEgg("minecraft:mooshroom");
registerSpawnEgg("minecraft:mule");
registerSpawnEgg("minecraft:ocelot");
registerSpawnEgg("bat");
registerSpawnEgg("blaze");
registerSpawnEgg("cave_spider");
registerSpawnEgg("chicken");
registerSpawnEgg("cow");
registerSpawnEgg("creeper");
registerSpawnEgg("donkey");
registerSpawnEgg("elder_guardian");
registerSpawnEgg("enderman");
registerSpawnEgg("endermite");
registerSpawnEgg("evocation_illager");
registerSpawnEgg("ghast");
registerSpawnEgg("guardian");
registerSpawnEgg("horse");
registerSpawnEgg("husk");
registerSpawnEgg("llama");
registerSpawnEgg("magma_cube");
registerSpawnEgg("mooshroom");
registerSpawnEgg("mule");
registerSpawnEgg("ocelot");
registerSpawnEgg("minecraft:parrot");
registerSpawnEgg("minecraft:pig");
registerSpawnEgg("minecraft:polar_bear");
registerSpawnEgg("minecraft:rabbit");
registerSpawnEgg("minecraft:sheep");
registerSpawnEgg("minecraft:shulker");
registerSpawnEgg("minecraft:silverfish");
registerSpawnEgg("minecraft:skeleton");
registerSpawnEgg("minecraft:skeleton_horse");
registerSpawnEgg("minecraft:slime");
registerSpawnEgg("minecraft:spider");
registerSpawnEgg("minecraft:squid");
registerSpawnEgg("minecraft:stray");
registerSpawnEgg("minecraft:vex");
registerSpawnEgg("minecraft:villager");
registerSpawnEgg("minecraft:vindication_illager");
registerSpawnEgg("minecraft:witch");
registerSpawnEgg("minecraft:wither_skeleton");
registerSpawnEgg("minecraft:wolf");
registerSpawnEgg("minecraft:zombie");
registerSpawnEgg("minecraft:zombie_horse");
registerSpawnEgg("minecraft:zombie_pigman");
registerSpawnEgg("minecraft:zombie_villager");
registerSpawnEgg("parrot");
registerSpawnEgg("pig");
registerSpawnEgg("polar_bear");
registerSpawnEgg("rabbit");
registerSpawnEgg("sheep");
registerSpawnEgg("shulker");
registerSpawnEgg("silverfish");
registerSpawnEgg("skeleton");
registerSpawnEgg("skeleton_horse");
registerSpawnEgg("slime");
registerSpawnEgg("spider");
registerSpawnEgg("squid");
registerSpawnEgg("stray");
registerSpawnEgg("vex");
registerSpawnEgg("villager");
registerSpawnEgg("vindication_illager");
registerSpawnEgg("witch");
registerSpawnEgg("wither_skeleton");
registerSpawnEgg("wolf");
registerSpawnEgg("zombie");
registerSpawnEgg("zombie_horse");
registerSpawnEgg("zombie_pigman");
registerSpawnEgg("zombie_villager");
}
private static void registerSpawnEgg(String key) {
spawnEggs.put(key, spawnEggs.size());
private static void registerSpawnEgg(String name) {
spawnEggs.put(Key.namespaced(name), spawnEggs.size());
}
// Make it a non-existing block id

Datei anzeigen

@ -18,13 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets;
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
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.github.steveice10.opennbt.tag.builtin.*;
import com.google.common.base.Joiner;
import com.google.common.primitives.Ints;
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.SpawnEggRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.util.Key;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
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
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", "");
String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
if (numberConverted != null) {
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
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String oldId = value.toString().replace("minecraft:", "");
String oldId = Key.stripMinecraftNamespace(value.toString());
String numberConverted = BlockIdData.numberIdToString.get(Ints.tryParse(oldId));
if (numberConverted != null) {
oldId = numberConverted;
@ -629,7 +625,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
? ((String) value).replace("minecraft:", "")
? Key.stripMinecraftNamespace((String) value)
: null);
if (newValues != null) {
for (String newValue : newValues) {
@ -652,7 +648,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
for (Tag oldTag : old) {
Object value = oldTag.getValue();
String[] newValues = BlockIdData.fallbackReverseMapping.get(value instanceof String
? ((String) value).replace("minecraft:", "")
? Key.stripMinecraftNamespace((String) value)
: null);
if (newValues != null) {
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.connection.UserConnection;
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.chunks.Chunk;
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.remapper.PacketHandlers;
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_13to1_12_2.ClientboundPackets1_13;
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.PaintingProvider;
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.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.util.Key;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
public class WorldPackets {
@ -320,7 +320,7 @@ public class WorldPackets {
public void register() {
map(Type.STRING);
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);
wrapper.set(Type.STRING, 0, newSoundId);
});
@ -445,7 +445,7 @@ public class WorldPackets {
final Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
// 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")) {
iterator.remove();
}

Datei anzeigen

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

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.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.Pair;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -66,7 +68,7 @@ public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler
// Convert item to String without namespace or to Byte
if (item instanceof String) {
item = ((String) item).replace("minecraft:", "");
item = Key.stripMinecraftNamespace((String) item);
} else if (item instanceof Number) {
item = ((Number) item).byteValue();
} else {

Datei anzeigen

@ -17,13 +17,7 @@
*/
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.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.github.steveice10.opennbt.tag.builtin.*;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
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.metadata.MetadataRewriter1_16To1_15_2;
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.UUID;
@ -242,8 +238,8 @@ public class EntityPackets {
String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = "minecraft:" + key;
if (!com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.MappingData.isValid1_13Channel(attributeIdentifier)) {
attributeIdentifier = Key.namespaced(key);
if (!Key.isValid(attributeIdentifier)) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
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.Tag;
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.Int2IntOpenHashMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -177,7 +179,7 @@ public class ItemRewriter {
int data = 0;
if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion");
String potionName = potion.getValue().replace("minecraft:", "");
String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName);
}
@ -193,7 +195,7 @@ public class ItemRewriter {
item.setIdentifier(373); // Potion
if (tag != null && tag.get("Potion") instanceof StringTag) {
StringTag potion = tag.get("Potion");
String potionName = potion.getValue().replace("minecraft:", "");
String potionName = Key.stripMinecraftNamespace(potion.getValue());
if (POTION_NAME_TO_ID.containsKey(potionName)) {
data = POTION_NAME_TO_ID.get(potionName) + 8192;
}
@ -275,7 +277,7 @@ public class ItemRewriter {
item.setData((short) (item.data() - 8192));
}
String name = potionNameFromDamage(item.data());
StringTag potion = new StringTag("minecraft:" + name);
StringTag potion = new StringTag(Key.namespaced(name));
tag.put("Potion", potion);
item.setTag(tag);
item.setData((short) 0);