@@ -397,6 +397,74 @@ default <E extends Entity> E createEntityNaturally(Supplier<EntityType<E>> type,
397
397
*/
398
398
Collection <Entity > spawnEntities (Iterable <? extends Entity > entities );
399
399
400
+ /**
401
+ * Applies the provided {@link Predicate} to the
402
+ * {@link Entity entities} such that any time that
403
+ * {@link Predicate#test(Object)} returns {@code false} on the
404
+ * {@link Entity}, the storage performs implementation dependant
405
+ * removal of it.
406
+ *
407
+ * @param predicate The predicate to use for filtering
408
+ */
409
+ default void filterEntities (Predicate <? super Entity > predicate ) {
410
+ this .entities ().forEach (e -> {
411
+ if (!predicate .test (e )) {
412
+ e .remove ();
413
+ }
414
+ });
415
+ }
416
+
417
+ /**
418
+ * Performs implementation dependant removal of all
419
+ * the {@link Entity entities} that intersect the
420
+ * bounding box.
421
+ *
422
+ * @param box The intersection box
423
+ */
424
+ default void filterEntities (AABB box ) {
425
+ this .filterEntities (box , e -> false );
426
+ }
427
+
428
+ /**
429
+ * Applies the provided {@link Predicate} to the {@link Entity entities}
430
+ * that intersect the bounding box such that any time that
431
+ * {@link Predicate#test(Object)} returns {@code false} on the
432
+ * {@link Entity}, the storage performs implementation dependant
433
+ * removal of it.
434
+ *
435
+ * @param box The intersection box
436
+ * @param predicate The predicate to use for filtering
437
+ */
438
+ default void filterEntities (AABB box , Predicate <? super Entity > predicate ) {
439
+ this .entities (box , predicate .negate ()).forEach (Entity ::remove );
440
+ }
441
+
442
+ /**
443
+ * Performs implementation dependant removal of all
444
+ * the {@link Entity entities} that match the given type
445
+ * and intersect the bounding box.
446
+ *
447
+ * @param entityClass The entity type
448
+ * @param box The intersection box
449
+ */
450
+ default <T extends Entity > void filterEntities (Class <? extends T > entityClass , AABB box ) {
451
+ this .filterEntities (entityClass , box , null );
452
+ }
453
+
454
+ /**
455
+ * Applies the provided {@link Predicate} to the {@link Entity entities}
456
+ * that match the given type and intersect the bounding box such that
457
+ * any time that {@link Predicate#test(Object)} returns {@code false}
458
+ * on the {@link Entity}, the storage performs implementation dependant
459
+ * removal of it.
460
+ *
461
+ * @param entityClass The entity type
462
+ * @param box The intersection box
463
+ * @param predicate The predicate to use for filtering
464
+ */
465
+ default <T extends Entity > void filterEntities (Class <? extends T > entityClass , AABB box , @ Nullable Predicate <? super T > predicate ) {
466
+ this .entities (entityClass , box , predicate != null ? predicate .negate () : null ).forEach (Entity ::remove );
467
+ }
400
468
}
401
469
402
470
interface Mutable extends Modifiable <Mutable > {
0 commit comments