ServerEntityFinder.java 697 Bytes
Newer Older
1
package com.owlmaddie.utils;
2 3

import net.minecraft.entity.Entity;
4
import net.minecraft.entity.LivingEntity;
5
import net.minecraft.server.world.ServerWorld;
6

7 8
import java.util.UUID;

9
/**
10
 * The {@code ServerEntityFinder} class is used to find a specific LivingEntity by UUID, since
11 12
 * there is not a built-in method for this.
 */
13
public class ServerEntityFinder {
14
    public static LivingEntity getEntityByUUID(ServerWorld world, UUID uuid) {
15
        for (Entity entity : world.iterateEntities()) {
16 17
            if (entity.getUuid().equals(uuid) && entity instanceof LivingEntity) {
                return (LivingEntity) entity;
18 19 20 21 22
            }
        }
        return null; // Entity not found
    }
}