Handle custom armor trims in 1.20.5->1.20.3

Fixes #847, closes #850
This commit is contained in:
Nassim Jahnke 2024-08-07 12:47:26 +02:00
parent 87d05ae487
commit 6a766f2467
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
4 changed files with 25 additions and 10 deletions

View File

@ -69,7 +69,7 @@ import java.util.logging.Logger;
public interface ViaBackwardsPlatform {
String MINIMUM_VV_VERSION = "5.0.2";
String MINIMUM_VV_VERSION = "5.0.3";
/**
* Initialize ViaBackwards.

View File

@ -54,6 +54,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPac
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.BannerPatternStorage;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
@ -233,6 +234,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
user.put(new CookieStorage());
user.put(new RegistryDataStorage());
user.put(new BannerPatternStorage());
user.put(new ArmorTrimStorage());
}
@Override

View File

@ -48,6 +48,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.BannerPatternStorage;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.KeyMappings;
@ -110,16 +111,21 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
final RegistryDataStorage registryDataStorage = wrapper.user().get(RegistryDataStorage.class);
final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY);
// Track trim patterns and armor trims for conversion in items
if (registryKey.equals("banner_pattern")) {
// Track banner pattern and material ids for conversion in items
final String[] keys = new String[entries.length];
for (int i = 0; i < entries.length; i++) {
keys[i] = Key.stripMinecraftNamespace(entries[i].key());
}
wrapper.user().get(BannerPatternStorage.class).setBannerPatterns(new KeyMappings(keys));
// Don't send it
wrapper.user().get(BannerPatternStorage.class).setBannerPatterns(toMappings(entries));
return;
}
final boolean isTrimPattern = registryKey.equals("trim_pattern");
if (isTrimPattern) {
wrapper.user().get(ArmorTrimStorage.class).setTrimPatterns(toMappings(entries));
} else if (registryKey.equals("trim_material")) {
wrapper.user().get(ArmorTrimStorage.class).setTrimMaterials(toMappings(entries));
}
// Track biome and dimension data
if (registryKey.equals("worldgen/biome")) {
tracker(wrapper.user()).setBiomesSent(entries.length);
@ -156,7 +162,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}
// Write to old format
final boolean isTrimPattern = registryKey.equals("trim_pattern");
final CompoundTag registryTag = new CompoundTag();
final ListTag<CompoundTag> entriesTag = new ListTag<>(CompoundTag.class);
registryTag.putString("type", registryKey);
@ -291,6 +296,14 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
});
}
private KeyMappings toMappings(final RegistryEntry[] entries) {
final String[] keys = new String[entries.length];
for (int i = 0; i < entries.length; i++) {
keys[i] = Key.stripMinecraftNamespace(entries[i].key());
}
return new KeyMappings(keys);
}
private void updateParticleFormat(final CompoundTag options, final String particleType) {
if ("block".equals(particleType) || "block_marker".equals(particleType) || "falling_dust".equals(particleType) || "dust_pillar".equals(particleType)) {
Tag blockState = options.remove("block_state");

View File

@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions]
# ViaVersion
viaver = "5.0.2-SNAPSHOT"
viaver = "5.0.3-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"