Skip to content

Commit 5689389

Browse files
Implement wolf sound & chicken variants hashing (#4698)
1 parent ed07809 commit 5689389

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
5252
import com.viaversion.viaversion.api.minecraft.item.data.Enchantable;
5353
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
54+
import com.viaversion.viaversion.api.minecraft.item.data.EntityData;
5455
import com.viaversion.viaversion.api.minecraft.item.data.EnumTypes;
5556
import com.viaversion.viaversion.api.minecraft.item.data.Equippable;
5657
import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
@@ -71,7 +72,6 @@
7172
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
7273
import com.viaversion.viaversion.api.minecraft.item.data.TooltipDisplay;
7374
import com.viaversion.viaversion.api.minecraft.item.data.TropicalFishPattern;
74-
import com.viaversion.viaversion.api.minecraft.item.data.EntityData;
7575
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
7676
import com.viaversion.viaversion.api.minecraft.item.data.UseCooldown;
7777
import com.viaversion.viaversion.api.minecraft.item.data.Weapon;
@@ -80,7 +80,7 @@
8080
import com.viaversion.viaversion.api.type.Type;
8181
import com.viaversion.viaversion.api.type.Types;
8282
import com.viaversion.viaversion.api.type.types.ArrayType;
83-
import com.viaversion.viaversion.api.type.types.EitherType;
83+
import com.viaversion.viaversion.api.type.types.misc.SynchronizedRegistryEitherType;
8484
import com.viaversion.viaversion.api.type.types.misc.SynchronizedRegistryValueType;
8585
import com.viaversion.viaversion.api.type.types.version.VersionedTypes;
8686
import com.viaversion.viaversion.util.Either;
@@ -197,7 +197,7 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
197197

198198
public static final StructuredDataKey<Integer> VILLAGER_VARIANT = new StructuredDataKey<>("villager/variant", EnumTypes.VILLAGER_TYPE);
199199
public static final StructuredDataKey<Integer> WOLF_VARIANT = new StructuredDataKey<>("wolf/variant", new SynchronizedRegistryValueType(RegistryKey.of("wolf_variant")));
200-
public static final StructuredDataKey<Integer> WOLF_SOUND_VARIANT = new StructuredDataKey<>("wolf/sound_variant", Types.VAR_INT);
200+
public static final StructuredDataKey<Integer> WOLF_SOUND_VARIANT = new StructuredDataKey<>("wolf/sound_variant", new SynchronizedRegistryValueType(RegistryKey.of("wolf_sound_variant")));
201201
public static final StructuredDataKey<Integer> WOLF_COLLAR = new StructuredDataKey<>("wolf/collar", EnumTypes.DYE_COLOR);
202202
public static final StructuredDataKey<Integer> FOX_VARIANT = new StructuredDataKey<>("fox/variant", EnumTypes.FOX_VARIANT);
203203
public static final StructuredDataKey<Integer> SALMON_SIZE = new StructuredDataKey<>("salmon/size", EnumTypes.SALMON_VARIANT);
@@ -209,7 +209,7 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
209209
public static final StructuredDataKey<Integer> RABBIT_VARIANT = new StructuredDataKey<>("rabbit/variant", EnumTypes.RABBIT_VARIANT);
210210
public static final StructuredDataKey<Integer> PIG_VARIANT = new StructuredDataKey<>("pig/variant", new SynchronizedRegistryValueType(RegistryKey.of("pig_variant")));
211211
public static final StructuredDataKey<Integer> COW_VARIANT = new StructuredDataKey<>("cow/variant", new SynchronizedRegistryValueType(RegistryKey.of("cow_variant")));
212-
public static final StructuredDataKey<Either<Integer, String>> CHICKEN_VARIANT = new StructuredDataKey<>("chicken/variant", new EitherType<>(Types.VAR_INT, Types.STRING)); // ???
212+
public static final StructuredDataKey<Either<Integer, String>> CHICKEN_VARIANT = new StructuredDataKey<>("chicken/variant", new SynchronizedRegistryEitherType(RegistryKey.of("chicken_variant")));
213213
public static final StructuredDataKey<Integer> FROG_VARIANT = new StructuredDataKey<>("frog/variant", new SynchronizedRegistryValueType(RegistryKey.of("frog_variant")));
214214
public static final StructuredDataKey<Integer> HORSE_VARIANT = new StructuredDataKey<>("horse/variant", EnumTypes.HORSE_VARIANT);
215215
public static final StructuredDataKey<Holder<PaintingVariant>> PAINTING_VARIANT = new StructuredDataKey<>("painting/variant", PaintingVariant.TYPE1_21_2);

api/src/main/java/com/viaversion/viaversion/api/type/types/EitherType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import io.netty.buffer.ByteBuf;
2828

2929
// Yuck - only use when necessary
30-
public final class EitherType<T, V> extends Type<Either<T, V>> {
30+
public class EitherType<T, V> extends Type<Either<T, V>> {
3131
private final Type<T> leftType;
3232
private final Type<V> rightType;
3333

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
3+
* Copyright (C) 2016-2025 ViaVersion and contributors
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
package com.viaversion.viaversion.api.type.types.misc;
24+
25+
import com.viaversion.viaversion.api.minecraft.RegistryKey;
26+
import com.viaversion.viaversion.api.minecraft.codec.Ops;
27+
import com.viaversion.viaversion.api.type.Types;
28+
import com.viaversion.viaversion.api.type.types.EitherType;
29+
import com.viaversion.viaversion.util.Either;
30+
import com.viaversion.viaversion.util.Key;
31+
32+
// ???
33+
public final class SynchronizedRegistryEitherType extends EitherType<Integer, String> {
34+
35+
private final RegistryKey registryKey;
36+
37+
public SynchronizedRegistryEitherType(final RegistryKey registryKey) {
38+
super(Types.VAR_INT, Types.STRING);
39+
this.registryKey = registryKey;
40+
}
41+
42+
@Override
43+
public void write(final Ops ops, final Either<Integer, String> value) {
44+
if (value.isLeft()) {
45+
final Key key = ops.context().registryAccess().registryKey(this.registryKey.key().toString(), value.left());
46+
Types.RESOURCE_LOCATION.write(ops, key);
47+
} else {
48+
Types.RESOURCE_LOCATION.write(ops, Key.of(value.right()));
49+
}
50+
}
51+
}

common/src/main/java/com/viaversion/viaversion/codec/CodecRegistryContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public record CodecRegistryContext(Protocol<?, ?, ?, ?> protocol, RegistryAccess
3131
// Generally from hardcoded, but highly variable client data
3232
private static final Set<StructuredDataKey<?>> NOT_IMPLEMENTED = new ReferenceOpenHashSet<>(List.of(
3333
StructuredDataKey.CONSUMABLE1_21_2, StructuredDataKey.JUKEBOX_PLAYABLE1_21_5,
34-
StructuredDataKey.DEATH_PROTECTION, StructuredDataKey.WOLF_SOUND_VARIANT, StructuredDataKey.CHICKEN_VARIANT, StructuredDataKey.PAINTING_VARIANT
34+
StructuredDataKey.DEATH_PROTECTION, StructuredDataKey.PAINTING_VARIANT
3535
));
3636

3737
public CodecRegistryContext(final Protocol<?, ?, ?, ?> protocol, final RegistryAccess registryAccess, final boolean mapped) {

0 commit comments

Comments
 (0)