3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Handle removed item conversion in component rewriter

Dieser Commit ist enthalten in:
FlorianMichael 2024-04-17 22:39:08 +02:00
Ursprung 8cf9114403
Commit 033d5ae49a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: C2FB87E71C425126
3 geänderte Dateien mit 14 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -58,7 +58,7 @@ public final class BlockPredicate {
private final StatePropertyMatcher[] propertyMatchers; private final StatePropertyMatcher[] propertyMatchers;
private final CompoundTag tag; private final CompoundTag tag;
public BlockPredicate(@Nullable final HolderSet holderSet, @Nullable final StatePropertyMatcher[] propertyMatchers, @Nullable final CompoundTag tag) { public BlockPredicate(@Nullable final HolderSet holderSet, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) {
this.holderSet = holderSet; this.holderSet = holderSet;
this.propertyMatchers = propertyMatchers; this.propertyMatchers = propertyMatchers;
this.tag = tag; this.tag = tag;
@ -68,7 +68,7 @@ public final class BlockPredicate {
return holderSet; return holderSet;
} }
public @Nullable StatePropertyMatcher[] propertyMatchers() { public StatePropertyMatcher @Nullable [] propertyMatchers() {
return propertyMatchers; return propertyMatchers;
} }

Datei anzeigen

@ -226,7 +226,7 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
if (!data.isEmpty()) { if (!data.isEmpty()) {
CompoundTag components; CompoundTag components;
try { try {
components = toTag(data); components = toTag(data, false);
} catch (Exception e) { } catch (Exception e) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().log(Level.WARNING, "Error writing 1.20.5 components in show_item!", e); Via.getPlatform().getLogger().log(Level.WARNING, "Error writing 1.20.5 components in show_item!", e);
@ -237,7 +237,7 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
} }
} }
protected CompoundTag toTag(final Map<StructuredDataKey<?>, StructuredData<?>> data) { protected CompoundTag toTag(final Map<StructuredDataKey<?>, StructuredData<?>> data, final boolean empty) {
final CompoundTag tag = new CompoundTag(); final CompoundTag tag = new CompoundTag();
for (final Map.Entry<StructuredDataKey<?>, StructuredData<?>> entry : data.entrySet()) { for (final Map.Entry<StructuredDataKey<?>, StructuredData<?>> entry : data.entrySet()) {
final StructuredDataKey<?> key = entry.getKey(); final StructuredDataKey<?> key = entry.getKey();
@ -247,13 +247,19 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
} }
final StructuredData<?> value = entry.getValue(); final StructuredData<?> value = entry.getValue();
if (value.isEmpty()) { if (value.isEmpty()) {
if (empty) {
// Theoretically not needed here, but we'll keep it for consistency
tag.put("!" + key.identifier(), new CompoundTag());
continue;
}
throw new IllegalArgumentException("Empty structured data: " + key.identifier()); throw new IllegalArgumentException("Empty structured data: " + key.identifier());
} }
//noinspection unchecked //noinspection unchecked
final Tag valueTag = rewriters.get(key).convert(value.value()); final Tag valueTag = rewriters.get(key).convert(value.value());
if (valueTag == null) continue; if (valueTag == null) {
continue;
}
tag.put(key.identifier(), valueTag); tag.put(key.identifier(), valueTag);
} }
return tag; return tag;
@ -863,7 +869,7 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
tag.putInt("count", 1); tag.putInt("count", 1);
} }
final Map<StructuredDataKey<?>, StructuredData<?>> components = item.structuredData().data(); final Map<StructuredDataKey<?>, StructuredData<?>> components = item.structuredData().data();
tag.put("components", toTag(components)); tag.put("components", toTag(components, true));
} }
protected void convertFilterableString(final CompoundTag tag, final FilterableString string, final int min, final int max) { protected void convertFilterableString(final CompoundTag tag, final FilterableString string, final int min, final int max) {

Datei anzeigen

@ -87,7 +87,7 @@ public final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
super.onMappingDataLoaded(); // Calls load methods on rewriters super.onMappingDataLoaded(); // Calls load methods on rewriters
// Uncomment this if the entity types enum has been newly added specificly for this Protocol // Uncomment this if the entity types enum has been newly added specifically for this Protocol
// EntityTypes1_20_5.initialize(this); // EntityTypes1_20_5.initialize(this);
// Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last // Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last