Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-16 04:50:08 +01:00
Handle attribute_modifiers inside container components in 1.21->1.20.5 (#4035)
Closes https://github.com/ViaVersion/ViaVersion/issues/3968
Dieser Commit ist enthalten in:
Ursprung
7f4faab4ab
Commit
35fa7e78a0
@ -34,20 +34,42 @@ public final class ComponentRewriter1_21 extends ComponentRewriter<ClientboundPa
|
||||
super(protocol, ReadType.NBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) {
|
||||
final CompoundTag attributeModifiers = TagUtil.getNamespacedCompoundTag(componentsTag, "minecraft:attribute_modifiers");
|
||||
if (attributeModifiers != null) {
|
||||
final ListTag<CompoundTag> modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class);
|
||||
for (final CompoundTag modifier : modifiers) {
|
||||
final String name = modifier.getString("name");
|
||||
final UUID uuid = UUIDUtil.fromIntArray(modifier.getIntArrayTag("uuid").getValue());
|
||||
final String id = Protocol1_20_5To1_21.mapAttributeUUID(uuid, name);
|
||||
modifier.putString("id", id);
|
||||
private void convertAttributeModifiersComponent(final CompoundTag tag) {
|
||||
final CompoundTag attributeModifiers = TagUtil.getNamespacedCompoundTag(tag, "minecraft:attribute_modifiers");
|
||||
if (attributeModifiers == null) {
|
||||
return;
|
||||
}
|
||||
final ListTag<CompoundTag> modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class);
|
||||
for (final CompoundTag modifier : modifiers) {
|
||||
final String name = modifier.getString("name");
|
||||
final UUID uuid = UUIDUtil.fromIntArray(modifier.getIntArrayTag("uuid").getValue());
|
||||
final String id = Protocol1_20_5To1_21.mapAttributeUUID(uuid, name);
|
||||
modifier.putString("id", id);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleContainerComponent(final CompoundTag tag) {
|
||||
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, "minecraft:container");
|
||||
if (container == null) {
|
||||
return;
|
||||
}
|
||||
for (final CompoundTag entryTag : container) {
|
||||
final CompoundTag itemTag = entryTag.getCompoundTag("item");
|
||||
|
||||
final CompoundTag componentsTag = itemTag.getCompoundTag("components");
|
||||
if (componentsTag != null) {
|
||||
convertAttributeModifiersComponent(componentsTag);
|
||||
handleContainerComponent(componentsTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) {
|
||||
convertAttributeModifiersComponent(componentsTag);
|
||||
handleContainerComponent(componentsTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SerializerVersion inputSerializerVersion() {
|
||||
return SerializerVersion.V1_20_5;
|
||||
|
@ -64,6 +64,11 @@ public final class TagUtil {
|
||||
return compoundTag != null ? compoundTag : tag.getCompoundTag(Key.stripMinecraftNamespace(key));
|
||||
}
|
||||
|
||||
public static @Nullable ListTag<CompoundTag> getNamespacedCompoundTagList(final CompoundTag tag, final String key) {
|
||||
final ListTag<CompoundTag> listTag = tag.getListTag(Key.namespaced(key), CompoundTag.class);
|
||||
return listTag != null ? listTag : tag.getListTag(Key.stripMinecraftNamespace(key), 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