From 269f318306b6eac81c133003817d446e83b7fe5f Mon Sep 17 00:00:00 2001 From: ImMorpheus Date: Sun, 30 Jun 2024 12:57:58 +0200 Subject: [PATCH 1/2] Use Aerial to abstract flying trait --- .../api/entity/{living => }/Aerial.java | 17 ++++++++++++++--- .../spongepowered/api/entity/living/Bat.java | 1 + .../api/entity/living/animal/Bee.java | 4 +++- .../api/entity/living/animal/Parrot.java | 3 ++- .../api/entity/living/monster/Blaze.java | 2 +- .../api/entity/living/monster/Ghast.java | 2 +- .../api/entity/living/monster/Phantom.java | 3 +-- .../api/entity/living/monster/boss/Wither.java | 2 +- .../living/monster/boss/dragon/EnderDragon.java | 2 +- .../api/entity/living/player/Player.java | 12 ++---------- 10 files changed, 27 insertions(+), 21 deletions(-) rename src/main/java/org/spongepowered/api/entity/{living => }/Aerial.java (74%) diff --git a/src/main/java/org/spongepowered/api/entity/living/Aerial.java b/src/main/java/org/spongepowered/api/entity/Aerial.java similarity index 74% rename from src/main/java/org/spongepowered/api/entity/living/Aerial.java rename to src/main/java/org/spongepowered/api/entity/Aerial.java index 3aa7abe37d6..da170edb1d9 100644 --- a/src/main/java/org/spongepowered/api/entity/living/Aerial.java +++ b/src/main/java/org/spongepowered/api/entity/Aerial.java @@ -22,11 +22,22 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.api.entity.living; +package org.spongepowered.api.entity; + +import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.value.Value; /** - * Represents an entity that flies, such as a bat. + * Represents an {@link Entity} which can fly. */ -public interface Aerial extends Agent { +public interface Aerial extends Entity { + /** + * {@link Keys#IS_FLYING} + * + * @return Whether the entity is flying + */ + default Value.Mutable flying() { + return this.requireValue(Keys.IS_FLYING).asMutable(); + } } diff --git a/src/main/java/org/spongepowered/api/entity/living/Bat.java b/src/main/java/org/spongepowered/api/entity/living/Bat.java index fcaf5f0801c..988997bd939 100644 --- a/src/main/java/org/spongepowered/api/entity/living/Bat.java +++ b/src/main/java/org/spongepowered/api/entity/living/Bat.java @@ -26,6 +26,7 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.value.Value; +import org.spongepowered.api.entity.Aerial; /** * Represents a Bat. diff --git a/src/main/java/org/spongepowered/api/entity/living/animal/Bee.java b/src/main/java/org/spongepowered/api/entity/living/animal/Bee.java index cb8dccbb199..ea611d361f6 100644 --- a/src/main/java/org/spongepowered/api/entity/living/animal/Bee.java +++ b/src/main/java/org/spongepowered/api/entity/living/animal/Bee.java @@ -24,8 +24,10 @@ */ package org.spongepowered.api.entity.living.animal; +import org.spongepowered.api.entity.Aerial; + /** * Represents a Bee. */ -public interface Bee extends Animal { +public interface Bee extends Animal, Aerial { } diff --git a/src/main/java/org/spongepowered/api/entity/living/animal/Parrot.java b/src/main/java/org/spongepowered/api/entity/living/animal/Parrot.java index 4e135df319a..559d1fd2966 100644 --- a/src/main/java/org/spongepowered/api/entity/living/animal/Parrot.java +++ b/src/main/java/org/spongepowered/api/entity/living/animal/Parrot.java @@ -27,11 +27,12 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.ParrotType; import org.spongepowered.api.data.value.Value; +import org.spongepowered.api.entity.Aerial; /** * Represents a Parrot. */ -public interface Parrot extends TameableAnimal { +public interface Parrot extends TameableAnimal, Aerial { /** * {@link Keys#PARROT_TYPE} diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/Blaze.java b/src/main/java/org/spongepowered/api/entity/living/monster/Blaze.java index 483eb9cd569..8eeecd67504 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/Blaze.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/Blaze.java @@ -26,7 +26,7 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.value.Value; -import org.spongepowered.api.entity.living.Aerial; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.living.Monster; import org.spongepowered.api.entity.living.Ranger; diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/Ghast.java b/src/main/java/org/spongepowered/api/entity/living/monster/Ghast.java index f9a35cb2afb..7e4715c3bd5 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/Ghast.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/Ghast.java @@ -24,7 +24,7 @@ */ package org.spongepowered.api.entity.living.monster; -import org.spongepowered.api.entity.living.Aerial; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.living.Hostile; import org.spongepowered.api.entity.living.Ranger; diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java b/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java index 05fcda04555..559902fd46c 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java @@ -27,8 +27,7 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.PhantomPhase; import org.spongepowered.api.data.value.Value; -import org.spongepowered.api.entity.living.Aerial; -import org.spongepowered.api.entity.living.Creature; +import org.spongepowered.api.entity.Aerial; public interface Phantom extends Aerial, Creature { diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/boss/Wither.java b/src/main/java/org/spongepowered/api/entity/living/monster/boss/Wither.java index 233a39d1c45..4b305a6ae88 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/boss/Wither.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/boss/Wither.java @@ -26,9 +26,9 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.value.ListValue; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.explosive.fused.FusedExplosive; -import org.spongepowered.api.entity.living.Aerial; import org.spongepowered.api.entity.living.Monster; import org.spongepowered.api.entity.living.Ranger; diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/boss/dragon/EnderDragon.java b/src/main/java/org/spongepowered/api/entity/living/monster/boss/dragon/EnderDragon.java index 18e86c5e388..d6836cf2efc 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/boss/dragon/EnderDragon.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/boss/dragon/EnderDragon.java @@ -26,8 +26,8 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.value.Value; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.explosive.EndCrystal; -import org.spongepowered.api.entity.living.Aerial; import org.spongepowered.api.entity.living.ComplexLiving; import org.spongepowered.api.entity.living.Monster; import org.spongepowered.api.entity.living.Ranger; diff --git a/src/main/java/org/spongepowered/api/entity/living/player/Player.java b/src/main/java/org/spongepowered/api/entity/living/player/Player.java index 977601a8f48..db6520037c5 100644 --- a/src/main/java/org/spongepowered/api/entity/living/player/Player.java +++ b/src/main/java/org/spongepowered/api/entity/living/player/Player.java @@ -30,6 +30,7 @@ import org.spongepowered.api.data.type.HandPreference; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.effect.Viewer; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.living.Humanoid; import org.spongepowered.api.item.inventory.Carrier; import org.spongepowered.api.item.inventory.Inventory; @@ -40,7 +41,7 @@ /** * A Player is the representation of an actual unit playing the game. */ -public interface Player extends Humanoid, Identified, LocaleSource, Viewer, Carrier { +public interface Player extends Humanoid, Identified, LocaleSource, Viewer, Carrier, Aerial { /** * Gets the associated {@link GameProfile} of this player. @@ -155,15 +156,6 @@ default Value.Mutable foodLevel() { return this.requireValue(Keys.FOOD_LEVEL).asMutable(); } - /** - * {@link Keys#IS_FLYING} - * - * @return Whether the entity is flying - */ - default Value.Mutable flying() { - return this.requireValue(Keys.IS_FLYING).asMutable(); - } - /** * {@link Keys#IS_SLEEPING} * From 1dbbba44f69d5f95d23d4af9d523af25e4ca3153 Mon Sep 17 00:00:00 2001 From: Morpheus Date: Sun, 30 Jun 2024 11:40:00 +0000 Subject: [PATCH 2/2] Update Phantom.java --- .../org/spongepowered/api/entity/living/monster/Phantom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java b/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java index 8c3791ac2d5..2f10acb5b50 100644 --- a/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java +++ b/src/main/java/org/spongepowered/api/entity/living/monster/Phantom.java @@ -27,7 +27,7 @@ import org.spongepowered.api.data.Keys; import org.spongepowered.api.data.type.PhantomPhase; import org.spongepowered.api.data.value.Value; -import org.spongepowered.api.entity.living.Aerial; +import org.spongepowered.api.entity.Aerial; import org.spongepowered.api.entity.living.Agent; public interface Phantom extends Agent, Aerial {