package com.minelittlepony.client.render;

import net.minecraft.client.render.Frustum;
import net.minecraft.client.util.math.Matrix4f;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Box;

import com.minelittlepony.pony.IPony;

public class FrustrumCheck<T extends LivingEntity> extends Frustum {

    private T entity;

    private Frustum vanilla;

    private final RenderPony<T, ?> renderer;

    public FrustrumCheck(RenderPony<T, ?> render) {
        super(new Matrix4f(), new Matrix4f());
        renderer = render;
    }

    public Frustum withCamera(T entity, Frustum vanillaFrustrum) {
        this.entity = entity;
        vanilla = vanillaFrustrum;
        return this;
    }

    @Override
    public boolean isVisible(Box bounds) {
        IPony pony = renderer.getPony(entity);

        Box boundingBox = pony.getComputedBoundingBox(entity);

        return vanilla.isVisible(boundingBox);
    }

    @Override
    public void setPosition(double x, double y, double z) {
        vanilla.setPosition(x, y, z);
    }
}
