3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-16 21:10:25 +01:00

Fix holder set direct id conversion in 1.20.3->1.20.5 component rewriter (#4164)

Dieser Commit ist enthalten in:
EnZaXD 2024-10-05 21:34:34 +02:00 committet von GitHub
Ursprung c0821de2e2
Commit 9df1704357
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -396,6 +396,14 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
} }
protected CompoundTag convertCanPlaceOn(final AdventureModePredicate value) { protected CompoundTag convertCanPlaceOn(final AdventureModePredicate value) {
return convertBlockPredicate(value);
}
protected CompoundTag convertCanBreak(final AdventureModePredicate value) {
return convertBlockPredicate(value);
}
protected CompoundTag convertBlockPredicate(final AdventureModePredicate value) {
final CompoundTag tag = new CompoundTag(); final CompoundTag tag = new CompoundTag();
final ListTag<CompoundTag> predicates = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> predicates = new ListTag<>(CompoundTag.class);
for (final BlockPredicate predicate : value.predicates()) { for (final BlockPredicate predicate : value.predicates()) {
@ -404,8 +412,7 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
convertHolderSet(predicateTag, "blocks", predicate.holderSet()); convertHolderSet(predicateTag, "blocks", predicate.holderSet());
} }
if (predicate.propertyMatchers() != null) { if (predicate.propertyMatchers() != null) {
final CompoundTag state = convertPredicate(predicate); predicateTag.put("state", createState(predicate));
predicateTag.put("state", state);
} }
if (predicate.tag() != null) { if (predicate.tag() != null) {
predicateTag.put("nbt", predicate.tag()); predicateTag.put("nbt", predicate.tag());
@ -420,8 +427,10 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
return tag; return tag;
} }
protected CompoundTag convertPredicate(final BlockPredicate predicate) { // Not an own conversion method, just to avoid high nesting
protected CompoundTag createState(BlockPredicate predicate) {
final CompoundTag state = new CompoundTag(); final CompoundTag state = new CompoundTag();
for (final StatePropertyMatcher matcher : predicate.propertyMatchers()) { for (final StatePropertyMatcher matcher : predicate.propertyMatchers()) {
final Either<String, StatePropertyMatcher.RangedMatcher> match = matcher.matcher(); final Either<String, StatePropertyMatcher.RangedMatcher> match = matcher.matcher();
if (match.isLeft()) { if (match.isLeft()) {
@ -441,10 +450,6 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
return state; return state;
} }
protected CompoundTag convertCanBreak(final AdventureModePredicate value) {
return convertCanPlaceOn(value);
}
protected CompoundTag convertAttributeModifiers(final AttributeModifiers1_20_5 value) { protected CompoundTag convertAttributeModifiers(final AttributeModifiers1_20_5 value) {
final CompoundTag tag = new CompoundTag(); final CompoundTag tag = new CompoundTag();
final ListTag<CompoundTag> modifiers = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> modifiers = new ListTag<>(CompoundTag.class);
@ -946,7 +951,17 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
if (set.hasTagKey()) { if (set.hasTagKey()) {
tag.putString(name, set.tagKey()); tag.putString(name, set.tagKey());
} else { } else {
tag.put(name, new IntArrayTag(set.ids())); final ListTag<StringTag> identifiers = new ListTag<>(StringTag.class);
for (final int id : set.ids()) {
// Can use old block list because new ids are only at the end :tm:
final String identifier = Protocol1_20_3To1_20_5.MAPPINGS.blockName(id);
if (identifier == null) {
continue;
}
identifiers.add(new StringTag(identifier));
}
tag.put(name, identifiers);
} }
} }