11package net .darkhax .bookshelf .api .util ;
22
3- import java .util .HashMap ;
4- import java .util .HashSet ;
5- import java .util .List ;
6- import java .util .Map ;
7- import java .util .Set ;
8-
93import net .minecraft .core .BlockPos ;
104import net .minecraft .core .Direction ;
115import net .minecraft .util .Tuple ;
2822import net .minecraft .world .phys .HitResult ;
2923import net .minecraft .world .phys .Vec3 ;
3024
25+ import java .util .HashMap ;
26+ import java .util .HashSet ;
27+ import java .util .List ;
28+ import java .util .Map ;
29+ import java .util .Set ;
30+
3131public final class EntityUtils {
3232
3333 /**
34- * A cache of spawn egg colors mapped to the entity type. Populated by
35- * {@link #getEggColors(EntityType)}.
34+ * A cache of spawn egg colors mapped to the entity type. Populated by {@link #getEggColors(EntityType)}.
3635 */
37- private static Map <EntityType <?>, Tuple <Integer , Integer >> eggColorCache = new HashMap <>();
36+ private static final Map <EntityType <?>, Tuple <Integer , Integer >> eggColorCache = new HashMap <>();
3837
3938 /**
4039 * Calculates the distance between two entities.
4140 *
42- * @param firstEntity The first entity to use.
41+ * @param firstEntity The first entity to use.
4342 * @param secondEntity The second entity to use.
4443 * @return double The distance between the two entities passed.
4544 */
46- public static double getDistanceFromEntity (Entity firstEntity , Entity secondEntity ) {
45+ public static double getDistanceFromEntity (Entity firstEntity , Entity secondEntity ) {
4746
4847 return MathsUtils .getDistanceBetweenPoints (firstEntity .position (), secondEntity .position ());
4948 }
@@ -52,10 +51,10 @@ public static double getDistanceFromEntity (Entity firstEntity, Entity secondEnt
5251 * Calculates the distance between an entity and a BlockPos.
5352 *
5453 * @param entity The Entity to use for the first position.
55- * @param pos The BlockPos to use for the second position.
54+ * @param pos The BlockPos to use for the second position.
5655 * @return double The distance between the Entity and the BlockPos.
5756 */
58- public static double getDistaceFromPos (Entity entity , BlockPos pos ) {
57+ public static double getDistaceFromPos (Entity entity , BlockPos pos ) {
5958
6059 return MathsUtils .getDistanceBetweenPoints (entity .position (), Vec3 .atCenterOf (pos ));
6160 }
@@ -64,10 +63,10 @@ public static double getDistaceFromPos (Entity entity, BlockPos pos) {
6463 * Pushes an entity towards a specific direction.
6564 *
6665 * @param entityToMove The entity that you want to push.
67- * @param direction The direction to push the entity.
68- * @param force The amount of force to push the entity with.
66+ * @param direction The direction to push the entity.
67+ * @param force The amount of force to push the entity with.
6968 */
70- public static void pushTowards (Entity entityToMove , Direction direction , double force ) {
69+ public static void pushTowards (Entity entityToMove , Direction direction , double force ) {
7170
7271 pushTowards (entityToMove , entityToMove .blockPosition ().relative (direction .getOpposite (), 1 ), force );
7372 }
@@ -76,10 +75,10 @@ public static void pushTowards (Entity entityToMove, Direction direction, double
7675 * Pushes an Entity towards a BlockPos.
7776 *
7877 * @param entityToMove The entity that you want to push.
79- * @param pos The BlockPos to push the entity towards.
80- * @param force The amount of force to push the entity with.
78+ * @param pos The BlockPos to push the entity towards.
79+ * @param force The amount of force to push the entity with.
8180 */
82- public static void pushTowards (Entity entityToMove , BlockPos pos , double force ) {
81+ public static void pushTowards (Entity entityToMove , BlockPos pos , double force ) {
8382
8483 final BlockPos entityPos = entityToMove .blockPosition ();
8584 final double distanceX = (double ) pos .getX () - entityPos .getX ();
@@ -96,11 +95,10 @@ public static void pushTowards (Entity entityToMove, BlockPos pos, double force)
9695 * Pushes an entity towards another one.
9796 *
9897 * @param entityToMove The entity that should be pushed towards the other entity.
99- * @param destination The destination entity, that the entity to move should be pushed
100- * towards.
101- * @param force The amount of force to push the entityToMove with.
98+ * @param destination The destination entity, that the entity to move should be pushed towards.
99+ * @param force The amount of force to push the entityToMove with.
102100 */
103- public static void pushTowards (Entity entityToMove , Entity destination , double force ) {
101+ public static void pushTowards (Entity entityToMove , Entity destination , double force ) {
104102
105103 final double distanceX = destination .getX () - entityToMove .getX ();
106104 final double distanceY = destination .getY () - entityToMove .getY ();
@@ -113,15 +111,14 @@ public static void pushTowards (Entity entityToMove, Entity destination, double
113111 }
114112
115113 /**
116- * Creates a Vector3d that represents the additional motion that would be needed to push an
117- * entity towards a destination.
114+ * Creates a Vector3d that represents the additional motion that would be needed to push an entity towards a
115+ * destination.
118116 *
119117 * @param entityToMove The entity to push.
120- * @param direction The direction to push the entity.
121- * @param force The amount of force to use.
122- *
118+ * @param direction The direction to push the entity.
119+ * @param force The amount of force to use.
123120 */
124- public static void pushTowardsDirection (Entity entityToMove , Direction direction , double force ) {
121+ public static void pushTowardsDirection (Entity entityToMove , Direction direction , double force ) {
125122
126123 final BlockPos entityPos = entityToMove .blockPosition ();
127124 final BlockPos destination = entityToMove .blockPosition ().relative (direction .getOpposite (), 1 );
@@ -139,57 +136,56 @@ public static void pushTowardsDirection (Entity entityToMove, Direction directio
139136 /**
140137 * Checks if two entities are close enough together.
141138 *
142- * @param firstEntity The first entity to check.
139+ * @param firstEntity The first entity to check.
143140 * @param secondEntity The second entity to check.
144- * @param maxDistance The maximum distance that the entities can be apart.
145- * @return boolean True if the distance between the entities are within range of the
146- * maxDistance.
141+ * @param maxDistance The maximum distance that the entities can be apart.
142+ * @return boolean True if the distance between the entities are within range of the maxDistance.
147143 */
148- public static boolean areEntitiesCloseEnough (Entity firstEntity , Entity secondEntity , double maxDistance ) {
144+ public static boolean areEntitiesCloseEnough (Entity firstEntity , Entity secondEntity , double maxDistance ) {
149145
150146 return getDistanceFromEntity (firstEntity , secondEntity ) < maxDistance * maxDistance ;
151147 }
152148
153149 /**
154150 * Gets a List of entities that are within the provided area.
155151 *
156- * @param <T> The type of entities to look for.
152+ * @param <T> The type of entities to look for.
157153 * @param entityClass The type of entity you are looking for.
158- * @param world The world to search in.
159- * @param pos The position to start the search around.
160- * @param range The range of the search.
154+ * @param world The world to search in.
155+ * @param pos The position to start the search around.
156+ * @param range The range of the search.
161157 * @return A List containing all entities of the specified type that are within the range.
162158 */
163- public static <T extends Entity > List <T > getEntitiesInArea (Class <T > entityClass , Level world , BlockPos pos , int range ) {
159+ public static <T extends Entity > List <T > getEntitiesInArea (Class <T > entityClass , Level world , BlockPos pos , int range ) {
164160
165161 return getEntitiesInArea (entityClass , world , pos , (float ) range );
166162 }
167163
168164 /**
169165 * Gets a List of entities that are within the provided area.
170166 *
171- * @param <T> The type of entities to look for.
167+ * @param <T> The type of entities to look for.
172168 * @param entityClass The type of entity you are looking for.
173- * @param world The world to search in.
174- * @param pos The position to start the search around.
175- * @param range The range of the search.
169+ * @param world The world to search in.
170+ * @param pos The position to start the search around.
171+ * @param range The range of the search.
176172 * @return A List containing all entities of the specified type that are within the range.
177173 */
178- public static <T extends Entity > List <T > getEntitiesInArea (Class <T > entityClass , Level world , BlockPos pos , float range ) {
174+ public static <T extends Entity > List <T > getEntitiesInArea (Class <T > entityClass , Level world , BlockPos pos , float range ) {
179175
180176 return world .getEntitiesOfClass (entityClass , new AABB (pos .offset (-range , -range , -range ), pos .offset (range + 1 , range + 1 , range + 1 )));
181177 }
182178
183179 /**
184- * A check to see if an entity is wearing a full suit of the armor. This check is based on
185- * the class names of armor.
180+ * A check to see if an entity is wearing a full suit of the armor. This check is based on the class names of
181+ * armor.
186182 *
187- * @param living: The living entity to check the armor of.
183+ * @param living: The living entity to check the armor of.
188184 * @param armorClass: The class of the armor to check against.
189- * @return boolean: True if every piece of armor the entity is wearing are the same class
190- * as the provied armor class.
185+ * @return boolean: True if every piece of armor the entity is wearing are the same class as the provied armor
186+ * class.
191187 */
192- public static boolean isWearingFullSet (Mob living , Class <Item > armorClass ) {
188+ public static boolean isWearingFullSet (Mob living , Class <Item > armorClass ) {
193189
194190 for (final EquipmentSlot slot : EquipmentSlot .values ()) {
195191 if (slot .getType ().equals (EquipmentSlot .Type .ARMOR )) {
@@ -208,13 +204,13 @@ public static boolean isWearingFullSet (Mob living, Class<Item> armorClass) {
208204 /**
209205 * Performs a ray trace for the look vector of an entity.
210206 *
211- * @param entity The entity to perform a ray trace on.
212- * @param length The distance to cast the rays.
207+ * @param entity The entity to perform a ray trace on.
208+ * @param length The distance to cast the rays.
213209 * @param blockMode The mode used when detecting blocks.
214210 * @param fluidMode The mode used when detecting fluids.
215211 * @return An object containing the results of the ray trace.
216212 */
217- public static HitResult rayTrace (LivingEntity entity , double length , Block blockMode , Fluid fluidMode ) {
213+ public static HitResult rayTrace (LivingEntity entity , double length , Block blockMode , Fluid fluidMode ) {
218214
219215 final Vec3 startingPosition = new Vec3 (entity .getX (), entity .getY () + entity .getEyeHeight (), entity .getZ ());
220216 final Vec3 lookVector = entity .getLookAngle ();
@@ -223,27 +219,25 @@ public static HitResult rayTrace (LivingEntity entity, double length, Block bloc
223219 }
224220
225221 /**
226- * Checks if an entity can be affected by fire. While fire immune entities can already
227- * negate the effects of fire doing prechecks using this method can be used to avoid
228- * rendering flickers or filter out these types of entities.
222+ * Checks if an entity can be affected by fire. While fire immune entities can already negate the effects of fire
223+ * doing prechecks using this method can be used to avoid rendering flickers or filter out these types of entities.
229224 *
230225 * @param toCheck The entity to check.
231226 * @return Whether or not this entity can be affected by fire.
232227 */
233- public static boolean isAffectedByFire (LivingEntity toCheck ) {
228+ public static boolean isAffectedByFire (LivingEntity toCheck ) {
234229
235230 return !toCheck .fireImmune () && !toCheck .hasEffect (MobEffects .FIRE_RESISTANCE );
236231 }
237232
238233 /**
239- * Clears potion effect from an entity based on whether or not the effects are positive or
240- * negative.
234+ * Clears potion effect from an entity based on whether or not the effects are positive or negative.
241235 *
242- * @param entity The entity to remove effects from.
236+ * @param entity The entity to remove effects from.
243237 * @param removePositive Should positive effects be cleared?
244238 * @param removeNegative Should negative effects be cleared?
245239 */
246- public static void clearEffects (LivingEntity entity , boolean removePositive , boolean removeNegative ) {
240+ public static void clearEffects (LivingEntity entity , boolean removePositive , boolean removeNegative ) {
247241
248242 final Set <MobEffect > toClear = new HashSet <>();
249243
@@ -264,13 +258,13 @@ public static void clearEffects (LivingEntity entity, boolean removePositive, bo
264258 }
265259
266260 /**
267- * Get the egg color associated with an entity type. If the entity does not have an egg
268- * type this will be 0 for both values.
261+ * Get the egg color associated with an entity type. If the entity does not have an egg type this will be 0 for both
262+ * values.
269263 *
270264 * @param type The entity type to get a color for.
271265 * @return A Tuple containing the primary and secondary egg colors.
272266 */
273- public static Tuple <Integer , Integer > getEggColors (EntityType <?> type ) {
267+ public static Tuple <Integer , Integer > getEggColors (EntityType <?> type ) {
274268
275269 return eggColorCache .computeIfAbsent (type , key -> {
276270
0 commit comments