Skip to content

Commit d49272a

Browse files
Fix error when wolf_variant registry data isn't sent in 1.20.5->1.21 (ViaVersion#4655)
1 parent bea6df1 commit d49272a

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/EntityPacketRewriter1_21.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter;
1919

2020
import com.viaversion.nbt.tag.CompoundTag;
21+
import com.viaversion.nbt.tag.ListTag;
22+
import com.viaversion.nbt.tag.StringTag;
2123
import com.viaversion.viaversion.api.Via;
2224
import com.viaversion.viaversion.api.minecraft.Holder;
2325
import com.viaversion.viaversion.api.minecraft.PaintingVariant;
@@ -37,8 +39,10 @@
3739
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
3840
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
3941
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.PlayerPositionStorage;
42+
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.WolfVariantRegistryMarker;
4043
import com.viaversion.viaversion.rewriter.EntityRewriter;
4144
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
45+
import com.viaversion.viaversion.util.Key;
4246

4347
public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPacket1_20_5, Protocol1_20_5To1_21> {
4448

@@ -58,7 +62,15 @@ public void registerPackets() {
5862
campfireDamageType.putString("message_id", "inFire");
5963
campfireDamageType.putFloat("exhaustion", 0.1F);
6064
registryDataRewriter.addEntries("damage_type", new RegistryEntry("minecraft:campfire", campfireDamageType));
61-
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, registryDataRewriter::handle);
65+
protocol.registerClientbound(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA, wrapper -> {
66+
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
67+
RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY);
68+
entries = registryDataRewriter.handle(wrapper.user(), registryKey, entries);
69+
wrapper.write(Types.REGISTRY_ENTRY_ARRAY, entries);
70+
if (registryKey.equals("wolf_variant")) {
71+
wrapper.user().put(new WolfVariantRegistryMarker());
72+
}
73+
});
6274

6375
protocol.registerFinishConfiguration(ClientboundConfigurationPackets1_20_5.FINISH_CONFIGURATION, wrapper -> {
6476
// Add new registries
@@ -91,6 +103,10 @@ public void registerPackets() {
91103
jukeboxSongsPacket.write(Types.STRING, "minecraft:jukebox_song");
92104
jukeboxSongsPacket.write(Types.REGISTRY_ENTRY_ARRAY, protocol.getMappingData().jukeboxSongs());
93105
jukeboxSongsPacket.send(Protocol1_20_5To1_21.class);
106+
107+
if (!wrapper.user().has(WolfVariantRegistryMarker.class)) {
108+
createDefaultWolfVariantRegistryDataPacket(wrapper).send(Protocol1_20_5To1_21.class);
109+
}
94110
});
95111

96112
registerLogin1_20_5(ClientboundPackets1_20_5.LOGIN);
@@ -138,6 +154,24 @@ public void registerPackets() {
138154
});
139155
}
140156

157+
private static PacketWrapper createDefaultWolfVariantRegistryDataPacket(final PacketWrapper wrapper) {
158+
final PacketWrapper wolfVariantPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
159+
wolfVariantPacket.write(Types.STRING, "minecraft:wolf_variant");
160+
wolfVariantPacket.write(Types.REGISTRY_ENTRY_ARRAY, getDefaultWolfVariantRegistryEntries());
161+
return wolfVariantPacket;
162+
}
163+
164+
private static RegistryEntry[] getDefaultWolfVariantRegistryEntries() {
165+
final CompoundTag paleWolfVariant = new CompoundTag();
166+
paleWolfVariant.putString("wild_texture", "minecraft:entity/wolf/wolf");
167+
paleWolfVariant.putString("angry_texture", "minecraft:entity/wolf/wolf_angry");
168+
paleWolfVariant.put("biomes", new ListTag<>(StringTag.class));
169+
paleWolfVariant.putString("tame_texture", "minecraft:entity/wolf/wolf_tame");
170+
return new RegistryEntry[]{
171+
new RegistryEntry("minecraft:pale", paleWolfVariant),
172+
};
173+
}
174+
141175
private void storePosition(final PacketWrapper wrapper) {
142176
final double x = wrapper.passthrough(Types.DOUBLE);
143177
final double y = wrapper.passthrough(Types.DOUBLE);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
3+
* Copyright (C) 2016-2025 ViaVersion and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.viaversion.viaversion.protocols.v1_20_5to1_21.storage;
19+
20+
import com.viaversion.viaversion.api.connection.StorableObject;
21+
22+
public final class WolfVariantRegistryMarker implements StorableObject {
23+
}

0 commit comments

Comments
 (0)