-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathEntityUtil.java
More file actions
26 lines (23 loc) · 1.02 KB
/
EntityUtil.java
File metadata and controls
26 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package de.srendi.advancedperipherals.common.util;
import dan200.computercraft.api.lua.LuaException;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.server.ServerLifecycleHooks;
import java.util.Map;
import java.util.UUID;
public class EntityUtil {
/**
* Searches all levels for an {@link Entity} with the given {@link UUID}.
* @param uuid the unique identifier of the {@code Entity}
* @return an {@code Entity} that has the given {@code UUID} if one is found
* @throws IllegalArgumentException throws if there is no {@code Entity} with the given {@code UUID}
*/
public static Entity getEntityFromUUID(UUID uuid) {
for (ServerLevel level : ServerLifecycleHooks.getCurrentServer().getAllLevels()) {
Entity entity = level.getEntity(uuid);
if (entity != null)
return entity;
}
throw new IllegalArgumentException("No Entity with UUID '" + uuid + "' exists in any level");
}
}