Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Fall back to keys without namespace in registry data
Dieser Commit ist enthalten in:
Ursprung
b221e47eb7
Commit
bff1536529
@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,7 +38,7 @@ public class MappingData extends MappingDataBase {
|
||||
dimensionRegistry = MappingDataLoader.INSTANCE.loadNBTFromFile("dimension-registry-1.16.2.nbt");
|
||||
|
||||
// Data of each dimension
|
||||
final ListTag<CompoundTag> dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> dimensions = TagUtil.getRegistryEntries(dimensionRegistry, "dimension_type");
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
// Copy with an empty name
|
||||
final CompoundTag dimensionData = dimension.getCompoundTag("element").copy();
|
||||
|
@ -34,6 +34,7 @@ import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPac
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
|
||||
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2, Protocol1_17To1_16_4> {
|
||||
|
||||
@ -76,8 +77,8 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_16_2
|
||||
map(Type.NAMED_COMPOUND_TAG); // Current dimension
|
||||
handler(wrapper -> {
|
||||
// Add new dimension fields
|
||||
CompoundTag dimensionRegistry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0).getCompoundTag("minecraft:dimension_type");
|
||||
ListTag<CompoundTag> dimensions = dimensionRegistry.getListTag("value", CompoundTag.class);
|
||||
CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
ListTag<CompoundTag> dimensions = TagUtil.getRegistryEntries(registry, "dimension_type");
|
||||
for (CompoundTag dimension : dimensions) {
|
||||
CompoundTag dimensionCompound = dimension.getCompoundTag("element");
|
||||
addNewDimensionData(dimensionCompound);
|
||||
|
@ -28,10 +28,10 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
|
||||
public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
|
||||
|
||||
|
||||
public Protocol1_18_2To1_18() {
|
||||
super(ClientboundPackets1_18.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
|
||||
}
|
||||
@ -70,8 +70,7 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPack
|
||||
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final CompoundTag dimensionsHolder = registry.getCompoundTag("minecraft:dimension_type");
|
||||
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> dimensions = TagUtil.getRegistryEntries(registry, "dimension_type");
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
addTagPrefix(dimension.getCompoundTag("element"));
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19;
|
||||
import com.viaversion.viaversion.util.CipherUtil;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -189,7 +190,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol<ClientboundPack
|
||||
chatTypeStorage.clear();
|
||||
|
||||
final CompoundTag registry = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
|
||||
final ListTag<CompoundTag> chatTypes = registry.getCompoundTag("minecraft:chat_type").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> chatTypes = TagUtil.getRegistryEntries(registry, "chat_type");
|
||||
for (final CompoundTag chatType : chatTypes) {
|
||||
final NumberTag idTag = chatType.getNumberTag("id");
|
||||
chatTypeStorage.addChatType(idTag.asInt(), chatType);
|
||||
|
@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPac
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage.PlayerVehicleTracker;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
|
||||
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3, Protocol1_19_4To1_19_3> {
|
||||
|
||||
@ -62,8 +63,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
||||
final CompoundTag damageTypeRegistry = protocol.getMappingData().damageTypesRegistry();
|
||||
registry.put("minecraft:damage_type", damageTypeRegistry);
|
||||
|
||||
final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
|
||||
final ListTag<CompoundTag> biomes = biomeRegistry.getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome");
|
||||
for (final CompoundTag biomeTag : biomes) {
|
||||
final CompoundTag biomeData = biomeTag.getCompoundTag("element");
|
||||
final StringTag precipitation = biomeData.getStringTag("precipitation");
|
||||
|
@ -44,6 +44,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.Dimensio
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@ -178,7 +179,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
|
||||
tag.put("minecraft:chat_type", protocol.getMappingData().chatRegistry());
|
||||
|
||||
// Cache a whole lot of data
|
||||
final ListTag<CompoundTag> dimensions = tag.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> dimensions = TagUtil.getRegistryEntries(tag, "dimension_type");
|
||||
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
|
||||
final Map<CompoundTag, String> dimensionsMap = new HashMap<>(dimensions.size());
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
|
@ -44,6 +44,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Clientb
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.storage.AcknowledgedMessagesStorage;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -75,7 +76,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
trackBiomeSize(wrapper.user(), registryData);
|
||||
|
||||
// Update format of height provider
|
||||
final ListTag<CompoundTag> dimensionTypes = registryData.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> dimensionTypes = TagUtil.getRegistryEntries(registryData, "dimension_type");
|
||||
for (final CompoundTag dimensionType : dimensionTypes) {
|
||||
final CompoundTag elementTag = dimensionType.getCompoundTag("element");
|
||||
final CompoundTag monsterSpawnLightLevel = elementTag.getCompoundTag("monster_spawn_light_level");
|
||||
@ -87,7 +88,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
}
|
||||
|
||||
// Changes in biomes
|
||||
final ListTag<CompoundTag> biomes = registryData.getCompoundTag("minecraft:worldgen/biome").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> biomes = TagUtil.getRegistryEntries(registryData, "worldgen/biome");
|
||||
for (final CompoundTag biome : biomes) {
|
||||
final CompoundTag effects = biome.getCompoundTag("element").getCompoundTag("effects");
|
||||
|
||||
|
@ -33,6 +33,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
|
||||
public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4, Protocol1_20To1_19_4> {
|
||||
|
||||
@ -75,8 +76,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_4
|
||||
handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
handler(wrapper -> {
|
||||
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
||||
final CompoundTag damageTypeRegistry = registry.getCompoundTag("minecraft:damage_type");
|
||||
final ListTag<CompoundTag> damageTypes = damageTypeRegistry.getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> damageTypes = TagUtil.getRegistryEntries(registry, "damage_type");
|
||||
int highestId = -1;
|
||||
for (final CompoundTag damageType : damageTypes) {
|
||||
final IntTag id = damageType.getUnchecked("id");
|
||||
|
@ -48,6 +48,7 @@ import com.viaversion.viaversion.rewriter.meta.MetaFilter;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
|
||||
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEventImpl;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@ -205,9 +206,9 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
/**
|
||||
* Registers a metadata handler to rewrite, item, block, and particle ids stored in metadata.
|
||||
*
|
||||
* @param itemType item meta type if needed
|
||||
* @param blockStateType block state meta type if needed
|
||||
* @param particleType particle meta type if needed
|
||||
* @param itemType item meta type if needed
|
||||
* @param blockStateType block state meta type if needed
|
||||
* @param particleType particle meta type if needed
|
||||
*/
|
||||
public void registerMetaTypeHandler(@Nullable MetaType itemType, @Nullable MetaType blockStateType, @Nullable MetaType particleType) {
|
||||
registerMetaTypeHandler(itemType, null, blockStateType, particleType, null);
|
||||
@ -491,8 +492,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
|
||||
public void trackBiomeSize(final UserConnection connection, final CompoundTag registry) {
|
||||
final CompoundTag biomeRegistry = registry.getCompoundTag("minecraft:worldgen/biome");
|
||||
final ListTag<?> biomes = biomeRegistry.getListTag("value");
|
||||
final ListTag<?> biomes = TagUtil.getRegistryEntries(registry, "worldgen/biome");
|
||||
tracker(connection).setBiomesSent(biomes.size());
|
||||
}
|
||||
|
||||
@ -508,7 +508,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
* Caches dimension data, later used to get height values and other important info.
|
||||
*/
|
||||
public void cacheDimensionData(final UserConnection connection, final CompoundTag registry) {
|
||||
final ListTag<CompoundTag> dimensions = registry.getCompoundTag("minecraft:dimension_type").getListTag("value", CompoundTag.class);
|
||||
final ListTag<CompoundTag> dimensions = TagUtil.getRegistryEntries(registry, "dimension_type");
|
||||
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(dimensions.size());
|
||||
for (final CompoundTag dimension : dimensions) {
|
||||
final NumberTag idTag = dimension.getNumberTag("id");
|
||||
|
@ -21,12 +21,18 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import java.util.Map;
|
||||
import net.lenni0451.mcstructs.snbt.exceptions.SNbtDeserializeException;
|
||||
import net.lenni0451.mcstructs.snbt.exceptions.SNbtSerializeException;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class TagUtil {
|
||||
|
||||
public static ListTag<CompoundTag> getRegistryEntries(final CompoundTag tag, final String key) {
|
||||
CompoundTag registry = tag.getCompoundTag(Key.namespaced(key));
|
||||
if (registry == null) {
|
||||
registry = tag.getCompoundTag(Key.stripMinecraftNamespace(key));
|
||||
}
|
||||
return registry.getListTag("value", CompoundTag.class);
|
||||
}
|
||||
|
||||
public static Tag handleDeep(final Tag tag, final TagUpdater consumer) {
|
||||
return handleDeep(null, tag, consumer);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren