3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 09:00:09 +01:00

Store attribute mappings in full

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-08-16 13:50:53 +02:00
Ursprung 16e32a62e5
Commit c150e50636
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
3 geänderte Dateien mit 32 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -126,10 +126,10 @@ public interface MappingData {
@Nullable Mappings getEnchantmentMappings(); @Nullable Mappings getEnchantmentMappings();
@Nullable Mappings getAttributeMappings();
@Nullable Mappings getPaintingMappings(); @Nullable Mappings getPaintingMappings();
@Nullable FullMappings getAttributeMappings();
@Nullable FullMappings getEntityMappings(); @Nullable FullMappings getEntityMappings();
@Nullable FullMappings getArgumentTypeMappings(); @Nullable FullMappings getArgumentTypeMappings();

Datei anzeigen

@ -43,10 +43,10 @@ public class MappingDataBase implements MappingData {
protected FullMappings entityMappings; protected FullMappings entityMappings;
protected FullMappings recipeSerializerMappings; protected FullMappings recipeSerializerMappings;
protected FullMappings itemDataSerializerMappings; protected FullMappings itemDataSerializerMappings;
protected FullMappings attributeMappings;
protected ParticleMappings particleMappings; protected ParticleMappings particleMappings;
protected BiMappings itemMappings; protected BiMappings itemMappings;
protected BiMappings blockMappings; protected BiMappings blockMappings;
protected BiMappings attributeMappings;
protected Mappings blockStateMappings; protected Mappings blockStateMappings;
protected Mappings blockEntityMappings; protected Mappings blockEntityMappings;
protected Mappings soundMappings; protected Mappings soundMappings;
@ -76,8 +76,6 @@ public class MappingDataBase implements MappingData {
menuMappings = loadMappings(data, "menus"); menuMappings = loadMappings(data, "menus");
enchantmentMappings = loadMappings(data, "enchantments"); enchantmentMappings = loadMappings(data, "enchantments");
paintingMappings = loadMappings(data, "paintings"); paintingMappings = loadMappings(data, "paintings");
attributeMappings = loadBiMappings(data, "attributes");
final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt"); final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt");
final CompoundTag mappedIdentifierData = readMappedIdentifiersFile("identifiers-" + mappedVersion + ".nbt"); final CompoundTag mappedIdentifierData = readMappedIdentifiersFile("identifiers-" + mappedVersion + ".nbt");
@ -87,6 +85,7 @@ public class MappingDataBase implements MappingData {
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes"); argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers"); recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type"); itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
attributeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "attributes");
final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles"); final List<String> unmappedParticles = identifiersFromGlobalIds(unmappedIdentifierData, "particles");
final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles"); final List<String> mappedParticles = identifiersFromGlobalIds(mappedIdentifierData, "particles");
@ -272,7 +271,7 @@ public class MappingDataBase implements MappingData {
} }
@Override @Override
public @Nullable Mappings getAttributeMappings() { public @Nullable FullMappings getAttributeMappings() {
return attributeMappings; return attributeMappings;
} }

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
@ -37,8 +38,6 @@ import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.TagUtil; import com.viaversion.viaversion.util.TagUtil;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public final class EntityPacketRewriter1_21_2 extends EntityRewriter<ClientboundPacket1_21, Protocol1_21To1_21_2> { public final class EntityPacketRewriter1_21_2 extends EntityRewriter<ClientboundPacket1_21, Protocol1_21To1_21_2> {
@ -56,17 +55,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY); RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY);
if (registryKey.equals("enchantment")) { if (registryKey.equals("enchantment")) {
for (final RegistryEntry entry : entries) { updateEnchantmentAttributes(entries, protocol.getMappingData().getAttributeMappings());
if (entry.tag() == null) {
continue;
}
final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects");
if (effects != null) {
updateLocationChangedAttributes(effects);
updateAttributesFields(effects);
}
}
} else if (registryKey.equals("damage_type")) { } else if (registryKey.equals("damage_type")) {
// Add new damage types // Add new damage types
final int length = entries.length; final int length = entries.length;
@ -153,18 +142,32 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
protocol.appendServerbound(ServerboundPackets1_21_2.MOVE_PLAYER_STATUS_ONLY, this::readOnGround); protocol.appendServerbound(ServerboundPackets1_21_2.MOVE_PLAYER_STATUS_ONLY, this::readOnGround);
} }
private void updateAttributesFields(final CompoundTag effects) { public static void updateEnchantmentAttributes(final RegistryEntry[] entries, final FullMappings mappings) {
for (final RegistryEntry entry : entries) {
if (entry.tag() == null) {
continue;
}
final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects");
if (effects != null) {
updateLocationChangedAttributes(effects, mappings);
updateAttributesFields(effects, mappings);
}
}
}
private static void updateAttributesFields(final CompoundTag effects, final FullMappings mappings) {
final ListTag<CompoundTag> attributesList = TagUtil.getNamespacedCompoundTagList(effects, "attributes"); final ListTag<CompoundTag> attributesList = TagUtil.getNamespacedCompoundTagList(effects, "attributes");
if (attributesList == null) { if (attributesList == null) {
return; return;
} }
for (final CompoundTag attributeData : attributesList) { for (final CompoundTag attributeData : attributesList) {
updateAttributeField(attributeData); updateAttributeField(attributeData, mappings);
} }
} }
private void updateLocationChangedAttributes(final CompoundTag effects) { private static void updateLocationChangedAttributes(final CompoundTag effects, final FullMappings mappings) {
final ListTag<CompoundTag> locationChanged = TagUtil.getNamespacedCompoundTagList(effects, "location_changed"); final ListTag<CompoundTag> locationChanged = TagUtil.getNamespacedCompoundTagList(effects, "location_changed");
if (locationChanged == null) { if (locationChanged == null) {
return; return;
@ -173,28 +176,23 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
for (final CompoundTag data : locationChanged) { for (final CompoundTag data : locationChanged) {
final CompoundTag effect = data.getCompoundTag("effect"); final CompoundTag effect = data.getCompoundTag("effect");
if (effect != null) { if (effect != null) {
updateAttributeField(effect); updateAttributeField(effect, mappings);
} }
} }
} }
private void updateAttributeField(final CompoundTag attributeData) { private static void updateAttributeField(final CompoundTag attributeData, final FullMappings mappings) {
final StringTag attributeTag = attributeData.getStringTag("attribute"); final StringTag attributeTag = attributeData.getStringTag("attribute");
if (attributeTag == null) { if (attributeTag == null) {
return; return;
} }
final String attribute = Key.stripMinecraftNamespace(attributeTag.getValue()); final String attribute = Key.stripMinecraftNamespace(attributeTag.getValue());
final int firstSeparator = attribute.indexOf('.'); String mappedAttribute = mappings.mappedIdentifier(attribute);
if (firstSeparator == -1) { if (mappedAttribute == null) {
return; mappedAttribute = mappings.mappedIdentifier(0); // Dummy
}
// Remove prefix from attributes
final String prefix = attribute.substring(0, firstSeparator);
if (prefix.equals("generic") || prefix.equals("player") || prefix.equals("zombie")) {
attributeTag.setValue(attribute.substring(firstSeparator + 1));
} }
attributeTag.setValue(mappedAttribute);
} }
private void readOnGround(final PacketWrapper wrapper) { private void readOnGround(final PacketWrapper wrapper) {
@ -215,9 +213,9 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
Types1_21_2.ENTITY_DATA_TYPES.componentType, Types1_21_2.ENTITY_DATA_TYPES.componentType,
Types1_21_2.ENTITY_DATA_TYPES.optionalComponentType Types1_21_2.ENTITY_DATA_TYPES.optionalComponentType
); );
registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); // Data type registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_20_5.SALMON).addIndex(17); filter().type(EntityTypes1_20_5.SALMON).addIndex(17); // Data type
} }
@Override @Override