|
| 1 | +// Copyright (c) BlueLib. Licensed under the MIT License. |
| 2 | +package software.bluelib.interfaces.entity; |
| 3 | + |
| 4 | +import net.minecraft.core.BlockPos; |
| 5 | +import net.minecraft.world.entity.LivingEntity; |
| 6 | +import net.minecraft.world.entity.ai.attributes.AttributeInstance; |
| 7 | +import net.minecraft.world.entity.ai.attributes.Attributes; |
| 8 | +import software.bluelib.entity.EntityStateManager; |
| 9 | +import software.bluelib.utils.logging.BaseLogLevel; |
| 10 | +import software.bluelib.utils.logging.BaseLogger; |
| 11 | + |
| 12 | +/** |
| 13 | + * An interface for flying entities in the BlueLib library. |
| 14 | + * <p> |
| 15 | + * Purpose: This interface defines some basic methods for managing the behavior, state, and properties of entities capable of flight.<br> |
| 16 | + * When: These methods are invoked during interactions or gameplay mechanics for flying entities.<br> |
| 17 | + * Where: This interface is implemented by entities that are capable of flying.<br> |
| 18 | + * Additional Info: The interface provides default implementations for common flying-related features such as flight state, speed, and altitude.<br> |
| 19 | + * </p> |
| 20 | + * Key Methods: |
| 21 | + * <ul> |
| 22 | + * <li>{@link #getFlyingState(LivingEntity)} - Retrieves the flying state of the entity.</li> |
| 23 | + * <li>{@link #setFlyingState(LivingEntity, boolean)} - Sets the flying state of the entity.</li> |
| 24 | + * <li>{@link #getFlyingSpeedMultiplier(LivingEntity)} - Retrieves the speed multiplier for the entity while flying.</li> |
| 25 | + * <li>{@link #setFlyingSpeedMultiplier(LivingEntity, double)} - Sets the speed multiplier for the entity while flying.</li> |
| 26 | + * <li>{@link #canFly(LivingEntity)} - Checks if the entity is capable of flight.</li> |
| 27 | + * <li>{@link #getFlightCooldown(LivingEntity)} - Retrieves the cooldown period between flights.</li> |
| 28 | + * <li>{@link #setFlightCooldown(LivingEntity, int)} - Sets the cooldown period between flights.</li> |
| 29 | + * <li>{@link #getAltitude(LivingEntity)} - Retrieves the current altitude of the entity.</li> |
| 30 | + * </ul> |
| 31 | + * |
| 32 | + * @author Kyradjis |
| 33 | + * @version 1.7.0 |
| 34 | + * @see EntityStateManager |
| 35 | + * @see LivingEntity |
| 36 | + * @since 1.7.0 |
| 37 | + */ |
| 38 | +@SuppressWarnings("unused") |
| 39 | +public interface IFlyingEntity { |
| 40 | + |
| 41 | + /** |
| 42 | + * Retrieves the flying state of the entity. |
| 43 | + * <p> |
| 44 | + * Purpose: Indicates whether the entity is currently flying.<br> |
| 45 | + * When: Called to check the entity's current flight status.<br> |
| 46 | + * Where: Used in interaction logic for flying behavior.<br> |
| 47 | + * Additional Info: The library does not enforce the flying state; it is up to the developer to manage the flying state.<br> |
| 48 | + * </p> |
| 49 | + * |
| 50 | + * @return {@code true} if the entity is flying; {@code false} otherwise. |
| 51 | + * @see EntityStateManager |
| 52 | + * @see LivingEntity |
| 53 | + * @since 1.7.0 |
| 54 | + */ |
| 55 | + default boolean getFlyingState(LivingEntity pEntity) { |
| 56 | + return EntityStateManager.getFlyingState(pEntity); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Sets the flying state of the entity. |
| 61 | + * <p> |
| 62 | + * Purpose: Updates the entity's state to indicate whether it is flying.<br> |
| 63 | + * When: Invoked during gameplay or AI behavior changes.<br> |
| 64 | + * Where: Used in methods controlling flight mechanics.<br> |
| 65 | + * Additional Info: The library does not enforce the flying state; it is up to the developer to manage the flying state.<br> |
| 66 | + * </p> |
| 67 | + * |
| 68 | + * @param pFlying {@code true} to set the entity as flying; {@code false} otherwise. |
| 69 | + * @see EntityStateManager |
| 70 | + * @see LivingEntity |
| 71 | + * @since 1.7.0 |
| 72 | + */ |
| 73 | + default void setFlyingState(LivingEntity pEntity, boolean pFlying) { |
| 74 | + EntityStateManager.setFlyingState(pEntity, pFlying); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Retrieves the flying speed multiplier for the entity. |
| 79 | + * <p> |
| 80 | + * Purpose: Determines the speed multiplier applied when the entity is flying.<br> |
| 81 | + * When: Called during movement calculations for flying entities.<br> |
| 82 | + * Where: Used in movement logic.<br> |
| 83 | + * </p> |
| 84 | + * |
| 85 | + * @param pEntity The entity for which to retrieve the flying speed multiplier. |
| 86 | + * @return The flying speed multiplier as a {@code double}. |
| 87 | + * @author Kyradjis |
| 88 | + * @see EntityStateManager |
| 89 | + * @see LivingEntity |
| 90 | + * @since 1.7.0 |
| 91 | + */ |
| 92 | + default double getFlyingSpeedMultiplier(LivingEntity pEntity) { |
| 93 | + return pEntity.getAttributeValue(Attributes.FLYING_SPEED); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Sets the flying speed multiplier for the entity. |
| 98 | + * <p> |
| 99 | + * Purpose: Updates the speed multiplier applied when the entity is flying.<br> |
| 100 | + * When: Invoked during gameplay or entity configuration.<br> |
| 101 | + * Where: Used in methods controlling movement mechanics.<br> |
| 102 | + * </p> |
| 103 | + * |
| 104 | + * @param pEntity The entity for which to set the flying speed multiplier. |
| 105 | + * @param pSpeedMultiplier The flying speed multiplier as a {@code double}. |
| 106 | + * @author Kyradjis |
| 107 | + * @see EntityStateManager |
| 108 | + * @see LivingEntity |
| 109 | + * @since 1.7.0 |
| 110 | + */ |
| 111 | + default void setFlyingSpeedMultiplier(LivingEntity pEntity, double pSpeedMultiplier) { |
| 112 | + AttributeInstance flyingSpeedAttribute = pEntity.getAttribute(Attributes.FLYING_SPEED); |
| 113 | + if (flyingSpeedAttribute != null) { |
| 114 | + flyingSpeedAttribute.setBaseValue(pSpeedMultiplier); |
| 115 | + } else { |
| 116 | + BaseLogger.log(BaseLogLevel.ERROR, pEntity + " does not have a flying speed attribute.", true); |
| 117 | + throw new IllegalStateException(pEntity + " does not have a flying speed attribute."); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Checks if the entity is capable of flight. |
| 123 | + * <p> |
| 124 | + * Purpose: Determines whether the entity has the ability to fly.<br> |
| 125 | + * When: Called to validate the entity's flight capabilities.<br> |
| 126 | + * Where: Used in AI or interaction logic involving flight.<br> |
| 127 | + * Additional Info: The library does not enforce the flying ability; it is up to the developer to manage the flying ability.<br> |
| 128 | + * </p> |
| 129 | + * |
| 130 | + * @return {@code true} if the entity can fly; {@code false} otherwise (e.g., when the entity is a baby). |
| 131 | + * @author Kyradjis |
| 132 | + * @see EntityStateManager |
| 133 | + * @see LivingEntity |
| 134 | + * @since 1.7.0 |
| 135 | + */ |
| 136 | + default boolean canFly(LivingEntity pEntity) { |
| 137 | + return EntityStateManager.getCanFly(pEntity); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Sets whether the entity can fly. |
| 142 | + * <p> |
| 143 | + * Purpose: Updates the entity's ability to fly.<br> |
| 144 | + * When: Invoked during gameplay or entity configuration.<br> |
| 145 | + * Where: Used in methods controlling flight mechanics.<br> |
| 146 | + * Additional Info: The library does not enforce the flying ability; it is up to the developer to manage the flying ability.<br> |
| 147 | + * </p> |
| 148 | + * |
| 149 | + * @param pCanFly {@code true} to enable flight for the entity; {@code false} otherwise. |
| 150 | + * @author MeAlam |
| 151 | + * @see EntityStateManager |
| 152 | + * @see LivingEntity |
| 153 | + * @since 1.7.0 |
| 154 | + */ |
| 155 | + default void canFly(LivingEntity pEntity, boolean pCanFly) { |
| 156 | + EntityStateManager.setCanFly(pEntity, pCanFly); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Retrieves the cooldown period between flights for the entity. |
| 161 | + * <p> |
| 162 | + * Purpose: Indicates the amount of time (in seconds) the entity must wait before flying again.<br> |
| 163 | + * When: Called during flight cooldown checks.<br> |
| 164 | + * Where: Used in gameplay mechanics.<br> |
| 165 | + * Additional Info: The library does not enforce the cooldown period; it is up to the developer to manage flight cooldowns.<br> |
| 166 | + * </p> |
| 167 | + * |
| 168 | + * @return The flight cooldown period (in seconds) as an {@code int}. |
| 169 | + * @author Kyradjis |
| 170 | + * @see EntityStateManager |
| 171 | + * @see LivingEntity |
| 172 | + * @since 1.7.0 |
| 173 | + */ |
| 174 | + default int getFlightCooldown(LivingEntity pEntity) { |
| 175 | + return EntityStateManager.getFlyingCooldown(pEntity); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Sets the cooldown period between flights for the entity. |
| 180 | + * <p> |
| 181 | + * Purpose: Updates the amount of time (in seconds) the entity must wait before flying again.<br> |
| 182 | + * When: Invoked during gameplay or entity configuration.<br> |
| 183 | + * Where: Used in cooldown management logic.<br> |
| 184 | + * Additional Info: The library does not enforce the cooldown period; it is up to the developer to manage flight cooldowns.<br> |
| 185 | + * </p> |
| 186 | + * |
| 187 | + * @param pFlightCooldown The flight cooldown period (in seconds) as an {@code int}. |
| 188 | + * @author Kyradjis |
| 189 | + * @see EntityStateManager |
| 190 | + * @see LivingEntity |
| 191 | + * @since 1.7.0 |
| 192 | + */ |
| 193 | + default void setFlightCooldown(LivingEntity pEntity, int pFlightCooldown) { |
| 194 | + EntityStateManager.setFlyingCooldown(pEntity, pFlightCooldown); |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Retrieves the current altitude of the entity. |
| 199 | + * <p> |
| 200 | + * Purpose: Indicates the current height of the entity above the ground (measured in blocks).<br> |
| 201 | + * When: Called during calculations or checks involving altitude.<br> |
| 202 | + * Where: Used in AI and movement logic.<br> |
| 203 | + * </p> |
| 204 | + * |
| 205 | + * @return The current altitude (in blocks) of the entity as an {@code int}. |
| 206 | + * @author Kyradjis |
| 207 | + * @see EntityStateManager |
| 208 | + * @see LivingEntity |
| 209 | + * @since 1.7.0 |
| 210 | + */ |
| 211 | + default int getAltitude(LivingEntity pEntity) { |
| 212 | + BlockPos blockPos = pEntity.getOnPos(); |
| 213 | + return blockPos.getY(); |
| 214 | + } |
| 215 | +} |
0 commit comments