diff --git a/engine/src/main/java/org/terasology/engine/entitySystem/entity/EntityPool.java b/engine/src/main/java/org/terasology/engine/entitySystem/entity/EntityPool.java index 81db3be6f5e..961fed1c68a 100644 --- a/engine/src/main/java/org/terasology/engine/entitySystem/entity/EntityPool.java +++ b/engine/src/main/java/org/terasology/engine/entitySystem/entity/EntityPool.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.entitySystem.entity; @@ -130,10 +130,32 @@ public interface EntityPool { Iterable getAllEntities(); /** + * All entities containing every one of the given components. + *

+ * Implementation note: + * Java generic types are a mess, especially where + * varargs are involved. We can't use {@link SafeVarargs @SafeVarargs} on any interface methods + * because there is no way to know the implementations of the interface are safe. + *

+ * In this case, in practice, there are few (if any) callers that pass more than two values. + * By adding methods that explicitly take one and two values, we can present an interface the + * compiler doesn't need to complain about at every call site. + * * @return An iterable over all entities with the provided component types. */ Iterable getEntitiesWith(Class... componentClasses); + @SuppressWarnings("unchecked") + default Iterable getEntitiesWith(Class componentClass) { + return getEntitiesWith(new Class[] {componentClass}); + } + + @SuppressWarnings("unchecked") + default Iterable getEntitiesWith(Class componentClass, Class componentClass2) { + return getEntitiesWith(new Class[] {componentClass, componentClass2}); + } + /** * @return A count of entities with the provided component types */