mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-21 12:07:38 +01:00
Track banner patterns
This commit is contained in:
parent
7d6c330fa3
commit
68807be880
@ -74,8 +74,6 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundP
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// TODO Trim storage in registry sending
|
||||
// TODO also for banners?
|
||||
super.registerPackets();
|
||||
|
||||
final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);
|
||||
@ -89,7 +87,7 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundP
|
||||
tagRewriter.getGenericHandler().handle(wrapper);
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_20_5.START_CONFIGURATION, wrapper -> wrapper.user().get(RegistryDataStorage.class).registryData().clear());
|
||||
registerClientbound(ClientboundPackets1_20_5.START_CONFIGURATION, wrapper -> wrapper.user().get(RegistryDataStorage.class).clear());
|
||||
|
||||
final SoundRewriter<ClientboundPacket1_20_5> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.SOUND);
|
||||
|
@ -42,6 +42,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attribute
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.storage.BannerPatternStorage;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
import java.util.HashMap;
|
||||
@ -78,20 +79,28 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
} while (slot < 0);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
handler(wrapper -> {
|
||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.read(Type.STRING));
|
||||
// TODO Track banner pattern/material ids
|
||||
if (registryKey.equals("wolf_variant") || registryKey.equals("banner_pattern") || registryKey.equals("banner_material")) {
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.read(Type.STRING));
|
||||
if (registryKey.equals("wolf_variant")) {
|
||||
// There's only one wolf variant now
|
||||
return;
|
||||
}
|
||||
|
||||
// Track data
|
||||
final RegistryEntry[] entries = wrapper.read(Type.REGISTRY_ENTRY_ARRAY);
|
||||
final RegistryDataStorage registryDataStorage = wrapper.user().get(RegistryDataStorage.class);
|
||||
final RegistryEntry[] entries = wrapper.read(Type.REGISTRY_ENTRY_ARRAY);
|
||||
// Track banner pattern and material ids for conversion in items
|
||||
if (registryKey.equals("banner_pattern")) {
|
||||
final BannerPatternStorage bannerStorage = new BannerPatternStorage();
|
||||
wrapper.user().put(bannerStorage);
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
bannerStorage.bannerPatterns().put(i, entries[i].key());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Track biome and dimension data
|
||||
if (registryKey.equals("worldgen/biome")) {
|
||||
tracker(wrapper.user()).setBiomesSent(entries.length);
|
||||
} else if (registryKey.equals("dimension_type")) {
|
||||
@ -112,6 +121,7 @@ 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);
|
||||
@ -120,7 +130,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
final RegistryEntry entry = entries[i];
|
||||
Preconditions.checkNotNull(entry.tag(), "Server unexpectedly sent null registry data entry for " + entry.key());
|
||||
|
||||
if (registryKey.equals("trim_pattern")) {
|
||||
if (isTrimPattern) {
|
||||
final CompoundTag patternTag = (CompoundTag) entry.tag();
|
||||
final StringTag templateItem = patternTag.getStringTag("template_item");
|
||||
if (Protocol1_20_5To1_20_3.MAPPINGS.itemId(templateItem.getValue()) == -1) {
|
||||
@ -138,9 +148,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
|
||||
// Store and send together with the rest later
|
||||
registryDataStorage.registryData().put(registryKey, registryTag);
|
||||
wrapper.cancel();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_5.JOIN_GAME, new PacketHandlers() {
|
||||
|
Loading…
Reference in New Issue
Block a user