package me.km.entities;

import me.km.KajetansMod;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.registries.IForgeRegistry;

public class ModEntities {
    public static final EntityType<EntityHuman> HUMAN
            = (EntityType<EntityHuman>) EntityType.Builder.create(EntityHuman::new, EntityClassification.CREATURE)
                    .size(0.6f, 1.8f)
                    .build(String.format("%s:human", KajetansMod.MODID))
                    .setRegistryName(KajetansMod.MODID, "human");
    public static final EntityType<EntityNobody> NOBODY
            = (EntityType<EntityNobody>) EntityType.Builder.create(EntityNobody::new, EntityClassification.MISC)
                    .size(0.5f, 0.5f)
                    .build(String.format("%s:nobody", KajetansMod.MODID))
                    .setRegistryName(KajetansMod.MODID, "nobody");
    public static final EntityType<EntityBrownBear> BROWN_BEAR
            = (EntityType<EntityBrownBear>) EntityType.Builder.create(EntityBrownBear::new, EntityClassification.CREATURE)
                    .size(1.4f, 1.4f)
                    .build(String.format("%s:bear/brownbear", KajetansMod.MODID))
                    .setRegistryName(KajetansMod.MODID, "bear/brownbear");
    public static final EntityType<EntityBlackBear> BLACK_BEAR
            = (EntityType<EntityBlackBear>) EntityType.Builder.create(EntityBlackBear::new, EntityClassification.CREATURE)
                    .size(1.4f, 1.4f)
                    .build(String.format("%s:bear/blackbear", KajetansMod.MODID))
                    .setRegistryName(KajetansMod.MODID, "bear/blackbear");

    public static void init(IForgeRegistry<EntityType<?>> r) {
        if(FMLEnvironment.dist == Dist.CLIENT) {
            initClient();
        }
        r.register(HUMAN);
        r.register(NOBODY);
        r.register(BROWN_BEAR);
        r.register(BLACK_BEAR);
    }

    @OnlyIn(Dist.CLIENT)
    private static void initClient() {
        RenderingRegistry.registerEntityRenderingHandler(BROWN_BEAR, (rm) -> {
            return new RenderBrownBear(rm);
        });
        RenderingRegistry.registerEntityRenderingHandler(BLACK_BEAR, (rm) -> {
            return new RenderBlackBear(rm);
        });
        RenderingRegistry.registerEntityRenderingHandler(HUMAN, (rm) -> {
            return new RenderHuman(rm);
        });
        RenderingRegistry.registerEntityRenderingHandler(NOBODY, (rm) -> {
            return new RenderNobody(rm);
        });
    }
}
