mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-10 05:39:11 +01:00
Add experimental EntityTracker#chunkEntities to retrieve a copy
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
bef4fe37b3
commit
876f716e25
@ -5,11 +5,9 @@ import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.ExperienceOrb;
|
||||
import net.minestom.server.entity.ItemEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -64,6 +62,18 @@ public sealed interface EntityTracker permits EntityTrackerImpl {
|
||||
chunkEntities(point.chunkX(), point.chunkZ(), target, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the entities present in the specified chunk.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@Unmodifiable <T extends Entity> Collection<T> chunkEntities(int chunkX, int chunkZ, @NotNull Target<T> target);
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@Unmodifiable
|
||||
default <T extends Entity> @NotNull Collection<T> chunkEntities(@NotNull Point point, @NotNull Target<T> target) {
|
||||
return chunkEntities(point.chunkX(), point.chunkZ(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entities present in range of the specified chunk.
|
||||
* <p>
|
||||
|
@ -8,12 +8,10 @@ import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -111,6 +109,13 @@ final class EntityTrackerImpl implements EntityTracker {
|
||||
for (Entity entity : entities) query.consume((T) entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized @Unmodifiable <T extends Entity> Collection<T> chunkEntities(int chunkX, int chunkZ, @NotNull Target<T> target) {
|
||||
final TargetEntry<Entity> entry = entries[target.ordinal()];
|
||||
final List<Entity> entities = entry.chunkEntities.get(getChunkIndex(chunkX, chunkZ));
|
||||
return entities != null ? (Collection<T>) List.copyOf(entities) : List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> void visibleEntities(int chunkX, int chunkZ, @NotNull Target<T> target, @NotNull Query<T> query) {
|
||||
for (List<T> entities : references(chunkX, chunkZ, target)) {
|
||||
|
Loading…
Reference in New Issue
Block a user