From 5d8207c6981be3ad527b91529cf45bc135490013 Mon Sep 17 00:00:00 2001 From: Gabriel Harris-Rouquette Date: Wed, 22 Jan 2025 21:34:07 -0800 Subject: [PATCH] feat: add WolfVariant --- .../java/org/spongepowered/api/data/Keys.java | 6 ++ .../api/data/type/WolfVariant.java | 33 +++++++++ .../api/data/type/WolfVariants.java | 71 +++++++++++++++++++ .../api/entity/living/animal/Wolf.java | 9 +++ .../api/registry/RegistryTypes.java | 3 + 5 files changed, 122 insertions(+) create mode 100644 src/main/java/org/spongepowered/api/data/type/WolfVariant.java create mode 100644 src/main/java/org/spongepowered/api/data/type/WolfVariants.java diff --git a/src/main/java/org/spongepowered/api/data/Keys.java b/src/main/java/org/spongepowered/api/data/Keys.java index 691f5a002c..d4f4b46b8f 100644 --- a/src/main/java/org/spongepowered/api/data/Keys.java +++ b/src/main/java/org/spongepowered/api/data/Keys.java @@ -97,6 +97,7 @@ import org.spongepowered.api.data.type.VillagerType; import org.spongepowered.api.data.type.WallConnectionState; import org.spongepowered.api.data.type.WireAttachmentType; +import org.spongepowered.api.data.type.WolfVariant; import org.spongepowered.api.data.value.ListValue; import org.spongepowered.api.data.value.MapValue; import org.spongepowered.api.data.value.SetValue; @@ -3449,6 +3450,11 @@ public final class Keys { */ public static final Key> WITHER_TARGETS = Keys.listKey(ResourceKey.sponge("wither_targets"), Entity.class); + /** + * The {@link WolfVariant} of a {@link Wolf}. + */ + public static final Key> WOLF_VARIANT = Keys.key(ResourceKey.sponge("wolf_variant"), WolfVariant.class); + /** * The {@link Sheep} who is being targeted by the {@link SpellTypes#WOLOLO} * spell being casted by an {@link Evoker} diff --git a/src/main/java/org/spongepowered/api/data/type/WolfVariant.java b/src/main/java/org/spongepowered/api/data/type/WolfVariant.java new file mode 100644 index 0000000000..50f041bfaf --- /dev/null +++ b/src/main/java/org/spongepowered/api/data/type/WolfVariant.java @@ -0,0 +1,33 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.data.type; + +import org.spongepowered.api.registry.DefaultedRegistryValue; +import org.spongepowered.api.util.annotation.CatalogedBy; + +@CatalogedBy(WolfVariants.class) +public interface WolfVariant extends DefaultedRegistryValue { + +} diff --git a/src/main/java/org/spongepowered/api/data/type/WolfVariants.java b/src/main/java/org/spongepowered/api/data/type/WolfVariants.java new file mode 100644 index 0000000000..f362a6b189 --- /dev/null +++ b/src/main/java/org/spongepowered/api/data/type/WolfVariants.java @@ -0,0 +1,71 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.data.type; + +import org.spongepowered.api.ResourceKey; +import org.spongepowered.api.registry.Registry; +import org.spongepowered.api.registry.RegistryKey; +import org.spongepowered.api.registry.RegistryReference; +import org.spongepowered.api.registry.RegistryScope; +import org.spongepowered.api.registry.RegistryScopes; +import org.spongepowered.api.registry.RegistryTypes; +import org.spongepowered.api.world.server.ServerWorld; + +/** + * + */ +@SuppressWarnings("unused") +@RegistryScopes(scopes = RegistryScope.WORLD) +public final class WolfVariants { + + public static final RegistryReference ASHEN = WolfVariants.key(ResourceKey.minecraft("ashen")); + + public static final RegistryReference BLACK = WolfVariants.key(ResourceKey.minecraft("black")); + + public static final RegistryReference CHESTNUT = WolfVariants.key(ResourceKey.minecraft("chestnut")); + + public static final RegistryReference PALE = WolfVariants.key(ResourceKey.minecraft("pale")); + + public static final RegistryReference RUSTY = WolfVariants.key(ResourceKey.minecraft("rusty")); + + public static final RegistryReference SNOWY = WolfVariants.key(ResourceKey.minecraft("snowy")); + + public static final RegistryReference SPOTTED = WolfVariants.key(ResourceKey.minecraft("spotted")); + + public static final RegistryReference STRIPED = WolfVariants.key(ResourceKey.minecraft("striped")); + + public static final RegistryReference WOODS = WolfVariants.key(ResourceKey.minecraft("woods")); + + private WolfVariants() { + } + + public static Registry registry(final ServerWorld world) { + return world.registry(RegistryTypes.WOLF_VAIRANT); + } + + private static RegistryReference key(final ResourceKey location) { + return RegistryKey.of(RegistryTypes.WOLF_VAIRANT, location).asReference(); + } +} diff --git a/src/main/java/org/spongepowered/api/entity/living/animal/Wolf.java b/src/main/java/org/spongepowered/api/entity/living/animal/Wolf.java index 20a31a6a89..c35a73fee6 100644 --- a/src/main/java/org/spongepowered/api/entity/living/animal/Wolf.java +++ b/src/main/java/org/spongepowered/api/entity/living/animal/Wolf.java @@ -26,6 +26,7 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.DyeColor; +import org.spongepowered.api.data.type.WolfVariant; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.entity.Angerable; @@ -34,6 +35,14 @@ */ public interface Wolf extends TameableAnimal, Angerable { + /** + * {@link Keys#WOLF_VARIANT} + * @return The wolf's variant + */ + default Value.Mutable variant() { + return this.requireValue(Keys.WOLF_VARIANT).asMutable(); + } + /** * {@link Keys#DYE_COLOR} * @return The collar color diff --git a/src/main/java/org/spongepowered/api/registry/RegistryTypes.java b/src/main/java/org/spongepowered/api/registry/RegistryTypes.java index b621ca11f5..45ab49c05f 100644 --- a/src/main/java/org/spongepowered/api/registry/RegistryTypes.java +++ b/src/main/java/org/spongepowered/api/registry/RegistryTypes.java @@ -94,6 +94,7 @@ import org.spongepowered.api.data.type.VillagerType; import org.spongepowered.api.data.type.WallConnectionState; import org.spongepowered.api.data.type.WireAttachmentType; +import org.spongepowered.api.data.type.WolfVariant; import org.spongepowered.api.effect.particle.ParticleOption; import org.spongepowered.api.effect.particle.ParticleType; import org.spongepowered.api.effect.potion.PotionEffectType; @@ -512,6 +513,8 @@ public final class RegistryTypes { public static final DefaultedRegistryType WEATHER_TYPE = RegistryTypes.spongeKeyInGame("weather_type"); + public static final DefaultedRegistryType WOLF_VAIRANT = RegistryTypes.minecraftKeyInServer("wolf_vairant"); + public static final DefaultedRegistryType WIRE_ATTACHMENT_TYPE = RegistryTypes.spongeKeyInGame("wire_attachment_type"); // @formatter:on