package net.minecraft.client.renderer.entity;

import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.resources.model.Material;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.Vec3i;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.client.renderer.entity.layers.ShulkerHeadLayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.model.ShulkerModel;
import net.minecraft.world.entity.monster.Shulker;

public class ShulkerRenderer extends MobRenderer<Shulker, ShulkerModel<Shulker>> {
    public static final ResourceLocation DEFAULT_TEXTURE_LOCATION;
    public static final ResourceLocation[] TEXTURE_LOCATION;
    
    public ShulkerRenderer(final EntityRenderDispatcher dvf) {
        super(dvf, new ShulkerModel(), 0.0f);
        this.addLayer(new ShulkerHeadLayer(this));
    }
    
    public Vec3 getRenderOffset(final Shulker axe, final float float2) {
        final int integer4 = axe.getClientSideTeleportInterpolation();
        if (integer4 > 0 && axe.hasValidInterpolationPositions()) {
            final BlockPos fk5 = axe.getAttachPosition();
            final BlockPos fk6 = axe.getOldAttachPosition();
            double double7 = (integer4 - float2) / 6.0;
            double7 *= double7;
            final double double8 = (fk5.getX() - fk6.getX()) * double7;
            final double double9 = (fk5.getY() - fk6.getY()) * double7;
            final double double10 = (fk5.getZ() - fk6.getZ()) * double7;
            return new Vec3(-double8, -double9, -double10);
        }
        return super.getRenderOffset((T)axe, float2);
    }
    
    @Override
    public boolean shouldRender(final Shulker axe, final Frustum dtm, final double double3, final double double4, final double double5) {
        if (super.shouldRender(axe, dtm, double3, double4, double5)) {
            return true;
        }
        if (axe.getClientSideTeleportInterpolation() > 0 && axe.hasValidInterpolationPositions()) {
            final Vec3 cvl10 = new Vec3(axe.getAttachPosition());
            final Vec3 cvl11 = new Vec3(axe.getOldAttachPosition());
            if (dtm.isVisible(new AABB(cvl11.x, cvl11.y, cvl11.z, cvl10.x, cvl10.y, cvl10.z))) {
                return true;
            }
        }
        return false;
    }
    
    @Override
    public ResourceLocation getTextureLocation(final Shulker axe) {
        if (axe.getColor() == null) {
            return ShulkerRenderer.DEFAULT_TEXTURE_LOCATION;
        }
        return ShulkerRenderer.TEXTURE_LOCATION[axe.getColor().getId()];
    }
    
    @Override
    protected void setupRotations(final Shulker axe, final PoseStack cyl, final float float3, final float float4, final float float5) {
        super.setupRotations(axe, cyl, float3, float4, float5);
        cyl.translate(0.0, 0.5, 0.0);
        cyl.mulPose(axe.getAttachFace().getOpposite().getRotation());
        cyl.translate(0.0, -0.5, 0.0);
    }
    
    @Override
    protected void scale(final Shulker axe, final PoseStack cyl, final float float3) {
        final float float4 = 0.999f;
        cyl.scale(0.999f, 0.999f, 0.999f);
    }
    
    static {
        DEFAULT_TEXTURE_LOCATION = new ResourceLocation("textures/" + Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION.texture().getPath() + ".png");
        final ResourceLocation resourceLocation;
        TEXTURE_LOCATION = Sheets.SHULKER_TEXTURE_LOCATION.stream().map(eby -> {
            new ResourceLocation("textures/" + eby.texture().getPath() + ".png");
            return resourceLocation;
        }).<ResourceLocation>toArray(ResourceLocation[]::new);
    }
}
