ClientEntityFinder.java 1.07 KB
Newer Older
1
package com.owlmaddie.utils;
2

3
import net.minecraft.client.MinecraftClient;
4
import net.minecraft.client.world.ClientWorld;
5 6
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
7
import net.minecraft.entity.player.PlayerEntity;
8

9 10
import java.util.UUID;

11 12
/**
 * The {@code ClientEntityFinder} class is used to find a specific MobEntity by UUID, since
13
 * there is not a built-in method for this. Also has a method for client PlayerEntity lookup.
14
 */
15
public class ClientEntityFinder {
16
    public static MobEntity getEntityByUUID(ClientWorld world, UUID uuid) {
17
        for (Entity entity : world.getEntities()) {
18 19
            if (entity.getUuid().equals(uuid) && entity instanceof MobEntity) {
                return (MobEntity)entity;
20 21 22 23
            }
        }
        return null; // Entity not found
    }
24 25 26 27 28 29 30

    public static PlayerEntity getPlayerEntityFromUUID(UUID uuid) {
        return MinecraftClient.getInstance().world.getPlayers().stream()
                .filter(player -> player.getUuid().equals(uuid))
                .findFirst()
                .orElse(null);
    }
31
}