From 007abba2ecf0fd8dca702991dba3ea5da328ffdf Mon Sep 17 00:00:00 2001 From: Gabriel Harris-Rouquette Date: Wed, 15 Sep 2021 08:41:25 -0700 Subject: [PATCH] Add EntityCategory to API Signed-off-by: Gabriel Harris-Rouquette --- SpongeAPI | 2 +- .../registry/VanillaRegistryLoader.java | 2 + .../world/entity/MobCategoryMixin_API.java | 47 +++++++++++++++++++ src/mixins/resources/mixins.sponge.api.json | 3 +- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/MobCategoryMixin_API.java diff --git a/SpongeAPI b/SpongeAPI index e19cdcb70e9..a67a89fd62e 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit e19cdcb70e950a8452e36807cecc75887bc2ad5e +Subproject commit a67a89fd62e282231adbc724f8800d0715e2f93c diff --git a/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java b/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java index 2dd8da78933..fc3abb1c7e5 100644 --- a/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java +++ b/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java @@ -33,6 +33,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.HumanoidArm; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.animal.Fox; import net.minecraft.world.entity.animal.MushroomCow; @@ -206,6 +207,7 @@ private void loadEnumRegistries() { this.knownName(RegistryTypes.BANNER_PATTERN_SHAPE, BannerPattern.values(), b -> ((BannerPatternAccessor) (Object) b).accessor$filename()); this.automaticName(RegistryTypes.TROPICAL_FISH_SHAPE, TropicalFish.Pattern.values()); this.automaticName(RegistryTypes.HEIGHT_TYPE, Heightmap.Types.values()); + this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), MobCategory::getName); } private static RegistryLoader criterion() { diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/MobCategoryMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/MobCategoryMixin_API.java new file mode 100644 index 00000000000..efa79ed93ca --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/MobCategoryMixin_API.java @@ -0,0 +1,47 @@ +/* + * 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; + +import net.minecraft.world.entity.MobCategory; +import org.spongepowered.api.entity.EntityCategory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(MobCategory.class) +public abstract class MobCategoryMixin_API implements EntityCategory { + + @Shadow public abstract boolean shadow$isFriendly(); + @Shadow public abstract int shadow$getDespawnDistance(); + + @Override + public boolean friendly() { + return this.shadow$isFriendly(); + } + + @Override + public int despawnDistance() { + return this.shadow$getDespawnDistance(); + } +} diff --git a/src/mixins/resources/mixins.sponge.api.json b/src/mixins/resources/mixins.sponge.api.json index 72b839a3fb5..20e74cccf73 100644 --- a/src/mixins/resources/mixins.sponge.api.json +++ b/src/mixins/resources/mixins.sponge.api.json @@ -83,6 +83,7 @@ "minecraft.world.entity.HumanoidArmMixin_API", "minecraft.world.entity.LightningBoltMixin_API", "minecraft.world.entity.LivingEntityMixin_API", + "minecraft.world.entity.MobCategoryMixin_API", "minecraft.world.entity.MobMixin_API", "minecraft.world.entity.PathfinderMobMixin_API", "minecraft.world.entity.TamableAnimalMixin_API", @@ -182,8 +183,8 @@ "minecraft.world.entity.monster.PatrollingMonsterMixin_API", "minecraft.world.entity.monster.Phantom_AttackPhaseMixin_API", "minecraft.world.entity.monster.PhantomMixin_API", - "minecraft.world.entity.monster.PiglinMixin_API", "minecraft.world.entity.monster.PiglinBruteMixin_API", + "minecraft.world.entity.monster.PiglinMixin_API", "minecraft.world.entity.monster.PillagerMixin_API", "minecraft.world.entity.monster.RangedAttackMobMixin_API", "minecraft.world.entity.monster.RavagerMixin_API",