From f402974d66ec8594c3c8a827a28000bfe8ee1d3d Mon Sep 17 00:00:00 2001 From: aromaa Date: Wed, 23 Oct 2024 20:30:36 +0300 Subject: [PATCH] Implement frog type key --- SpongeAPI | 2 +- .../provider/entity/EntityDataProviders.java | 1 + .../common/data/provider/entity/FrogData.java | 48 +++++++++++++++++++ .../entity/animal/FrogVariantMixin_API.java | 33 +++++++++++++ .../entity/animal/frog/FrogMixin_API.java | 3 ++ src/mixins/resources/mixins.sponge.api.json | 1 + 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/spongepowered/common/data/provider/entity/FrogData.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/FrogVariantMixin_API.java diff --git a/SpongeAPI b/SpongeAPI index 9eec8a5e6e3..faefbd50d00 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 9eec8a5e6e3f64fc5a373bdb8d468e132261e67d +Subproject commit faefbd50d003cdbce5f61650fd49b61f96e6d79f diff --git a/src/main/java/org/spongepowered/common/data/provider/entity/EntityDataProviders.java b/src/main/java/org/spongepowered/common/data/provider/entity/EntityDataProviders.java index facac285ef6..29910a3ecac 100644 --- a/src/main/java/org/spongepowered/common/data/provider/entity/EntityDataProviders.java +++ b/src/main/java/org/spongepowered/common/data/provider/entity/EntityDataProviders.java @@ -66,6 +66,7 @@ public void registerProviders() { FireworkRocketData.register(this.registrator); FishingBobberData.register(this.registrator); FoxData.register(this.registrator); + FrogData.register(this.registrator); FurnaceMinecartData.register(this.registrator); FusedExplosiveData.register(this.registrator); GrieferData.register(this.registrator); diff --git a/src/main/java/org/spongepowered/common/data/provider/entity/FrogData.java b/src/main/java/org/spongepowered/common/data/provider/entity/FrogData.java new file mode 100644 index 00000000000..2fef31a0006 --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/provider/entity/FrogData.java @@ -0,0 +1,48 @@ +/* + * This file is part of Sponge, 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.common.data.provider.entity; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.entity.animal.FrogVariant; +import net.minecraft.world.entity.animal.frog.Frog; +import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.type.FrogType; +import org.spongepowered.common.data.provider.DataProviderRegistrator; + +public final class FrogData { + + private FrogData() { + } + + // @formatter:off + public static void register(final DataProviderRegistrator registrator) { + registrator + .asMutable(Frog.class) + .create(Keys.FROG_TYPE) + .get(h -> (FrogType) (Object) h.getVariant().value()) + .set((h, v) -> h.setVariant(BuiltInRegistries.FROG_VARIANT.wrapAsHolder((FrogVariant) (Object) v))); + } + // @formatter:on +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/FrogVariantMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/FrogVariantMixin_API.java new file mode 100644 index 00000000000..dad1a167076 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/FrogVariantMixin_API.java @@ -0,0 +1,33 @@ +/* + * This file is part of Sponge, 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.common.mixin.api.minecraft.world.entity.animal; + +import net.minecraft.world.entity.animal.FrogVariant; +import org.spongepowered.api.data.type.FrogType; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(FrogVariant.class) +public abstract class FrogVariantMixin_API implements FrogType { +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/frog/FrogMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/frog/FrogMixin_API.java index 71b3201cdc6..d7905b4a86d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/frog/FrogMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/animal/frog/FrogMixin_API.java @@ -24,6 +24,7 @@ */ package org.spongepowered.common.mixin.api.minecraft.world.entity.animal.frog; +import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.entity.living.animal.frog.Frog; import org.spongepowered.asm.mixin.Mixin; @@ -38,6 +39,8 @@ public abstract class FrogMixin_API extends AnimalMixin_API implements Frog { protected Set> api$getVanillaValues() { final Set> values = super.api$getVanillaValues(); + values.add(this.requireValue(Keys.FROG_TYPE).asImmutable()); + return values; } diff --git a/src/mixins/resources/mixins.sponge.api.json b/src/mixins/resources/mixins.sponge.api.json index e370254598e..db3af50bb32 100644 --- a/src/mixins/resources/mixins.sponge.api.json +++ b/src/mixins/resources/mixins.sponge.api.json @@ -182,6 +182,7 @@ "minecraft.world.entity.animal.FlyingAnimalMixin_API", "minecraft.world.entity.animal.Fox_TypeMixin_API", "minecraft.world.entity.animal.FoxMixin_API", + "minecraft.world.entity.animal.FrogVariantMixin_API", "minecraft.world.entity.animal.IronGolemMixin_API", "minecraft.world.entity.animal.MushroomCow_MushroomTypeMixin_API", "minecraft.world.entity.animal.MushroomCowMixin_API",