From 7f18693d7f4880973c9035c91b43683f74192b69 Mon Sep 17 00:00:00 2001 From: Gabriel Harris-Rouquette Date: Thu, 24 Oct 2024 00:43:58 -0700 Subject: [PATCH] feat: add salmon size data --- .../vanilla/generator/GeneratorMain.java | 8 ++++ .../provider/entity/EntityDataProviders.java | 1 + .../data/provider/entity/SalmonData.java | 46 +++++++++++++++++++ .../loader/VanillaRegistryLoader.java | 2 + 4 files changed, 57 insertions(+) create mode 100644 src/main/java/org/spongepowered/common/data/provider/entity/SalmonData.java diff --git a/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java b/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java index fa239231a98..46fa7017b7e 100644 --- a/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java +++ b/generator/src/main/java/org/spongepowered/vanilla/generator/GeneratorMain.java @@ -57,6 +57,7 @@ import net.minecraft.world.entity.animal.Panda; import net.minecraft.world.entity.animal.Parrot; import net.minecraft.world.entity.animal.Rabbit; +import net.minecraft.world.entity.animal.Salmon; import net.minecraft.world.entity.animal.TropicalFish; import net.minecraft.world.entity.animal.horse.Llama; import net.minecraft.world.entity.animal.horse.Markings; @@ -373,6 +374,13 @@ private static List generators(final Context context) { "getSerializedName", "sponge" ), + new EnumEntriesValidator<>( + "data.type", + "SalmonSizes", + Salmon.Variant.class, + "getSerializedName", + "sponge" + ), new EnumEntriesValidator<>( "world.explosion", "ExplosionBlockInteractions", 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 0741cb7dadb..9f55a53a1ad 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 @@ -101,6 +101,7 @@ public void registerProviders() { PufferfishData.register(this.registrator); RabbitData.register(this.registrator); RavagerData.register(this.registrator); + SalmonData.register(this.registrator); ServerPlayerData.register(this.registrator); SheepData.register(this.registrator); ShulkerBulletData.register(this.registrator); diff --git a/src/main/java/org/spongepowered/common/data/provider/entity/SalmonData.java b/src/main/java/org/spongepowered/common/data/provider/entity/SalmonData.java new file mode 100644 index 00000000000..9dc5a937a6c --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/provider/entity/SalmonData.java @@ -0,0 +1,46 @@ +/* + * 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.world.entity.animal.Salmon; +import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.type.SalmonSize; +import org.spongepowered.common.data.provider.DataProviderRegistrator; + +public final class SalmonData { + + private SalmonData() {} + + // @formatter:off + public static void register(final DataProviderRegistrator registrator) { + registrator + .asMutable(Salmon.class) + .create(Keys.SALMON_SIZE) + .get(h -> (SalmonSize) (Object) h.getVariant()) + .set((h, v) -> h.setVariant((Salmon.Variant) (Object) v)) + ; + } + // @formatter:on +} diff --git a/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java b/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java index 8a2491cc8d2..6b66a6ee5e8 100644 --- a/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java +++ b/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java @@ -44,6 +44,7 @@ import net.minecraft.world.entity.animal.Panda; import net.minecraft.world.entity.animal.Parrot; import net.minecraft.world.entity.animal.Rabbit; +import net.minecraft.world.entity.animal.Salmon; import net.minecraft.world.entity.animal.TropicalFish; import net.minecraft.world.entity.animal.horse.Llama; import net.minecraft.world.entity.animal.horse.Markings; @@ -206,6 +207,7 @@ private void loadEnumRegistries() { this.automaticName(RegistryTypes.WIRE_ATTACHMENT_TYPE, RedstoneSide.values()); this.automaticName(RegistryTypes.ADVANCEMENT_TYPE, AdvancementType.values()); this.automaticName(RegistryTypes.TROPICAL_FISH_SHAPE, TropicalFish.Pattern.values()); + this.automaticName(RegistryTypes.SALMON_SIZE, Salmon.Variant.values()); this.automaticName(RegistryTypes.HEIGHT_TYPE, Heightmap.Types.values()); this.automaticName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values()); this.automaticName(RegistryTypes.WALL_CONNECTION_STATE, WallSide.values());