3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Fix attribute slot handling

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-22 23:49:13 +02:00
Ursprung f525ad98e7
Commit a4adef3cec
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 62 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,45 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class EquipmentSlots1_20_5 {
public static final KeyMappings SLOTS = new KeyMappings(
"any",
"mainhand",
"offhand",
"hand",
"feet",
"legs",
"chest",
"head",
"armor",
"body"
);
public static @Nullable String idToKey(final int id) {
return SLOTS.idToKey(id);
}
public static int keyToId(final String enchantment) {
return SLOTS.keyToId(enchantment);
}
}

Datei anzeigen

@ -85,6 +85,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attribute
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.DyeColors;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.EquipmentSlots1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instruments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.MapDecorations1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEffects1_20_5;
@ -795,11 +796,16 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final String name = modifierTag.getString("Name");
final NumberTag amountTag = modifierTag.getNumberTag("Amount");
final IntArrayTag uuidTag = modifierTag.getIntArrayTag("UUID");
final int slotType = modifierTag.getInt("Slot");
final String slotType = modifierTag.getString("Slot", "any");
if (name == null || attributeName == null || amountTag == null || uuidTag == null) {
continue;
}
final int slotTypeId = EquipmentSlots1_20_5.keyToId(slotType);
if (slotTypeId == -1) {
continue;
}
final int operationId = modifierTag.getInt("Operation");
if (operationId < 0 || operationId > 2) {
continue;
@ -818,7 +824,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
amountTag.asDouble(),
operationId
),
slotType
slotTypeId
));
}
data.set(StructuredDataKey.ATTRIBUTE_MODIFIERS, new AttributeModifiers(modifiers.toArray(new AttributeModifier[0]), showInTooltip));

Datei anzeigen

@ -76,6 +76,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.DyeColors;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.EquipmentSlots1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEffects1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_5;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
@ -401,12 +402,13 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
if (type == null) {
throw new IllegalArgumentException("Unknown attribute type: " + modifier.attribute());
}
modifierTag.putString("type", type);
convertModifierData(modifierTag, modifier.modifier());
if (modifier.slotType() != 0) {
final StringTag slotTag = convertEnumEntry(modifier.slotType(), "any", "mainhand", "offhand",
"hand", "feet", "legs", "chest", "head", "armor", "body");
modifierTag.put("slot", slotTag);
final String slotType = EquipmentSlots1_20_5.idToKey(modifier.slotType());
Preconditions.checkNotNull(slotType, "Unknown slot type %s", modifier.slotType());
modifierTag.putString("slot", slotType);
}
modifiers.add(modifierTag);

Datei anzeigen

@ -54,6 +54,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.EquipmentSlots1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instruments1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.MapDecorations1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEffects1_20_5;
@ -137,7 +138,9 @@ public final class StructuredDataConverter {
modifierTag.putString("AttributeName", identifier.equals("generic.jump_strength") ? "horse.jump_strength" : identifier);
modifierTag.putString("Name", modifier.modifier().name());
modifierTag.putDouble("Amount", modifier.modifier().amount());
modifierTag.putInt("Slot", modifier.slotType());
if (modifier.slotType() != 0) {
modifierTag.putString("Slot", EquipmentSlots1_20_5.idToKey(modifier.slotType()));
}
modifierTag.putInt("Operation", modifier.modifier().operation());
modifiers.add(modifierTag);
}