Skip to content

Commit 6c74286

Browse files
committed
Add EntityCategory to API
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
1 parent 1b2527e commit 6c74286

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.entity;
26+
27+
import org.spongepowered.api.ResourceKey;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.registry.DefaultedRegistryReference;
30+
import org.spongepowered.api.registry.RegistryKey;
31+
import org.spongepowered.api.registry.RegistryTypes;
32+
33+
public final class EntityCategories {
34+
35+
//@formatter:off
36+
37+
public static final DefaultedRegistryReference<EntityCategory> MONSTER = EntityCategories.key(ResourceKey.sponge("monster"));
38+
39+
public static final DefaultedRegistryReference<EntityCategory> CREATURE = EntityCategories.key(ResourceKey.sponge("creature"));
40+
41+
public static final DefaultedRegistryReference<EntityCategory> AMBIENT = EntityCategories.key(ResourceKey.sponge("ambient"));
42+
43+
public static final DefaultedRegistryReference<EntityCategory> WATER_CREATURE = EntityCategories.key(ResourceKey.sponge("water_creature"));
44+
45+
public static final DefaultedRegistryReference<EntityCategory> WATER_AMBIENT = EntityCategories.key(ResourceKey.sponge("water_ambient"));
46+
47+
public static final DefaultedRegistryReference<EntityCategory> MISCELLANEOUS = EntityCategories.key(ResourceKey.sponge("misc"));
48+
49+
//@formatter:on
50+
51+
private EntityCategories() {
52+
throw new AssertionError("You should not be attempting to instantiate this class.");
53+
}
54+
55+
private static DefaultedRegistryReference<EntityCategory> key(final ResourceKey location) {
56+
return RegistryKey.of(RegistryTypes.ENTITY_CATEGORY, location).asDefaultedReference(Sponge::game);
57+
}
58+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.entity;
26+
27+
import org.spongepowered.api.entity.living.animal.Chicken;
28+
import org.spongepowered.api.entity.living.monster.Creeper;
29+
import org.spongepowered.api.entity.living.monster.zombie.Zombie;
30+
import org.spongepowered.api.registry.DefaultedRegistryValue;
31+
import org.spongepowered.api.util.annotation.CatalogedBy;
32+
33+
/**
34+
* A category of entities that conveys a variety of meanings to
35+
* consider a group of entities that may differ in {@link EntityType}
36+
* are the "same category" grouping. Examples can be for monsters
37+
* to include {@link Zombie}, {@link Creeper}, while a creature
38+
* may include {@link Chicken}.
39+
*/
40+
@CatalogedBy(EntityCategories.class)
41+
public interface EntityCategory extends DefaultedRegistryValue {
42+
43+
/**
44+
* Whether this category of entities is considered "friendly".
45+
*
46+
* @return True if this category of entities is friendly
47+
*/
48+
boolean friendly();
49+
50+
/**
51+
* Gets the distance in blocks in which an entity of this category
52+
* may be considered to be despawned/removed from a World if too
53+
* far from a Player.
54+
* <p>Obvious exceptions include when the Entity logic considers
55+
* itself not to be despawnable or owned/permanent by a player,
56+
* function, or plugin thereof.
57+
*
58+
* @return The distance at which entities of this category may be
59+
* considered to be removed if too far from a player
60+
*/
61+
int despawnDistance();
62+
63+
64+
}

src/main/java/org/spongepowered/api/entity/EntityType.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ public interface EntityType<A extends Entity> extends DefaultedRegistryValue, Co
6363
* @return If the type can spawn far away from a player
6464
*/
6565
boolean canSpawnAwayFromPlayer();
66+
67+
/**
68+
* Gets the {@link EntityCategory} of this type.
69+
*
70+
* @return The category of this type
71+
*/
72+
EntityCategory category();
6673
}

src/main/java/org/spongepowered/api/registry/RegistryTypes.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.spongepowered.api.effect.potion.PotionEffectType;
8888
import org.spongepowered.api.effect.sound.SoundType;
8989
import org.spongepowered.api.effect.sound.music.MusicDisc;
90+
import org.spongepowered.api.entity.EntityCategory;
9091
import org.spongepowered.api.entity.EntityType;
9192
import org.spongepowered.api.entity.ai.goal.GoalExecutorType;
9293
import org.spongepowered.api.entity.ai.goal.GoalType;
@@ -134,7 +135,6 @@
134135
import org.spongepowered.api.statistic.StatisticCategory;
135136
import org.spongepowered.api.tag.Tag;
136137
import org.spongepowered.api.tag.TagType;
137-
import org.spongepowered.api.tag.TagTypes;
138138
import org.spongepowered.api.util.mirror.Mirror;
139139
import org.spongepowered.api.util.orientation.Orientation;
140140
import org.spongepowered.api.util.rotation.Rotation;
@@ -182,6 +182,8 @@ public final class RegistryTypes {
182182

183183
public static final DefaultedRegistryType<EnchantmentType> ENCHANTMENT_TYPE = RegistryTypes.minecraftKeyInGame("enchantment");
184184

185+
public static final DefaultedRegistryType<EntityCategory> ENTITY_CATEGORY = RegistryTypes.spongeKeyInGame("mob_category");
186+
185187
public static final DefaultedRegistryType<EntityType<@NonNull ?>> ENTITY_TYPE = RegistryTypes.minecraftKeyInGame("entity_type");
186188

187189
public static final DefaultedRegistryType<FluidType> FLUID_TYPE = RegistryTypes.minecraftKeyInGame("fluid");

0 commit comments

Comments
 (0)