package com.mythlane.chainlightning.sceptre; import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import com.hypixel.hytale.server.core.util.TargetUtil; import com.mythlane.chainlightning.chain.ChainEntity; import com.mythlane.chainlightning.chain.EntitySource; import com.mythlane.chainlightning.chain.Vec3; import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; /** Phase 3 EntitySource that copies TargetUtil's thread-local result into a stable list of snapshots. */ public final class HytaleEntitySource implements EntitySource { private final ComponentAccessor accessor; public HytaleEntitySource(@Nonnull ComponentAccessor accessor) { this.accessor = accessor; } @Override public List nearby(Vec3 origin, double radius) { Vector3d hytaleOrigin = new Vector3d(origin.x(), origin.y(), origin.z()); List> refs = TargetUtil.getAllEntitiesInSphere(hytaleOrigin, radius, accessor); if (refs == null || refs.isEmpty()) { return List.of(); } List snapshots = new ArrayList<>(refs.size()); for (Ref ref : refs) { snapshots.add(HytaleEntityAdapter.snapshot(ref, accessor)); } return snapshots; } }