Repository navigation
Rework horse variant component to match vanilla - #2996
Conversation
kermandev
left a comment
There was a problem hiding this comment.
Correct me if im wrong, but..
| public static final DataComponent<RegistryKey<ChickenVariant>> CHICKEN_VARIANT = register("chicken/variant", ChickenVariant.NETWORK_TYPE, ChickenVariant.CODEC); | ||
| public static final DataComponent<RegistryKey<FrogVariant>> FROG_VARIANT = register("frog/variant", FrogVariant.NETWORK_TYPE, FrogVariant.CODEC); | ||
| public static final DataComponent<HorseMeta.Color> HORSE_VARIANT = register("horse/variant", HorseMeta.Color.NETWORK_TYPE, HorseMeta.Color.NBT_TYPE); | ||
| public static final DataComponent<HorseMeta.Variant> HORSE_VARIANT = register("horse/variant", HorseMeta.Variant.NETWORK_TYPE, HorseMeta.Variant.CODEC); |
There was a problem hiding this comment.
Color is actually correct here. The markings is determined by the horse metadata (annoying right?)
| protected <T> @Nullable T get(DataComponent<T> component) { | ||
| if (component == DataComponents.HORSE_VARIANT) | ||
| return (T) getVariant().getMarking(); | ||
| return (T) getVariant(); |
There was a problem hiding this comment.
Hmm it seems the original was wrong should be getColor
| variant.setMarking((Marking) value); | ||
| setVariant(variant); | ||
| } else super.set(component, value); | ||
| setVariant((Variant) value); |
There was a problem hiding this comment.
should be Color, we probably should retain the marking though
| import net.minestom.server.codec.StructCodec; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public class HorseMeta extends AbstractHorseMeta { |
There was a problem hiding this comment.
No clue why the original setVariant was deprecated (as marking needs to be set), to be fair there should be little reason to have a Variant builder class and Color should become Variant. Maybe a change you would want to target next instead.
So HoreMeta would have
set(Variant, etc...)
setVariantAndMarking(Variant variant, Marking marking)
setMarking(Marking)
getMarking()
I agree its a little weird, but horse variant is probably a weird oversight from mojang that havent bothered to fix it yet.
| var meta = (HorseMeta) horse.getEntityMeta(); | ||
| meta.setBaby(baby); | ||
| meta.setVariant(new HorseMeta.Variant(marking, color)); | ||
| horse.set(DataComponents.HORSE_VARIANT, new HorseMeta.Variant(marking, color)); |
There was a problem hiding this comment.
Sadly this component could only ever change the color, not the marking.
There was a problem hiding this comment.
Not true, in my screenshot you can see it's setting the marking correctly. The PR is correct as Minecraft represents markings + color as a single entity component named 'variant'.
There was a problem hiding this comment.
Yes cause the data component is incorrectly implemented. If you were to use this data component generically it would be incorrect
Binary CompatibilityThis Pull Request has introduced binary incompatible changes compared to the What is Binary Compatibility? What should you do?
View offending signatures |
|
@mudkipdev you missed ba3873e when swapping |
HorseMeta.ColortoHorseMeta.Variant, matching vanilla's color-only variant enumHORSE_VARIANTnow serializes identically to vanilla (string in NBT, var-int id on the network)Variantwrapper class andgetVariantID/getVariantFromIDsetVariantonly changes the color and preserves the marking, like vanillagetMarking,setMarking, andsetVariantAndMarkingtoHorseMetaget/setoverrides using the marking where the color was expectednextdue to breaking API changes