3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Handle 1.21 attribute id changes

Fixes #4005
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-07-19 11:26:28 +02:00
Ursprung 87b041bf3a
Commit 0915afe43b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 12 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -46,6 +46,7 @@ public class MappingDataBase implements MappingData {
protected ParticleMappings particleMappings;
protected BiMappings itemMappings;
protected BiMappings blockMappings;
protected BiMappings attributeMappings;
protected Mappings blockStateMappings;
protected Mappings blockEntityMappings;
protected Mappings soundMappings;
@ -53,7 +54,6 @@ public class MappingDataBase implements MappingData {
protected Mappings enchantmentMappings;
protected Mappings paintingMappings;
protected Mappings menuMappings;
protected Mappings attributeMappings;
protected Map<RegistryType, List<TagData>> tags;
public MappingDataBase(final String unmappedVersion, final String mappedVersion) {
@ -76,7 +76,7 @@ public class MappingDataBase implements MappingData {
menuMappings = loadMappings(data, "menus");
enchantmentMappings = loadMappings(data, "enchantments");
paintingMappings = loadMappings(data, "paintings");
attributeMappings = loadMappings(data, "attributes");
attributeMappings = loadBiMappings(data, "attributes");
final CompoundTag unmappedIdentifierData = readUnmappedIdentifiersFile("identifiers-" + unmappedVersion + ".nbt");

Datei anzeigen

@ -41,6 +41,7 @@ import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_5, Protocol1_20_5To1_21> {
@ -139,9 +140,10 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
dataContainer.replaceKey(StructuredDataKey.BUNDLE_CONTENTS1_20_5, StructuredDataKey.BUNDLE_CONTENTS1_21);
dataContainer.replace(StructuredDataKey.ATTRIBUTE_MODIFIERS1_20_5, StructuredDataKey.ATTRIBUTE_MODIFIERS1_21, attributeModifiers -> {
final AttributeModifiers1_21.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> {
final int mappedAttributeId = Protocol1_20_5To1_21.MAPPINGS.getNewAttributeId(modifier.attribute());
final AttributeModifiers1_20_5.ModifierData modData = modifier.modifier();
final AttributeModifiers1_21.ModifierData updatedModData = new AttributeModifiers1_21.ModifierData(Protocol1_20_5To1_21.mapAttributeUUID(modData.uuid(), modData.name()), modData.amount(), modData.operation());
return new AttributeModifiers1_21.AttributeModifier(modifier.attribute(), updatedModData, modifier.slotType());
return new AttributeModifiers1_21.AttributeModifier(mappedAttributeId, updatedModData, modifier.slotType());
}).toArray(AttributeModifiers1_21.AttributeModifier[]::new);
return new AttributeModifiers1_21(modifiers, attributeModifiers.showInTooltip());
});
@ -168,6 +170,11 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
dataContainer.remove(StructuredDataKey.JUKEBOX_PLAYABLE);
dataContainer.replace(StructuredDataKey.ATTRIBUTE_MODIFIERS1_21, StructuredDataKey.ATTRIBUTE_MODIFIERS1_20_5, attributeModifiers -> {
final AttributeModifiers1_20_5.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> {
final int mappedAttributeId = Protocol1_20_5To1_21.MAPPINGS.getAttributeMappings().inverse().getNewId(modifier.attribute());
if (mappedAttributeId == -1) {
return null;
}
final AttributeModifiers1_21.ModifierData modData = modifier.modifier();
final String name = AttributeModifierMappings1_21.idToName(modData.id());
final AttributeModifiers1_20_5.ModifierData updatedModData = new AttributeModifiers1_20_5.ModifierData(
@ -176,8 +183,8 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
modData.amount(),
modData.operation()
);
return new AttributeModifiers1_20_5.AttributeModifier(modifier.attribute(), updatedModData, modifier.slotType());
}).toArray(AttributeModifiers1_20_5.AttributeModifier[]::new);
return new AttributeModifiers1_20_5.AttributeModifier(mappedAttributeId, updatedModData, modifier.slotType());
}).filter(Objects::nonNull).toArray(AttributeModifiers1_20_5.AttributeModifier[]::new);
return new AttributeModifiers1_20_5(modifiers, attributeModifiers.showInTooltip());
});
}