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

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

7 8
import java.util.UUID;

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