Skip to content

Commit 1993b88

Browse files
authored
Refactor breedable and ageable entities (#2549)
1 parent c7d825a commit 1993b88

File tree

7 files changed

+70
-30
lines changed

7 files changed

+70
-30
lines changed

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import org.spongepowered.api.effect.potion.PotionEffectTypes;
110110
import org.spongepowered.api.effect.sound.SoundType;
111111
import org.spongepowered.api.effect.sound.music.MusicDisc;
112+
import org.spongepowered.api.entity.Ageable;
112113
import org.spongepowered.api.entity.AreaEffectCloud;
113114
import org.spongepowered.api.entity.Entity;
114115
import org.spongepowered.api.entity.EntityArchetype;
@@ -132,7 +133,6 @@
132133
import org.spongepowered.api.entity.hanging.ItemFrame;
133134
import org.spongepowered.api.entity.hanging.LeashKnot;
134135
import org.spongepowered.api.entity.hanging.Painting;
135-
import org.spongepowered.api.entity.living.Ageable;
136136
import org.spongepowered.api.entity.living.Agent;
137137
import org.spongepowered.api.entity.living.ArmorStand;
138138
import org.spongepowered.api.entity.living.Bat;
@@ -1533,7 +1533,7 @@ public final class Keys {
15331533
public static final Key<Value<Boolean>> IN_WALL = Keys.key(ResourceKey.sponge("in_wall"), Boolean.class);
15341534

15351535
/**
1536-
* Whether an {@link Ageable} is considered an adult.
1536+
* Whether a {@link Living} is considered an adult.
15371537
*/
15381538
public static final Key<Value<Boolean>> IS_ADULT = Keys.key(ResourceKey.sponge("is_adult"), Boolean.class);
15391539

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.data.Keys;
28+
import org.spongepowered.api.data.value.Value;
29+
import org.spongepowered.api.util.Ticks;
30+
31+
import java.util.Optional;
32+
33+
/**
34+
* Represents an {@link Entity} that can age
35+
*/
36+
public interface Ageable extends Entity {
37+
38+
/**
39+
* {@link Keys#BABY_TICKS}
40+
*
41+
* @return The ticks until this entity turns into an adult
42+
*/
43+
default Optional<Value.Mutable<Ticks>> babyTicks() {
44+
return this.getValue(Keys.BABY_TICKS).map(Value::asMutable);
45+
}
46+
47+
}

src/main/java/org/spongepowered/api/entity/living/Ageable.java renamed to src/main/java/org/spongepowered/api/entity/Breedable.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
package org.spongepowered.api.entity.living;
25+
package org.spongepowered.api.entity;
2626

2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.value.Value;
@@ -31,28 +31,9 @@
3131
import java.util.Optional;
3232

3333
/**
34-
* Represents an {@link Agent} that produces offspring and grows into an adult
34+
* Represents an {@link Entity} which can breed.
3535
*/
36-
public interface Ageable extends Agent {
37-
38-
/**
39-
* {@link Keys#IS_ADULT}
40-
*
41-
* @return Whether this entity is an adult or not
42-
*/
43-
default Value.Mutable<Boolean> adult() {
44-
return this.requireValue(Keys.IS_ADULT).asMutable();
45-
}
46-
47-
/**
48-
* {@link Keys#BABY_TICKS}
49-
*
50-
* @return The ticks until this entity turns into an adult
51-
*/
52-
default Optional<Value.Mutable<Ticks>> babyTicks() {
53-
return this.getValue(Keys.BABY_TICKS).map(Value::asMutable);
54-
}
55-
36+
public interface Breedable extends Entity {
5637
/**
5738
* {@link Keys#CAN_BREED}
5839
*
@@ -70,5 +51,4 @@ default Value.Mutable<Boolean> canBreed() {
7051
default Optional<Value.Mutable<Ticks>> breedingCooldown() {
7152
return this.getValue(Keys.BREEDING_COOLDOWN).map(Value::asMutable);
7253
}
73-
7454
}

src/main/java/org/spongepowered/api/entity/living/Living.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ default Value.Mutable<Double> health() {
7474
return this.requireValue(Keys.HEALTH).asMutable();
7575
}
7676

77+
/**
78+
* {@link Keys#IS_ADULT}
79+
*
80+
* @return Whether this entity is an adult or not
81+
*/
82+
default Value.Mutable<Boolean> adult() {
83+
return this.requireValue(Keys.IS_ADULT).asMutable();
84+
}
85+
7786
/**
7887
* {@link Keys#MAX_HEALTH}
7988
*

src/main/java/org/spongepowered/api/entity/living/animal/Animal.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.value.Value;
29+
import org.spongepowered.api.entity.Ageable;
30+
import org.spongepowered.api.entity.Breedable;
2931
import org.spongepowered.api.entity.EntityType;
30-
import org.spongepowered.api.entity.living.Ageable;
32+
import org.spongepowered.api.entity.living.PathfinderAgent;
3133
import org.spongepowered.api.entity.living.animal.cow.Cow;
3234
import org.spongepowered.api.item.inventory.ItemStack;
3335

@@ -37,7 +39,7 @@
3739
/**
3840
* Represents an animal, such as a {@link Cow}.
3941
*/
40-
public interface Animal extends Ageable {
42+
public interface Animal extends PathfinderAgent, Ageable, Breedable {
4143

4244
/**
4345
* {@link Keys#BREEDER}

src/main/java/org/spongepowered/api/entity/living/trader/VillagerLike.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
*/
2525
package org.spongepowered.api.entity.living.trader;
2626

27-
import org.spongepowered.api.entity.living.Ageable;
27+
import org.spongepowered.api.entity.Ageable;
28+
import org.spongepowered.api.entity.Breedable;
29+
import org.spongepowered.api.entity.living.PathfinderAgent;
2830
import org.spongepowered.api.item.merchant.Merchant;
2931

3032
/**
3133
* An abstract representation of a Villager.
3234
*/
33-
public interface VillagerLike extends Ageable, Merchant {
35+
public interface VillagerLike extends PathfinderAgent, Ageable, Breedable, Merchant {
3436
}

src/main/java/org/spongepowered/api/event/entity/BreedingEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
*/
2525
package org.spongepowered.api.event.entity;
2626

27+
import org.spongepowered.api.entity.Ageable;
2728
import org.spongepowered.api.entity.Entity;
28-
import org.spongepowered.api.entity.living.Ageable;
2929
import org.spongepowered.api.entity.living.animal.Animal;
3030
import org.spongepowered.api.event.Cancellable;
3131
import org.spongepowered.api.event.Event;

0 commit comments

Comments
 (0)